using System; using System.Threading.Tasks; 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 IBikeInfoMutable = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.IBikeInfoMutable; using CloseCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.CloseCommand; using StartRentalCommand = ShareeBike.Model.Bikes.BikeInfoNS.BikeNS.Command.StartRentalCommand; using static ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory; namespace ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler { /// Bike is reserved, lock is open and connected to app. /// /// This state might occur when a ILOCKIT was manually opened (color code) and app connects afterwards. /// This should never during ILOCKIT is connected to app because /// - manually opening lock is not possible when lock is connected /// - two devices can not simultaneously connect to same lock. public class ReservedOpen : Base, IRequestHandler, CloseCommand.ICloseCommandListener, StartRentalCommand.IStartRentalCommandListener { /// Provides info about the smart device (phone, tablet, ...) /// View model to be used for progress report and unlocking/ locking view. public ReservedOpen( IBikeInfoMutable selectedBike, Func isConnectedDelegate, Func connectorFactory, IGeolocationService geolocation, ILocksService lockService, Func viewUpdateManager, ISmartDevice smartDevice, IViewService viewService, IBikesViewModel bikesViewModel, IUser activeUser) : base( selectedBike, AppResources.ActionCloseLock, // Close Lock true, // Show button isConnectedDelegate, connectorFactory, geolocation, lockService, viewUpdateManager, smartDevice, viewService, bikesViewModel, activeUser) { LockitButtonText = AppResources.ActionRentBike; // Rent bike IsLockitButtonVisible = true; // Show button _closeLockActionViewModel = new CloseLockActionViewModel( selectedBike, viewUpdateManager, viewService, bikesViewModel); _startRentalActionViewModel = new StartReservationOrRentalActionViewModel( selectedBike, viewUpdateManager, viewService, bikesViewModel); } /// /// 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); /// /// Holds the view model for requesting a bike action. /// private readonly StartReservationOrRentalActionViewModel _startRentalActionViewModel; /// /// Processes the renting a bike progress. /// /// /// Only used for testing. /// /// Current step to process. public void ReportStep(StartRentalCommand.Step step) => _startRentalActionViewModel?.ReportStep(step); /// /// Processes the renting a bike state. /// /// /// Only used for testing. /// /// State to process. /// Textual details describing current state. public async Task ReportStateAsync(StartRentalCommand.State state, string details) => await _startRentalActionViewModel.ReportStateAsync(state, details); /// Close lock. public async Task HandleRequestOption1() { await _closeLockActionViewModel.CloseLockAsync(); return Create( SelectedBike, IsConnectedDelegate, ConnectorFactory, GeolocationService, LockService, ViewUpdateManager, SmartDevice, ViewService, BikesViewModel, ActiveUser); } /// Start Rental. /// public async Task HandleRequestOption2() { await _startRentalActionViewModel.StartReservationOrRentalAsync(); return Create( SelectedBike, IsConnectedDelegate, ConnectorFactory, GeolocationService, LockService, ViewUpdateManager, SmartDevice, ViewService, BikesViewModel, ActiveUser); } } }