2023-04-19 12:14:14 +02:00
|
|
|
using System;
|
2024-04-09 12:53:23 +02:00
|
|
|
using ShareeBike.Model.Connector;
|
|
|
|
using ShareeBike.Model.Device;
|
|
|
|
using ShareeBike.Model.User;
|
|
|
|
using ShareeBike.View;
|
|
|
|
using ShareeBike.ViewModel.Bikes.Bike.BC.RequestHandler;
|
|
|
|
using BikeInfoMutable = ShareeBike.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable;
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2024-04-09 12:53:23 +02:00
|
|
|
namespace ShareeBike.ViewModel.Bikes.Bike.BC
|
2021-05-13 20:03:07 +02:00
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
public static class RequestHandlerFactory
|
|
|
|
{
|
|
|
|
/// <param name="smartDevice">Provides info about the smart device (phone, tablet, ...)</param>
|
|
|
|
/// <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,
|
|
|
|
ISmartDevice smartDevice,
|
|
|
|
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,
|
|
|
|
smartDevice,
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
case Model.State.InUseStateEnum.Reserved:
|
2023-04-19 12:14:14 +02:00
|
|
|
// Reservation can be canceled.
|
2022-09-06 16:08:19 +02:00
|
|
|
return new Reserved(
|
|
|
|
selectedBike,
|
|
|
|
isConnectedDelegate,
|
|
|
|
connectorFactory,
|
|
|
|
viewUpdateManager,
|
|
|
|
smartDevice,
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
2021-05-13 20:03:07 +02:00
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
default:
|
|
|
|
// No action using app possible.
|
|
|
|
return new Booked(
|
|
|
|
selectedBike,
|
|
|
|
viewService,
|
|
|
|
bikesViewModel,
|
|
|
|
activeUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 20:03:07 +02:00
|
|
|
}
|