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

179 lines
5.2 KiB
C#
Raw Normal View History

2023-01-18 14:22:51 +01:00
using System;
2021-05-13 20:03:07 +02:00
using System.Collections.Generic;
2022-08-30 15:42:25 +02:00
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
2021-05-13 20:03:07 +02:00
using TINK.Model.State;
2022-08-30 15:42:25 +02:00
namespace TINK.Model.Bikes.BikeInfoNS.BC
2021-05-13 20:03:07 +02:00
{
2022-09-06 16:08:19 +02:00
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 _StateInfo;
/// <summary>
/// Holds the bike object.
/// </summary>
2023-01-18 14:22:51 +01:00
public Bike Bike { get; }
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds the drive object.
/// </summary>
public Drive Drive { get; }
2023-01-18 14:22:51 +01:00
/// <summary> Gets the information where the data origins from. </summary>
public DataSource DataSource { get; }
2022-09-06 16:08:19 +02:00
/// <summary> Constructs a bike object.</summary>
2023-01-18 14:22:51 +01:00
/// <param name="dataSource">Specified the source of the data.</param>
2022-09-06 16:08:19 +02:00
protected BikeInfo(
IStateInfo stateInfo,
2023-01-18 14:22:51 +01:00
Bike bike,
2022-09-06 16:08:19 +02:00
Drive drive,
2023-01-18 14:22:51 +01:00
DataSource dataSource,
2022-09-06 16:08:19 +02:00
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable<string> 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));
2023-01-18 14:22:51 +01:00
DataSource = dataSource;
2022-09-06 16:08:19 +02:00
_StateInfo = stateInfo;
IsDemo = isDemo ?? DEFAULTVALUEISDEMO;
Group = group ?? new List<string>();
StationId = stationId;
OperatorUri = operatorUri;
TariffDescription = tariffDescription;
}
public BikeInfo(BikeInfo bikeInfo) : this(
bikeInfo != null ? bikeInfo?.State : throw new ArgumentNullException(nameof(bikeInfo)),
bikeInfo.Bike,
bikeInfo.Drive,
2023-01-18 14:22:51 +01:00
bikeInfo.DataSource,
2022-09-06 16:08:19 +02:00
bikeInfo.IsDemo,
bikeInfo.Group,
bikeInfo.StationId,
bikeInfo.OperatorUri,
bikeInfo.TariffDescription)
{ }
/// <summary>
/// Constructs a bike info object for a available bike.
/// </summary>
2023-01-18 14:22:51 +01:00
/// <param name="dataSource">Specified the source of the data.</param>
2022-09-06 16:08:19 +02:00
/// <param name="stationId">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>
public BikeInfo(
2023-01-18 14:22:51 +01:00
Bike bike,
2022-09-06 16:08:19 +02:00
Drive drive,
2023-01-18 14:22:51 +01:00
DataSource dataSource,
2022-09-06 16:08:19 +02:00
string stationId,
Uri operatorUri = null,
RentalDescription tariffDescription = null,
bool? isDemo = DEFAULTVALUEISDEMO,
IEnumerable<string> group = null) : this(
new StateInfo(),
bike,
drive,
2023-01-18 14:22:51 +01:00
dataSource,
2022-09-06 16:08:19 +02:00
isDemo,
group,
stationId,
operatorUri,
tariffDescription)
{
}
/// <summary>
/// Constructs a bike info object for a booked bike.
/// </summary>
2023-01-18 14:22:51 +01:00
/// <param name="dataSource">Specified the source of the data.</param>
2022-09-06 16:08:19 +02:00
/// <param name="dateTimeProvider">Provider for current date time to calculate remainig time on demand for state of type reserved.</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(
2023-01-18 14:22:51 +01:00
Bike bike,
2022-09-06 16:08:19 +02:00
Drive drive,
2023-01-18 14:22:51 +01:00
DataSource dataSource,
2022-09-06 16:08:19 +02:00
bool? isDemo,
IEnumerable<string> group,
string currentStationId,
Uri operatorUri,
RentalDescription tariffDescription,
DateTime bookedAt,
string mailAddress,
string code) : this(
new StateInfo(
bookedAt,
mailAddress,
code),
bike,
drive,
2023-01-18 14:22:51 +01:00
dataSource,
2022-09-06 16:08:19 +02:00
isDemo,
group,
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>
public string StationId { get; }
/// <summary> Holds description about the tarif. </summary>
public RentalDescription TariffDescription { get; }
/// Holds the rent state of the bike.
/// </summary>
public IStateInfo State
{
get { return _StateInfo; }
}
public string Id => Bike.Id;
public WheelType? WheelType => Bike.WheelType;
public TypeOfBike? TypeOfBike => Bike.TypeOfBike;
/// <summary> Gets the model of the lock. </summary>
public LockModel LockModel => Bike.LockModel;
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()
{
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}.";
}
}
2021-05-13 20:03:07 +02:00
}