sharee.bike-App/TINKLib/ViewModel/Bikes/Bike/BC/RequestHandlerFactory.cs

62 lines
1.6 KiB
C#
Raw Normal View History

2023-04-19 12:14:14 +02:00
using System;
2021-05-13 20:03:07 +02:00
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;
2022-08-30 15:42:25 +02:00
using BikeInfoMutable = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfoMutable;
2021-05-13 20:03:07 +02:00
namespace TINK.ViewModel.Bikes.Bike.BC
{
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
}