using System;
using System.Threading.Tasks;
using Serilog;
using ShareeBike.Model.State;
using ShareeBike.MultilingualResources;
using ShareeBike.View;
namespace ShareeBike.ViewModel.Bikes.Bike.BluetoothLock
{
public class NotLoggedIn : IRequestHandler
{
/// View model to be used for progress report and unlocking/ locking view.
public NotLoggedIn(
InUseStateEnum state,
IViewService viewService,
IBikesViewModel bikesViewModel)
{
ButtonText = BC.StateToText.GetActionText(state);
ViewService = viewService;
BikesViewModel = bikesViewModel
?? throw new ArgumentException($"Can not construct {GetType().Name}-object. {nameof(bikesViewModel)} must not be null.");
}
/// View model to be used for progress report and unlocking/ locking view.
public IBikesViewModel BikesViewModel { get; }
public bool IsButtonVisible => true;
public bool IsLockitButtonVisible => false;
public string ButtonText { get; private set; }
public string LockitButtonText => GetType().Name;
///
/// Reference on view service to show modal notifications and to perform navigation.
///
private IViewService ViewService { get; }
public bool IsConnected => throw new NotImplementedException();
/// Gets if the bike has to be removed after action has been completed.
public bool IsRemoveBikeRequired => false;
public async Task HandleRequestOption1()
{
Log.ForContext().Information("User selected bike but is not logged in.");
// User is not logged in
BikesViewModel.ActionText = string.Empty;
var l_oResult = await ViewService.DisplayAlert(
AppResources.QuestionLogInTitle,
AppResources.QuestionLogIn,
AppResources.MessageAnswerYes,
AppResources.MessageAnswerNo);
if (l_oResult == false)
{
// User aborted booking process
BikesViewModel.IsIdle = true;
return this;
}
try
{
// Switch to map page
await ViewService.ShowPage("//LoginPage");
}
catch (Exception p_oException)
{
Log.ForContext().Error("Ein unerwarteter Fehler ist in der Klasse NotLoggedIn aufgetreten. Kontext: Aufruf nach Reservierungsversuch ohne Anmeldung. {@Exception}", p_oException);
BikesViewModel.IsIdle = true;
return this;
}
BikesViewModel.IsIdle = true;
return this;
}
public async Task HandleRequestOption2()
{
Log.ForContext().Error("Click of unsupported button detected.");
return await Task.FromResult(this);
}
public string ErrorText => string.Empty;
}
}