sharee.bike-App/TINKLib/ViewModel/Bikes/RentalProcess.cs

134 lines
3.1 KiB
C#
Raw Normal View History

2023-08-31 12:20:06 +02:00
using System.ComponentModel;
using TINK.Model;
namespace TINK.ViewModel.Bikes
{
public enum CurrentRentalProcess
{
None = 0,
ReserveBike = 1,
StartRental = 2,
OpenLock = 3,
CloseLock = 4,
EndRental = 5,
}
public enum CurrentStepStatus
{
None = 0,
Succeeded = 1,
Failed = 2,
}
public class RentalProcess : IRentalProcess, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public RentalProcess(string bikeId = null) => BikeId = bikeId ?? string.Empty;
/// <summary>
/// Gets the id of the bike which is rental ends.
/// </summary>
public string BikeId { get; }
/// <summary> Holds info about active rental process. </summary>
private CurrentRentalProcess _state = CurrentRentalProcess.None;
/// <summary> Holds info about active rental process. </summary>
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)));
}
}
/// <summary> Holds info about current step in rental process. </summary>
private int? _stepIndex;
/// <summary> Holds info about current step in rental process. </summary>
public int? StepIndex
{
get => _stepIndex;
set
{
if (_stepIndex == value) { return; }
_stepIndex = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(StepIndex)));
}
}
/// <summary> Holds info about current step. </summary>
private string _stepInfoText;
/// <summary> Holds info about current step. </summary>
public string StepInfoText
{
get => _stepInfoText;
set
{
if (value == _stepInfoText)
return;
_stepInfoText = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(StepInfoText)));
}
}
/// <summary> Holds important info about current step. </summary>
private string _importantStepInfoText;
/// <summary> Holds important info about current step. </summary>
public string ImportantStepInfoText
{
get => _importantStepInfoText;
set
{
if (value == _importantStepInfoText)
return;
_importantStepInfoText = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ImportantStepInfoText)));
}
}
/// <summary> Holds info about status of current rental process. </summary>
private CurrentStepStatus _result = CurrentStepStatus.None;
/// <summary> Holds info about status of current rental process. </summary>
public CurrentStepStatus Result
{
get => _result;
set
{
if (_result == value) { return; }
_result = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Result)));
}
}
/// <summary>
/// Holds the info returned from back end when rent is ended.
/// </summary>
public BookingFinishedModel EndRentalInfo { get; set; }
}
}