mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-12-23 23:56:26 +01:00
171 lines
5.8 KiB
C#
171 lines
5.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using TINK.Model.Bikes.BikeInfoNS.BC;
|
|
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
|
|
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
|
|
using TINK.Model.State;
|
|
|
|
namespace TINK.Model.Bikes.BikeInfoNS.BluetoothLock
|
|
{
|
|
public class BikeInfo : BC.BikeInfo, IBikeInfo
|
|
{
|
|
/// <summary>
|
|
/// Constructs a bike info object for a available bike.
|
|
/// </summary>
|
|
/// <param name="dataSource">Specified the source of the data.</param>
|
|
/// <param name="lockId">Id of the lock.</param>
|
|
/// <param name="lockGuid">GUID specifying the lock.</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>
|
|
public BikeInfo(
|
|
Bike bike,
|
|
DriveMutable drive,
|
|
DataSource dataSource,
|
|
int lockId,
|
|
Guid lockGuid,
|
|
string currentStationId,
|
|
Uri operatorUri = null,
|
|
RentalDescription tariffDescription = null,
|
|
bool? isDemo = DEFAULTVALUEISDEMO,
|
|
IEnumerable<string> group = null) : base(
|
|
new StateInfo(),
|
|
bike != null
|
|
? new Bike(
|
|
bike.Id,
|
|
LockModel.ILockIt /* Ensure consistent lock model value */,
|
|
bike.WheelType,
|
|
bike.TypeOfBike,
|
|
bike.AaRideType,
|
|
bike.Description)
|
|
: throw new ArgumentNullException(nameof(bike)),
|
|
drive,
|
|
dataSource,
|
|
isDemo,
|
|
group,
|
|
currentStationId,
|
|
operatorUri,
|
|
tariffDescription)
|
|
{
|
|
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid }.Build();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructs a bike info object for a requested bike.
|
|
/// </summary>
|
|
/// <param name="dataSource">Specified the source of the data.</param>
|
|
/// <param name="dateTimeProvider">Provider for current date time to calculate remaining time on demand for state of type reserved.</param>
|
|
/// <param name="lockId">Id of the lock.</param>
|
|
/// <param name="lockGuid">GUID specifying the lock.</param>
|
|
/// <param name="requestedAt">Date time when bike was requested</param>
|
|
/// <param name="mailAddress">Mail address of user which requested 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="dateTimeProvider">Date time provider to calculate remaining time.</param>
|
|
public BikeInfo(
|
|
Bike bike,
|
|
DriveMutable drive,
|
|
DataSource dataSource,
|
|
int lockId,
|
|
Guid lockGuid,
|
|
byte[] userKey,
|
|
byte[] adminKey,
|
|
byte[] seed,
|
|
DateTime requestedAt,
|
|
string mailAddress,
|
|
string currentStationId,
|
|
Uri operatorUri,
|
|
RentalDescription tariffDescription,
|
|
Func<DateTime> dateTimeProvider,
|
|
bool? isDemo = DEFAULTVALUEISDEMO,
|
|
IEnumerable<string> group = null) : base(
|
|
new StateInfo(
|
|
dateTimeProvider,
|
|
requestedAt,
|
|
tariffDescription?.MaxReservationTimeSpan ?? StateRequestedInfo.UNKNOWNMAXRESERVATIONTIMESPAN,
|
|
mailAddress,
|
|
"" ), // BC code
|
|
bike != null
|
|
? new Bike(
|
|
bike.Id,
|
|
LockModel.ILockIt /* Ensure consistent lock model value */,
|
|
bike.WheelType,
|
|
bike.TypeOfBike,
|
|
bike.AaRideType,
|
|
bike.Description)
|
|
: throw new ArgumentNullException(nameof(bike)),
|
|
drive,
|
|
dataSource,
|
|
isDemo,
|
|
group,
|
|
currentStationId,
|
|
operatorUri,
|
|
tariffDescription)
|
|
{
|
|
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructs a bike info object for a booked bike.
|
|
/// </summary>
|
|
/// <param name="bike">Unique id of bike.</param>
|
|
/// <param name="dataSource">Specified the source of the data.</param>
|
|
/// <param name="lockId">Id of the lock.</param>
|
|
/// <param name="lockGuid">GUID specifying the lock.</param>
|
|
/// <param name="bookedAt">Date time when bike was booked</param>
|
|
/// <param name="mailAddress">Mail address of user which booked 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="wheelType"></param>
|
|
public BikeInfo(
|
|
Bike bike,
|
|
DriveMutable drive,
|
|
DataSource dataSource,
|
|
int lockId,
|
|
Guid lockGuid,
|
|
byte[] userKey,
|
|
byte[] adminKey,
|
|
byte[] seed,
|
|
DateTime bookedAt,
|
|
string mailAddress,
|
|
string currentStationId,
|
|
Uri operatorUri,
|
|
RentalDescription tariffDescription = null,
|
|
bool? isDemo = DEFAULTVALUEISDEMO,
|
|
IEnumerable<string> group = null) : base(
|
|
new StateInfo(
|
|
bookedAt,
|
|
mailAddress,
|
|
""),
|
|
bike != null
|
|
? new Bike(
|
|
bike.Id,
|
|
LockModel.ILockIt /* Ensure consistent lock model value */,
|
|
bike.WheelType,
|
|
bike.TypeOfBike,
|
|
bike.AaRideType,
|
|
bike.Description)
|
|
: throw new ArgumentNullException(),
|
|
drive,
|
|
dataSource,
|
|
isDemo,
|
|
group,
|
|
currentStationId,
|
|
operatorUri,
|
|
tariffDescription)
|
|
{
|
|
LockInfo = new LockInfo.Builder { Id = lockId, Guid = lockGuid, UserKey = userKey, AdminKey = adminKey, Seed = seed }.Build();
|
|
}
|
|
|
|
public BikeInfo(BC.BikeInfo bikeInfo, LockInfo lockInfo) : base(
|
|
bikeInfo ?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source bike info must not be null."))
|
|
{
|
|
LockInfo = lockInfo
|
|
?? throw new ArgumentException($"Can not copy-construct {typeof(BikeInfo).Name}-object. Source lock object must not be null.");
|
|
}
|
|
|
|
public LockInfo LockInfo { get; private set; }
|
|
}
|
|
}
|