using System;
using System.Collections.Generic;
using TINK.Model.Bikes.Bike;
using TINK.Model.State;
namespace TINK.Model.Bike.BC
{
public class BikeInfo : IBikeInfo
{
/// Default value of demo property.
public const bool DEFAULTVALUEISDEMO = false;
/// Holds the info about the bike state.
private readonly IStateInfo m_oStateInfo;
///
/// Holds the bike object.
///
private Bike Bike { get; }
/// Constructs a bike object.
protected BikeInfo(
IStateInfo stateInfo,
int id,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null,
int? currentStationId = null,
Uri operatorUri = null,
TariffDescription tariffDescription = null)
{
Bike = new Bike(id, wheelType, typeOfBike, description);
m_oStateInfo = stateInfo;
IsDemo = isDemo ?? DEFAULTVALUEISDEMO;
Group = group ?? new List();
CurrentStation = currentStationId;
OperatorUri = operatorUri;
TariffDescription = tariffDescription;
}
public BikeInfo(BikeInfo bikeInfo) : this(
bikeInfo?.State,
bikeInfo?.Id ?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source must not be null."),
bikeInfo.IsDemo,
bikeInfo.Group,
bikeInfo.WheelType,
bikeInfo.TypeOfBike,
bikeInfo.Description,
bikeInfo.CurrentStation,
bikeInfo.OperatorUri,
bikeInfo.TariffDescription) { }
///
/// Constructs a bike info object for a available bike.
///
/// Unique id of bike.
/// Id of station where bike is located.
/// Holds the uri of the operator or null, in case of single operator setup.
/// Hold tariff description of bike.
///
public BikeInfo(
int id,
int? currentStationId,
Uri operatorUri = null,
TariffDescription tariffDescription = null,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable group = null,
WheelType? wheelType = null,
TypeOfBike? typeOfBike = null,
string description = null) : this(
new StateInfo(),
id,
isDemo,
group,
wheelType,
typeOfBike,
description,
currentStationId,
operatorUri,
tariffDescription)
{
}
///
/// Constructs a bike info object for a requested bike.
///
/// Provider for current date time to calculate remainig time on demand for state of type reserved.
///
/// Unique id of bike.
/// 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.
/// Date time when bike was requested
/// Mail address of user which requested bike.
/// Booking code.
/// Date time provider to calculate reaining time.
public BikeInfo(
int id,
bool? isDemo,
IEnumerable group,
WheelType? wheelType,
TypeOfBike? typeOfBike,
string description,
int? stationId,
Uri operatorUri,
TariffDescription tariffDescription,
DateTime requestedAt,
string mailAddress,
string code,
Func dateTimeProvider = null) : this(
new StateInfo(
dateTimeProvider,
requestedAt,
mailAddress,
code),
id,
isDemo,
group,
wheelType,
typeOfBike,
description,
stationId,
operatorUri,
tariffDescription)
{
}
///
/// Constructs a bike info object for a booked bike.
///
/// Provider for current date time to calculate remainig time on demand for state of type reserved.
///
/// Unique id of bike.
/// 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.
/// Date time when bike was booked
/// Mail address of user which booked bike.
/// Booking code.
public BikeInfo(
int id,
bool? isDemo,
IEnumerable group,
WheelType? wheelType,
TypeOfBike? typeOfBike,
string description,
int? currentStationId,
Uri operatorUri,
TariffDescription tariffDescription,
DateTime bookedAt,
string mailAddress,
string code) : this(
new StateInfo(
bookedAt,
mailAddress,
code),
id,
isDemo,
group,
wheelType,
typeOfBike,
description,
currentStationId,
operatorUri,
tariffDescription)
{
}
/// True if device is demo device, false otherwise.
public bool IsDemo { get; }
/// Returns the group (TINK, Konrad, ...).
public IEnumerable Group { get; }
///
/// Station a which bike is located, null otherwise.
///
public int? CurrentStation { get; }
/// Holds description about the tarif.
public TariffDescription TariffDescription { get; }
/// Holds the rent state of the bike.
///
public IStateInfo State
{
get { return m_oStateInfo; }
}
public int Id => Bike.Id;
public WheelType? WheelType => Bike.WheelType;
public TypeOfBike? TypeOfBike => Bike.TypeOfBike;
public string Description => Bike.Description;
///
/// Uri of the operator or null, in case of single operator setup.
///
public Uri OperatorUri { get; }
///
/// Converts the instance to text.
///
public new string ToString()
{
return $"Id={Bike.Id}{(Bike.WheelType != null ? $", wheel(s)={Bike.WheelType}" : string.Empty)}{(Bike.TypeOfBike != null ? $"type={Bike.TypeOfBike}" : "")}, state={State}, location={(CurrentStation.HasValue ? $"Station {CurrentStation}" : "On the road")}, is demo={IsDemo}.";
}
}
}