using System.ComponentModel;
using ShareeBike.Model;
namespace ShareeBike.ViewModel.Bikes
{
public enum CurrentRentalProcess
{
None = 0,
StartReservationOrRental = 1,
CancelReservation = 2,
OpenLock = 3,
CloseLock = 4,
EndRental = 5,
CloseLockAndCancelReservation = 6,
CloseDisposableLock = 7,
}
public enum CurrentStepStatus
{
None = 0,
Succeeded = 1,
Failed = 2,
}
public class RentalProcessViewModel : IRentalProcessViewModel, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public RentalProcessViewModel(string bikeId = null) => BikeId = bikeId ?? string.Empty;
///
/// Loads rental process view model from source.
///
/// Source object to load from
public void LoadFrom(IRentalProcessViewModel processViewModel)
{
BikeId = processViewModel.BikeId;
_state = processViewModel.State;
_stepIndex = processViewModel.StepIndex;
_stepInfoText = processViewModel.StepInfoText;
_importantStepInfoText = processViewModel.ImportantStepInfoText;
_result = processViewModel.Result;
EndRentalInfo = processViewModel.EndRentalInfo;
}
///
/// Gets the id of the bike which is rental ends.
///
public string BikeId { get; private set; }
/// Holds info about active rental process.
private CurrentRentalProcess _state = CurrentRentalProcess.None;
/// Holds info about active rental process.
public CurrentRentalProcess State
{
get => _state;
set
{
if (_state == value) { return; }
_state = value;
if (value == CurrentRentalProcess.None)
{
StepIndex = null;
Result = CurrentStepStatus.None;
}
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(StepIndex)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Result)));
}
}
/// Holds info about current step in rental process.
private int? _stepIndex;
/// Holds info about current step in rental process.
public int? StepIndex
{
get => _stepIndex;
set
{
if (_stepIndex == value) { return; }
_stepIndex = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(StepIndex)));
}
}
/// Holds info about current step.
private string _stepInfoText;
/// Holds info about current step.
public string StepInfoText
{
get => _stepInfoText;
set
{
if (value == _stepInfoText)
return;
_stepInfoText = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(StepInfoText)));
}
}
/// Holds important info about current step.
private string _importantStepInfoText;
/// Holds important info about current step.
public string ImportantStepInfoText
{
get => _importantStepInfoText;
set
{
if (value == _importantStepInfoText)
return;
_importantStepInfoText = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ImportantStepInfoText)));
}
}
/// Holds info about status of current rental process.
private CurrentStepStatus _result = CurrentStepStatus.None;
/// Holds info about status of current rental process.
public CurrentStepStatus Result
{
get => _result;
set
{
if (_result == value) { return; }
_result = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Result)));
}
}
///
/// Holds the info returned from back end when rent is ended.
///
public BookingFinishedModel EndRentalInfo { get; set; }
}
}