using System;
using System.Threading.Tasks;
using TINK.Model.Bike;
using TINK.Model.Services.CopriApi;
using TINK.Repository;
namespace TINK.Model.Connector
{
/// Provides query functionality for a logged in user.
public class QueryLoggedIn : BaseLoggedIn, IQuery
{
/// Cached copri server.
private readonly ICopriServer server;
/// Constructs a copri query object.
/// Server which implements communication.
public QueryLoggedIn(ICopriServerBase p_oCopriServer,
string p_strSessionCookie,
string p_strMail,
Func p_oDateTimeProvider) : base(p_oCopriServer, p_strSessionCookie, p_strMail, p_oDateTimeProvider)
{
server = p_oCopriServer as ICopriServer;
if (server == null)
{
throw new ArgumentException($"Copri server is not of expected typ. Type detected is {p_oCopriServer.GetType()}.");
}
server = p_oCopriServer as ICopriServer;
}
/// Gets all stations including postions.
public async Task> GetBikesAndStationsAsync()
{
var stationResponse = await server.GetStationsAsync();
var bikesAvailableResponse = await server.GetBikesAvailableAsync();
var bikesOccupiedResponse = await server.GetBikesOccupiedAsync();
return new Result(
typeof(CopriCallsMonkeyStore),
new StationsAndBikesContainer(
stationResponse.GetStationsAllMutable(),
UpdaterJSON.GetBikesAll(bikesAvailableResponse, bikesOccupiedResponse, Mail, DateTimeProvider)));
}
/// Gets bikes occupied.
/// Collection of bikes.
public async Task> GetBikesOccupiedAsync()
{
return new Result(
typeof(CopriCallsMonkeyStore),
(await server.GetBikesOccupiedAsync()).GetBikesOccupied(Mail, DateTimeProvider));
}
/// Gets bikes available and bikes occupied.
/// Collection of bikes.
public async Task> GetBikesAsync()
{
var l_oBikesAvailableResponse = await server.GetBikesAvailableAsync();
var l_oBikesOccupiedResponse = await server.GetBikesOccupiedAsync();
return new Result(
typeof(CopriCallsMonkeyStore),
UpdaterJSON.GetBikesAll(l_oBikesAvailableResponse, l_oBikesOccupiedResponse, Mail, DateTimeProvider));
}
}
}