using Serilog;
using System;
using System.Threading.Tasks;
using TINK.Model.Bikes.Bike.BC;
using TINK.Model.State;
using TINK.Model.User;
using TINK.MultilingualResources;
using TINK.View;
namespace TINK.ViewModel.Bikes.Bike.BC.RequestHandler
{
public class Booked : IRequestHandler
{
/// Gets the bike state.
public InUseStateEnum State => InUseStateEnum.Booked;
///
/// If a bike is booked unbooking can not be done by though app.
///
public bool IsButtonVisible => false;
///
/// Gets the name of the button when bike is cancel reservation.
///
public string ButtonText => AppResources.ActionReturn; // "Miete beenden"
///
/// Reference on view servcie to show modal notifications and to perform navigation.
///
protected IViewService ViewService { get; }
/// View model to be used for progress report and unlocking/ locking view.
public IBikesViewModel BikesViewModel { get; }
/// Executes user request to cancel reservation.
public async Task HandleRequest()
{
// Lock list to avoid multiple taps while copri action is pending.
BikesViewModel.ActionText = AppResources.ActivityTextOneMomentPlease;
BikesViewModel.IsIdle = false;
Log.ForContext().Error("User selected booked bike {l_oId}.", SelectedBike.Id);
BikesViewModel.ActionText = string.Empty;
await ViewService.DisplayAlert(
string.Empty,
"Rückgabe nur über Bordcomputer des Fahrrads durch Drücken der Taste 2 möglich!",
"Ok");
BikesViewModel.IsIdle = true;
return this;
}
///
/// Bike to display.
///
protected IBikeInfoMutable SelectedBike { get; }
/// Gets the is connected state.
public bool IsConnected { get; set; }
/// Gets if the bike has to be remvoed after action has been completed.
public bool IsRemoveBikeRequired => false;
/// View model to be used for progress report and unlocking/ locking view.
public Booked(
IBikeInfoMutable selectedBike,
IViewService viewService,
IBikesViewModel bikesViewModel,
IUser activeUser)
{
SelectedBike = selectedBike;
ViewService = viewService;
BikesViewModel = bikesViewModel
?? throw new ArgumentException($"Can not construct {GetType().Name}-object. {nameof(bikesViewModel)} must not be null.");
}
}
}