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

113 lines
3.2 KiB
C#
Raw Permalink 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;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Bikes.BikeInfoNS.BikeNS;
using ShareeBike.Model.Bikes.BikeInfoNS.DriveNS;
using ShareeBike.Model.State;
2021-05-13 20:03:07 +02:00
2024-04-09 12:53:23 +02:00
namespace ShareeBike.Model.Bikes.BikeInfoNS.BC
2021-05-13 20:03:07 +02:00
{
2023-04-19 12:14:14 +02:00
public abstract class BikeInfo : IBikeInfo
2022-09-06 16:08:19 +02:00
{
/// <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>
2023-08-31 12:31:38 +02:00
public DriveMutable Drive { get; }
2022-09-06 16:08:19 +02:00
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,
2023-08-31 12:31:38 +02:00
DriveMutable 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> True if device is demo device, false otherwise. </summary>
public bool IsDemo { get; }
2024-04-09 12:53:23 +02:00
/// <summary> Returns the group (ShareeBike, Citybike, ...). </summary>
2022-09-06 16:08:19 +02:00
public IEnumerable<string> Group { get; }
/// <summary>
/// Station a which bike is located, null otherwise.
/// </summary>
public string StationId { get; }
2023-04-19 12:14:14 +02:00
/// <summary> Holds description about the tariff. </summary>
2022-09-06 16:08:19 +02:00
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>
2023-11-06 12:23:09 +01:00
public override string ToString()
2022-09-06 16:08:19 +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(StationId) ? $"Station {StationId}" : "On the road")}, is demo={IsDemo}.";
}
}
2021-05-13 20:03:07 +02:00
}