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
{
/// Holds the bike.
private readonly Bike m_oBike;
/// Holds the state info of the bike.
private readonly StateInfoMutable m_oStateInfo;
///
/// Constructs a bike.
///
/// Unique id of bike.
/// True if device is demo device, false otherwise.
/// Provider for current date time to calculate remainig time on demand for state of type reserved.
///
/// Name of station where bike is located, null if bike is on the road.
/// Holds the uri of the operator or null, in case of single operator setup.
/// Hold tariff description of bike.
/// Bike state info.
protected BikeInfoMutable(
int id,
bool isDemo = BikeInfo.DEFAULTVALUEISDEMO,
IEnumerable group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
int? currentStationId = null,
Uri operatorUri = null,
TariffDescription tariffDescription = null,
Func dateTimeProvider = null,
IStateInfo stateInfo = null)
{
IsDemo = isDemo;
Group = group;
m_oBike = new Bike(id, wheelType, typeOfBike, description);
m_oStateInfo = new StateInfoMutable(dateTimeProvider, stateInfo);
m_oStateInfo.PropertyChanged += (sender, eventargs) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(eventargs.PropertyName));
CurrentStation = currentStationId;
OperatorUri = operatorUri;
TariffDescription = tariffDescription;
}
/// Constructs a bike object from source.
public BikeInfoMutable(IBikeInfo p_oBike) : this(
p_oBike.Id,
p_oBike.IsDemo,
p_oBike.Group,
p_oBike.WheelType,
p_oBike.TypeOfBike,
p_oBike.Description,
p_oBike.CurrentStation,
p_oBike.OperatorUri,
p_oBike.TariffDescription,
null,
p_oBike.State)
{
}
///
/// Station a which bike is located, null otherwise.
///
[DataMember]
public int? CurrentStation { get; }
/// Holds description about the tarif.
[DataMember]
public TariffDescription TariffDescription { get; private set; }
///
/// Holds the rent state of the bike.
///
[DataMember]
public StateInfoMutable State
{
get { return m_oStateInfo; }
}
///
/// Uri of the operator or null, in case of single operator setup.
///
public Uri OperatorUri { get; }
/// Unused member.
IStateInfoMutable IBikeInfoMutable.State => m_oStateInfo;
public int Id => m_oBike.Id;
public bool IsDemo { get; }
/// Returns the group (TINK, Konrad, ...).
public IEnumerable Group { get; }
public WheelType? WheelType => m_oBike.WheelType;
public TypeOfBike? TypeOfBike => m_oBike.TypeOfBike;
public string Description => m_oBike.Description;
///
/// Fired whenever property of bike changes.
///
public event PropertyChangedEventHandler PropertyChanged;
///
/// Converts the instance to text.
///
///
public new string ToString()
{
return $"Id={Id}{(WheelType != null ? $", wheel(s)={WheelType}" : string.Empty)}{(TypeOfBike != null ? $", type={TypeOfBike}" : "")}, demo={IsDemo}, state={State.ToString()}, location={(CurrentStation.HasValue ? $"Station {CurrentStation}" : "On the road")}.";
}
}
}