using System;
using System.Threading.Tasks;
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Model.User;
using ShareeBike.MultilingualResources;
using ShareeBike.Services.BluetoothLock;
using ShareeBike.Services.Geolocation;
using ShareeBike.View;
using EndRentalCommand = ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Command.EndRentalCommand;
using OpenCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.OpenCommand;
using static ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory;
namespace ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
public class BookedClosed : Base, IRequestHandler, EndRentalCommand.IEndRentalCommandListener, OpenCommand.IOpenCommandListener
{
/// Provides info about the smart device (phone, tablet, ...)
/// View model to be used for progress report and unlocking/ locking view.
public BookedClosed(
IBikeInfoMutable selectedBike,
Func isConnectedDelegate,
Func connectorFactory,
IGeolocationService geolocation,
ILocksService lockService,
Func viewUpdateManager,
ISmartDevice smartDevice,
IViewService viewService,
IBikesViewModel bikesViewModel,
IUser activeUser) : base(
selectedBike,
AppResources.ActionEndRental, // End Rental
true, // Show button
isConnectedDelegate,
connectorFactory,
geolocation,
lockService,
viewUpdateManager,
smartDevice,
viewService,
bikesViewModel,
activeUser)
{
LockitButtonText = AppResources.ActionOpenLock; // Open Lock
IsLockitButtonVisible = true; // Show button
_openLockActionViewModel = new OpenLockActionViewModel(
selectedBike,
viewUpdateManager,
viewService,
bikesViewModel);
_endRentalActionViewModel = new EndRentalActionViewModel(
selectedBike,
isConnectedDelegate,
connectorFactory,
viewUpdateManager,
viewService,
bikesViewModel);
}
///
/// Holds the view model for end rental action.
///
private readonly EndRentalActionViewModel _endRentalActionViewModel;
///
/// Processes the get lock location progress.
///
/// Current step to process.
public void ReportStep(EndRentalCommand.Step step) => _endRentalActionViewModel.ReportStep(step);
///
/// Processes the get lock location state.
///
/// State to process.
/// Textual details describing current state.
public async Task ReportStateAsync(EndRentalCommand.State state, string details) => await _endRentalActionViewModel.ReportStateAsync(state, details);
/// End Rental.
public async Task HandleRequestOption1()
{
await _endRentalActionViewModel.EndRentalAsync();
return Create(
SelectedBike,
IsConnectedDelegate,
ConnectorFactory,
GeolocationService,
LockService,
ViewUpdateManager,
SmartDevice,
ViewService,
BikesViewModel,
ActiveUser);
}
///
/// Holds the view model for close action.
///
private readonly OpenLockActionViewModel _openLockActionViewModel;
///
/// Processes the open lock progress.
///
/// Current step to process.
public void ReportStep(OpenCommand.Step step) => _openLockActionViewModel.ReportStep(step);
///
/// Processes the open lock state.
///
/// State to process.
/// Textual details describing current state.
public async Task ReportStateAsync(OpenCommand.State state, string details) => await _openLockActionViewModel.ReportStateAsync(state, details);
/// Open lock.
public async Task HandleRequestOption2()
{
await _openLockActionViewModel.OpenLockAsync();
return Create(
SelectedBike,
IsConnectedDelegate,
ConnectorFactory,
GeolocationService,
LockService,
ViewUpdateManager,
SmartDevice,
ViewService,
BikesViewModel,
ActiveUser);
}
}
}