using System;
using TINK.Model.Services.CopriApi;
using TINK.Model.Repository;
namespace TINK.Model.Connector
{
///
/// Connects tink app to copri by getting data from copri and updating tink app model (i.e. bikes, user, ...)
///
public class ConnectorCache : IConnector
{
/// Constructs a copri connector object.
/// Holds the session cookie.
/// Mail of user.
/// Provides addess to copri.
public ConnectorCache(
string sessionCookie,
string mail,
ICopriServer server = null)
{
Command = Connector.GetCommand(
server ?? new CopriProviderMonkeyStore(TinkApp.MerchantId, sessionCookie),
sessionCookie,
mail);
Query = GetQuery(
server ?? new CopriProviderMonkeyStore(TinkApp.MerchantId, sessionCookie),
sessionCookie,
mail);
}
/// Object for queriying stations and bikes.
public ICommand Command { get; private set; }
/// Object for queriying stations and bikes.
public IQuery Query { get; private set; }
/// True if connector has access to copri server, false if cached values are used.
public bool IsConnected => Command.IsConnected;
/// Gets a command object to perform copri queries.
private static IQuery GetQuery(ICopriServer copri, string sessioncookie, string mail) => string.IsNullOrEmpty(sessioncookie)
? new Query(copri) as IQuery
: new QueryLoggedIn(copri, sessioncookie, mail, () => DateTime.Now);
}
}