using System; using System.Collections.Generic; using System.Threading.Tasks; using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock; using ShareeBike.Model.Connector; using ShareeBike.Model.Device; using ShareeBike.Repository; using ShareeBike.Repository.Request; using ShareeBike.Repository.Response; using ShareeBike.Repository.Response.Stations; using ShareeBike.Services.CopriApi.Exception; namespace ShareeBike.Model.Services.CopriApi { /// Object which manages calls to cache. public class CopriProviderMonkeyStore : ICopriServer { /// Object which manages stored copri answers. private readonly CopriCallsMonkeyStore monkeyStore; /// True if connector has access to copri server, false if cached values are used. public bool IsConnected => monkeyStore.IsConnected; /// Gets the session cookie if user is logged in, an empty string otherwise. public string SessionCookie => monkeyStore.SessionCookie; /// Constructs object which Object which manages stored copri answers in a thread save way. /// Id of the merchant ShareeBike-App. /// Two letter ISO language name. /// Holds info about smart device. public CopriProviderMonkeyStore( string merchantId, string uiIsoLangugageName, string sessionCookie, ISmartDevice smartDevice = null) { monkeyStore = new CopriCallsMonkeyStore(merchantId, uiIsoLangugageName, sessionCookie, smartDevice); } /// Gets the merchant id. public string MerchantId => monkeyStore.MerchantId; public Task DoReserveAsync(string bikeId, Uri operatorUri) => throw new RequestNotCachableException(nameof(DoReserveAsync)); public Task DoCancelReservationAsync(string bikeId, Uri operatorUri) => throw new RequestNotCachableException(nameof(DoCancelReservationAsync)); public Task CalculateAuthKeysAsync(string bikeId, Uri operatorUri) => throw new RequestNotCachableException(nameof(CalculateAuthKeysAsync)); public async Task StartReturningBike( string bikeId, Uri operatorUri) => await monkeyStore.StartReturningBike(bikeId, operatorUri); public async Task UpdateLockingStateAsync( string bikeId, lock_state state, Uri operatorUri, LocationDto geolocation, double batteryLevel, IVersionInfo versionInfo) => await monkeyStore.UpdateLockingStateAsync( bikeId, state, operatorUri, geolocation, batteryLevel, versionInfo); public async Task DoBookAsync(Uri operatorUri, string bikeId, Guid guid, double batteryPercentage, LockingAction? nextAction = null) => await monkeyStore.DoBookAsync(operatorUri, bikeId, guid, batteryPercentage, nextAction); public async Task BookAvailableAndStartOpeningAsync( string bikeId, Uri operatorUri) => await monkeyStore.BookAvailableAndStartOpeningAsync(bikeId, operatorUri); public async Task BookReservedAndStartOpeningAsync( string bikeId, Uri operatorUri) => await monkeyStore.BookReservedAndStartOpeningAsync(bikeId, operatorUri); public async Task DoReturn( string bikeId, LocationDto geolocation, Uri operatorUri) => await monkeyStore.DoReturn(bikeId, geolocation, operatorUri); public async Task ReturnAndStartClosingAsync( string bikeId, Uri operatorUri) => await monkeyStore.ReturnAndStartClosingAsync(bikeId, operatorUri); public Task DoSubmitFeedback(string bikeId, int? currentChargeBars, string messge, bool bIsBikeBroke, Uri operatorUri) => throw new RequestNotCachableException(nameof(DoSubmitFeedback)); /// Submits mini survey to copri server. /// Collection of answers. public Task DoSubmitMiniSurvey(IDictionary answers) => throw new RequestNotCachableException(nameof(DoSubmitMiniSurvey)); public async Task DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId) => await monkeyStore.DoAuthorizationAsync(p_strMailAddress, p_strPassword, p_strDeviceId); public async Task DoAuthoutAsync() => await monkeyStore.DoAuthoutAsync(); /// Gets a list of bikes from Copri. /// Uri of the operator host to get bikes from or null if bikes have to be gotten form primary host. /// Id of station which is used for filtering bikes. Null if no filtering should be applied. /// Id of bike which is used for filtering bikes. Null if no filtering should be applied. public async Task GetBikesAvailableAsync(Uri operatorUri = null, string stationId = null, string bikeId = null) => await monkeyStore.GetBikesAvailableAsync(operatorUri, stationId, bikeId); public async Task GetBikesOccupiedAsync() => await monkeyStore.GetBikesOccupiedAsync(); public async Task GetStationsAsync() => await monkeyStore.GetStationsAsync(); } }