using System;
using System.Collections.Generic;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Model.State;
namespace TINK.Model.Bikes.BikeInfoNS.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 _StateInfo;
///
/// Holds the bike object.
///
public BikeNS.Bike Bike { get; }
///
/// Holds the drive object.
///
public Drive Drive { get; }
/// Constructs a bike object.
protected BikeInfo(
IStateInfo stateInfo,
BikeNS.Bike bike,
Drive drive,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable group = null,
string stationId = null,
Uri operatorUri = null,
RentalDescription tariffDescription = null)
{
Bike = bike ?? throw new ArgumentNullException(nameof(bike));
Drive = drive ?? throw new ArgumentNullException(nameof(drive));
_StateInfo = stateInfo;
IsDemo = isDemo ?? DEFAULTVALUEISDEMO;
Group = group ?? new List();
StationId = stationId;
OperatorUri = operatorUri;
TariffDescription = tariffDescription;
}
public BikeInfo(BikeInfo bikeInfo) : this(
bikeInfo != null ? bikeInfo?.State : throw new ArgumentNullException(nameof(bikeInfo)),
bikeInfo.Bike,
bikeInfo.Drive,
bikeInfo.IsDemo,
bikeInfo.Group,
bikeInfo.StationId,
bikeInfo.OperatorUri,
bikeInfo.TariffDescription)
{ }
///
/// Constructs a bike info object for a available 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(
BikeNS.Bike bike,
Drive drive,
string stationId,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable group = null) : this(
new StateInfo(),
bike,
drive,
isDemo,
group,
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.
/// 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(
BikeNS.Bike bike,
Drive drive,
bool? isDemo,
IEnumerable group,
string currentStationId,
Uri operatorUri,
RentalDescription tariffDescription,
DateTime bookedAt,
string mailAddress,
string code) : this(
new StateInfo(
bookedAt,
mailAddress,
code),
bike,
drive,
isDemo,
group,
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 string StationId { get; }
/// Holds description about the tarif.
public RentalDescription TariffDescription { get; }
/// Holds the rent state of the bike.
///
public IStateInfo State
{
get { return _StateInfo; }
}
public string Id => Bike.Id;
public WheelType? WheelType => Bike.WheelType;
public TypeOfBike? TypeOfBike => Bike.TypeOfBike;
/// Gets the model of the lock.
public LockModel LockModel => Bike.LockModel;
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={(!string.IsNullOrEmpty(StationId) ? $"Station {StationId}" : "On the road")}, is demo={IsDemo}.";
}
}
}