using Serilog;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TINK.Model.Bike;
using TINK.Model.Services.CopriApi;
using TINK.Model.Repository;
using BikeInfo = TINK.Model.Bike.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()));
}
/// 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.Run(() => new BikeCollection(new Dictionary())),
new System.Exception("Abfrage der reservierten/ gebuchten Räder fehlgeschlagen. Kein Benutzer angemeldet."));
}
/// Gets bikes occupied.
/// Collection of bikes.
public async Task> GetBikesAsync()
{
return new Result(
typeof(CopriCallsMonkeyStore),
(await server.GetBikesAvailableAsync()).GetBikesAvailable());
}
}
}