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 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 p_oCopriServer) : base(p_oCopriServer)
{
server = p_oCopriServer as ICopriServer;
if (server == null)
{
throw new ArgumentException($"Copri server is not of expected typ. Type detected is {p_oCopriServer.GetType()}.");
}
}
/// Gets all stations including postions.
public async Task> GetBikesAndStationsAsync()
{
var stationsAllResponse = await server.GetStationsAsync();
var bikesAvailableResponse = await server.GetBikesAvailableAsync();
return new Result(
typeof(CopriCallsMonkeyStore),
new StationsAndBikesContainer(stationsAllResponse.GetStationsAllMutable(), bikesAvailableResponse.GetBikesAvailable()),
stationsAllResponse.GetGeneralData());
}
/// Gets bikes occupied.
/// Collection of bikes.
public async Task> GetBikesOccupiedAsync()
{
Log.ForContext().Error("Unexpected call to get be bikes occpied 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(),
bikesAvailableResponse.GetGeneralData());
}
}
}