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 CloseCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.CloseCommand; 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 BookedUnknown : Base, IRequestHandler, CloseCommand.ICloseCommandListener, OpenCommand.IOpenCommandListener { /// Provides info about the smart device (phone, tablet, ...). /// View model to be used for progress report and unlocking/ locking view. public BookedUnknown( IBikeInfoMutable selectedBike, Func isConnectedDelegate, Func connectorFactory, IGeolocationService geolocation, ILocksService lockService, Func viewUpdateManager, ISmartDevice smartDevice, IViewService viewService, IBikesViewModel bikesViewModel, IUser activeUser) : base( selectedBike, AppResources.ActionOpenLock, // Open Lock true, // Show button isConnectedDelegate, connectorFactory, geolocation, lockService, viewUpdateManager, smartDevice, viewService, bikesViewModel, activeUser) { LockitButtonText = AppResources.ActionCloseLock; // Close Lock IsLockitButtonVisible = true; // Show button _openLockActionViewModel = new OpenLockActionViewModel( selectedBike, viewUpdateManager, viewService, bikesViewModel); _closeLockActionViewModel = new CloseLockActionViewModel( selectedBike, viewUpdateManager, viewService, bikesViewModel); } /// /// 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 bike and update COPRI lock state. public async Task HandleRequestOption1() { await _openLockActionViewModel.OpenLockAsync(); return Create( SelectedBike, IsConnectedDelegate, ConnectorFactory, GeolocationService, LockService, ViewUpdateManager, SmartDevice, ViewService, BikesViewModel, ActiveUser); } /// /// Holds the view model for close action. /// private readonly CloseLockActionViewModel _closeLockActionViewModel; /// /// Processes the close lock progress. /// /// /// Only used for testing. /// /// Current step to process. public void ReportStep(CloseCommand.Step step) => _closeLockActionViewModel?.ReportStep(step); /// /// Processes the close lock state. /// /// /// Only used for testing. /// /// State to process. /// Textual details describing current state. public async Task ReportStateAsync(CloseCommand.State state, string details) => await _closeLockActionViewModel.ReportStateAsync(state, details); /// Close lock in order to pause ride and update COPRI lock state. public async Task HandleRequestOption2() { await _closeLockActionViewModel.CloseLockAsync(); if (_closeLockActionViewModel.IsEndRentalRequested == false) { return Create( SelectedBike, IsConnectedDelegate, ConnectorFactory, GeolocationService, LockService, ViewUpdateManager, SmartDevice, ViewService, BikesViewModel, ActiveUser); } var _endRentalActionViewModel = new EndRentalActionViewModel( SelectedBike, IsConnectedDelegate, ConnectorFactory, ViewUpdateManager, ViewService, BikesViewModel); await _endRentalActionViewModel.EndRentalAsync(); return Create( SelectedBike, IsConnectedDelegate, ConnectorFactory, GeolocationService, LockService, ViewUpdateManager, SmartDevice, ViewService, BikesViewModel, ActiveUser); } } }