sharee.bike-App/TINKLib/ViewModel/Bikes/RentalProcessViewModel.cs
2023-08-31 12:31:38 +02:00

146 lines
3.7 KiB
C#

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 RentalProcessViewModel : IRentalProcessViewModel, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
public RentalProcessViewModel(string bikeId = null) => BikeId = bikeId ?? string.Empty;
/// <summary>
/// Loads rental process view model from source.
/// </summary>
/// <param name="processViewModel">Source object to load from </param>
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;
}
/// <summary>
/// Gets the id of the bike which is rental ends.
/// </summary>
public string BikeId { get; private set; }
/// <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; }
}
}