sharee.bike-App/TINKLib/Model/Bikes/Bike/BC/BikeInfo.cs

217 lines
8 KiB
C#
Raw Permalink Normal View History

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