using System;
using System.Collections.Generic;
using System.Linq;
namespace TINK.Model.User.Account
{
/// Specifies extra user permissions.
[Flags]
public enum Permissions
{
None = 0, // No extra permissions.
PickCopriServer = 2, // Allows user to switch COPRI server.
ManageCopriCacheExpiration = 4, // Allows to manage the live time of COPRI cache entries.
ManagePolling = 8, // Turn polling off or on and set polling frequency.
PickLockServiceImplementation = 16, // Allows to pick the implementation which controls bluetooth lock management.
PickLocationServiceImplementation = 32, // Allows to pick the implementation which gets location information.
PickLoggingLevel = 64, // Allows to select the logging level.
ShowDiagnostics = 128, // Turns on display of diagnostics.
SwitchNoSiteCaching = 1024, // Allows to turn off/ on caching of sites displayed in app hosted by COPRI
ReportLevel = 2048, // Allows extent to show error messages.
SwitchTheme = 4096, // Allows user to switch theme (sharee.bike, Mein konrad, LastenRad Bayern)
All = PickCopriServer +
ManageCopriCacheExpiration +
ManagePolling +
PickLockServiceImplementation +
PickLocationServiceImplementation +
PickLoggingLevel +
ShowDiagnostics +
SwitchNoSiteCaching +
ReportLevel +
SwitchTheme,
}
///
/// Specifies parts of account data.
///
///
/// Usage: Account can be valid (user and password set) partly valid or completely invalid.
///
[Flags]
public enum Elements
{
None = 0,
Mail = 1,
Password = 2,
Account = Mail + Password
}
///
/// Holds account data.
///
public class Account : IAccount
{
public const bool DEFAULTISAGBACKNOWLEDGED = false;
/// Constructs an account object.
/// Mail address of the account holder.
/// Password.
/// Session cookie from copri.
/// Group holding info about Group (TINK, Konrad, ...)
/// Flag which controls display of debug settings.
public Account(
string mail,
string password,
bool isAgbAcknowledged,
string sessionCookie,
IEnumerable bikeGroup,
Permissions debugLevel = Permissions.None)
{
Mail = mail;
Pwd = password;
IsAgbAcknowledged = isAgbAcknowledged;
SessionCookie = sessionCookie;
DebugLevel = debugLevel;
Group = bikeGroup != null
? new HashSet(bikeGroup).ToList()
: throw new ArgumentException("Can not instantiate account object. Reference to group list must not be empty.");
}
public Account(IAccount source) : this(source?.Mail, source?.Pwd, source?.IsAgbAcknowledged ?? DEFAULTISAGBACKNOWLEDGED, source?.SessionCookie, source?.Group, source?.DebugLevel ?? Permissions.None)
{
}
/// Mail address of the account holder.
public string Mail { get; }
/// Password of to authenticate.
public string Pwd { get; }
/// True if user acknowledged AGBs.
public bool IsAgbAcknowledged { get; }
/// Session cookie used to sign in to copri.
public string SessionCookie { get; }
/// Debug level used to determine which features are available.
public Permissions DebugLevel { get; }
/// Holds the group of the bike (TINK, Konrad, ...).
public IEnumerable Group { get; }
}
}