using System;
using System.Threading.Tasks;
using Serilog;
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 ConnectCommand = ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock.Command.ConnectAndGetStateCommand;
using static ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandlerFactory;
namespace ShareeBike.ViewModel.Bikes.Bike.BluetoothLock.RequestHandler
{
public class BookedDisconnected : Base, IRequestHandler, ConnectCommand.IConnectAndGetStateCommandListener
{
/// Provides info about the smart device (phone, tablet, ...)
/// View model to be used for progress report and unlocking/ locking view.
public BookedDisconnected(
IBikeInfoMutable selectedBike,
Func isConnectedDelegate,
Func connectorFactory,
IGeolocationService geolocation,
ILocksService lockService,
Func viewUpdateManager,
ISmartDevice smartDevice,
IViewService viewService,
IBikesViewModel bikesViewModel,
IUser activeUser) :
base(
selectedBike,
AppResources.ActionSearchLock, // Connect Lock
true, // Show button
isConnectedDelegate,
connectorFactory,
geolocation,
lockService,
viewUpdateManager,
smartDevice,
viewService,
bikesViewModel,
activeUser)
{
LockitButtonText = GetType().Name;
IsLockitButtonVisible = false;
_connectLockActionViewModel = new ConnectLockActionViewModel(
selectedBike,
viewUpdateManager,
viewService,
bikesViewModel);
}
///
/// Holds the view model for connecting to lock action.
///
private readonly ConnectLockActionViewModel _connectLockActionViewModel;
///
/// Processes the connect to lock progress.
///
///
/// Only used for testing.
///
/// Current step to process.
public void ReportStep(ConnectCommand.Step step) => _connectLockActionViewModel?.ReportStep(step);
///
/// Processes the connect to lock state.
///
///
/// Only used for testing.
///
/// State to process.
/// Textual details describing current state.
public async Task ReportStateAsync(ConnectCommand.State state, string details) => await _connectLockActionViewModel.ReportStateAsync(state, details);
public async Task HandleRequestOption2() => await UnsupportedRequest();
/// Scan for lock.
///
public async Task HandleRequestOption1()
{
await _connectLockActionViewModel.ConnectLockAsync();
return Create(
SelectedBike,
IsConnectedDelegate,
ConnectorFactory,
GeolocationService,
LockService,
ViewUpdateManager,
SmartDevice,
ViewService,
BikesViewModel,
ActiveUser);
}
/// Request is not supported, button should be disabled.
///
public async Task UnsupportedRequest()
{
Log.ForContext().Error("Click of unsupported button click detected.");
return await Task.FromResult(this);
}
}
}