using System; using System.Collections.Generic; using System.Threading.Tasks; using Serilog; using TINK.Model.Bikes; using TINK.Model.Connector.Updater; using TINK.Model.Services.CopriApi; using TINK.Repository; using TINK.Services.CopriApi; using BikeInfo = TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo; namespace TINK.Model.Connector { /// Provides query functionality from cache without login. public class Query : Base, IQuery { /// Cached copri server. private readonly ICopriServer server; /// Constructs a copri query object. /// Server which implements communication. public Query(ICopriServerBase copriServer) : base(copriServer) { server = copriServer as ICopriServer; if (server == null) { throw new ArgumentException($"Copri server is not of expected typ. Type detected is {copriServer.GetType()}."); } } /// Gets all stations including positions. public async Task> GetBikesAndStationsAsync() { var stationsAllResponse = await server.GetStationsAsync(); return new Result( typeof(CopriCallsMonkeyStore), new StationsAndBikesContainer( stationsAllResponse.GetStationsAllMutable(), new BikeCollection() /* There are no bikes occupied because user is not logged in. */), stationsAllResponse.GetGeneralData()); } /// Gets bikes occupied. /// Collection of bikes. public async Task> GetBikesOccupiedAsync() { Log.ForContext().Error("Unexpected call to get be bikes occupied detected. No user is logged in."); return new Result( typeof(CopriCallsMonkeyStore), await Task.FromResult(new BikeCollection(new Dictionary())), new GeneralData(), new Exception("Abfrage der reservierten/ gebuchten Räder fehlgeschlagen. Kein Benutzer angemeldet.")); } /// Gets bikes occupied. /// Collection of bikes. public async Task> GetBikesAsync() { var bikesAvailableResponse = await server.GetBikesAvailableAsync(); return new Result( typeof(CopriCallsMonkeyStore), bikesAvailableResponse.GetBikesAvailable(Bikes.BikeInfoNS.BC.DataSource.Cache), bikesAvailableResponse.GetGeneralData()); } } }