2021-05-13 20:03:07 +02:00
|
|
|
|
using System;
|
|
|
|
|
using TINK.Model.Connector;
|
2021-06-26 20:57:55 +02:00
|
|
|
|
using TINK.Model.Device;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
using TINK.Model.User;
|
|
|
|
|
using TINK.View;
|
|
|
|
|
using TINK.ViewModel.Bikes.Bike.BC.RequestHandler;
|
|
|
|
|
using BikeInfoMutable = TINK.Model.Bike.BC.BikeInfoMutable;
|
|
|
|
|
|
|
|
|
|
namespace TINK.ViewModel.Bikes.Bike.BC
|
|
|
|
|
{
|
|
|
|
|
public static class RequestHandlerFactory
|
|
|
|
|
{
|
2021-06-26 20:57:55 +02:00
|
|
|
|
/// <param name="smartDevice">Provides info about the smart device (phone, tablet, ...)</param>
|
2021-05-13 20:03:07 +02:00
|
|
|
|
/// <param name="bikesViewModel">View model to be used for progress report and unlocking/ locking view.</param>
|
|
|
|
|
public static IRequestHandler Create(
|
|
|
|
|
BikeInfoMutable selectedBike,
|
|
|
|
|
Func<bool> isConnectedDelegate,
|
|
|
|
|
Func<bool, IConnector> connectorFactory,
|
|
|
|
|
Func<IPollingUpdateTaskManager> viewUpdateManager,
|
2021-06-26 20:57:55 +02:00
|
|
|
|
ISmartDevice smartDevice,
|
2021-05-13 20:03:07 +02:00
|
|
|
|
IViewService viewService,
|
|
|
|
|
IBikesViewModel bikesViewModel,
|
|
|
|
|
IUser activeUser)
|
|
|
|
|
{
|
|
|
|
|
switch (selectedBike.State.Value)
|
|
|
|
|
{
|
|
|
|
|
case Model.State.InUseStateEnum.Disposable:
|
|
|
|
|
// Bike can be booked.
|
|
|
|
|
return new Disposable(
|
|
|
|
|
selectedBike,
|
|
|
|
|
isConnectedDelegate,
|
|
|
|
|
connectorFactory,
|
|
|
|
|
viewUpdateManager,
|
2021-06-26 20:57:55 +02:00
|
|
|
|
smartDevice,
|
2021-05-13 20:03:07 +02:00
|
|
|
|
viewService,
|
|
|
|
|
bikesViewModel,
|
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
|
|
case Model.State.InUseStateEnum.Reserved:
|
|
|
|
|
// Reservation can be cancelled.
|
|
|
|
|
return new Reserved(
|
|
|
|
|
selectedBike,
|
|
|
|
|
isConnectedDelegate,
|
|
|
|
|
connectorFactory,
|
|
|
|
|
viewUpdateManager,
|
2021-06-26 20:57:55 +02:00
|
|
|
|
smartDevice,
|
2021-05-13 20:03:07 +02:00
|
|
|
|
viewService,
|
|
|
|
|
bikesViewModel,
|
|
|
|
|
activeUser);
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
// No action using app possible.
|
|
|
|
|
return new Booked(
|
|
|
|
|
selectedBike,
|
|
|
|
|
viewService,
|
|
|
|
|
bikesViewModel,
|
|
|
|
|
activeUser);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|