2021-05-13 20:03:07 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
|
using TINK.Model.Bikes.Bike;
|
|
|
|
|
using TINK.Model.Bikes.Bike.BC;
|
|
|
|
|
using TINK.Model.State;
|
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Bike.BC
|
|
|
|
|
{
|
|
|
|
|
[DataContract]
|
|
|
|
|
public class BikeInfoMutable : IBikeInfoMutable, INotifyPropertyChanged
|
|
|
|
|
{
|
|
|
|
|
/// <summary> Holds the bike. </summary>
|
|
|
|
|
private readonly Bike m_oBike;
|
|
|
|
|
|
|
|
|
|
/// <summary> Holds the state info of the bike. </summary>
|
|
|
|
|
private readonly StateInfoMutable m_oStateInfo;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a bike.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id">Unique id of bike.</param>
|
|
|
|
|
/// <param name="isDemo">True if device is demo device, false otherwise.</param>
|
|
|
|
|
/// <param name="dateTimeProvider">Provider for current date time to calculate remainig time on demand for state of type reserved.</param>
|
|
|
|
|
/// <param name="wheelType"></param>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <param name="stationId">Name of station where bike is located, null if bike is on the road.</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <param name="operatorUri">Holds the uri of the operator or null, in case of single operator setup.</param>
|
|
|
|
|
/// <param name="tariffDescription">Hold tariff description of bike.</param>
|
|
|
|
|
/// <param name="stateInfo">Bike state info.</param>
|
|
|
|
|
protected BikeInfoMutable(
|
2021-06-26 20:57:55 +02:00
|
|
|
|
string id,
|
2022-04-25 22:15:15 +02:00
|
|
|
|
LockModel lockModel,
|
2021-05-13 20:03:07 +02:00
|
|
|
|
bool isDemo = BikeInfo.DEFAULTVALUEISDEMO,
|
|
|
|
|
IEnumerable<string> group = null,
|
|
|
|
|
WheelType? wheelType = null,
|
|
|
|
|
TypeOfBike? typeOfBike = null,
|
|
|
|
|
string description = null,
|
2022-01-04 18:59:16 +01:00
|
|
|
|
string stationId = null,
|
|
|
|
|
string stationName = null,
|
2021-05-13 20:03:07 +02:00
|
|
|
|
Uri operatorUri = null,
|
2022-06-17 14:17:58 +02:00
|
|
|
|
RentalDescription tariffDescription = null,
|
2021-05-13 20:03:07 +02:00
|
|
|
|
Func<DateTime> dateTimeProvider = null,
|
|
|
|
|
IStateInfo stateInfo = null)
|
|
|
|
|
{
|
|
|
|
|
IsDemo = isDemo;
|
|
|
|
|
Group = group;
|
2022-04-25 22:15:15 +02:00
|
|
|
|
m_oBike = new Bike(id, lockModel, wheelType, typeOfBike, description);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
m_oStateInfo = new StateInfoMutable(dateTimeProvider, stateInfo);
|
|
|
|
|
m_oStateInfo.PropertyChanged += (sender, eventargs) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(eventargs.PropertyName));
|
2022-01-04 18:59:16 +01:00
|
|
|
|
StationId = stationId;
|
|
|
|
|
StationName = stationName;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
OperatorUri = operatorUri;
|
|
|
|
|
TariffDescription = tariffDescription;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary> Constructs a bike object from source. </summary>
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public BikeInfoMutable(IBikeInfo bike, string stationName) : this(
|
|
|
|
|
bike.Id,
|
2022-04-25 22:15:15 +02:00
|
|
|
|
bike.LockModel,
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike.IsDemo,
|
|
|
|
|
bike.Group,
|
|
|
|
|
bike.WheelType,
|
|
|
|
|
bike.TypeOfBike,
|
|
|
|
|
bike.Description,
|
|
|
|
|
bike.StationId,
|
|
|
|
|
stationName,
|
|
|
|
|
bike.OperatorUri,
|
|
|
|
|
bike.TariffDescription,
|
2021-05-13 20:03:07 +02:00
|
|
|
|
null,
|
2022-01-04 18:59:16 +01:00
|
|
|
|
bike.State)
|
2021-05-13 20:03:07 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-04 18:59:16 +01:00
|
|
|
|
/// <summary> Id of station a which bike is located, null otherwise.</summary>
|
|
|
|
|
[DataMember]
|
|
|
|
|
public string StationId { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary> Name of station a which bike is located, null otherwise. </summary>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
[DataMember]
|
2022-01-04 18:59:16 +01:00
|
|
|
|
public string StationName { get; }
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
/// <summary> Holds description about the tarif. </summary>
|
|
|
|
|
[DataMember]
|
2022-06-17 14:17:58 +02:00
|
|
|
|
public RentalDescription TariffDescription { get; private set; }
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Holds the rent state of the bike.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[DataMember]
|
|
|
|
|
public StateInfoMutable State
|
|
|
|
|
{
|
|
|
|
|
get { return m_oStateInfo; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Uri of the operator or null, in case of single operator setup.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Uri OperatorUri { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary> Unused member. </summary>
|
|
|
|
|
IStateInfoMutable IBikeInfoMutable.State => m_oStateInfo;
|
|
|
|
|
|
2021-06-26 20:57:55 +02:00
|
|
|
|
public string Id => m_oBike.Id;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
|
|
|
|
|
public bool IsDemo { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary> Returns the group (TINK, Konrad, ...). </summary>
|
|
|
|
|
public IEnumerable<string> Group { get; }
|
|
|
|
|
|
|
|
|
|
public WheelType? WheelType => m_oBike.WheelType;
|
|
|
|
|
|
|
|
|
|
public TypeOfBike? TypeOfBike => m_oBike.TypeOfBike;
|
|
|
|
|
|
2022-04-25 22:15:15 +02:00
|
|
|
|
public LockModel LockModel => m_oBike.LockModel;
|
|
|
|
|
|
2021-05-13 20:03:07 +02:00
|
|
|
|
public string Description => m_oBike.Description;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Fired whenever property of bike changes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Converts the instance to text.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public new string ToString()
|
|
|
|
|
{
|
2022-01-04 18:59:16 +01:00
|
|
|
|
return $"Id={Id}{(WheelType != null ? $", wheel(s)={WheelType}" : string.Empty)}{(TypeOfBike != null ? $", type={TypeOfBike}" : "")}, demo={IsDemo}, state={State.ToString()}, location={(!string.IsNullOrEmpty(StationId) ? $"Station {StationId}" : "On the road")}.";
|
2021-05-13 20:03:07 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|