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 livetime of COPRI cache entries. ManagePolling = 8, // Turn polling off or on and set pollig frequency. PickLockServiceImplementation = 16, // Allows to pick the implementation which controls bluetooth lock mangement. 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. All = PickCopriServer + ManageCopriCacheExpiration + ManagePolling + PickLockServiceImplementation + PickLocationServiceImplementation + PickLoggingLevel + ShowDiagnostics + SwitchNoSiteCaching + ReportLevel, } /// /// 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 { /// Constructs an account object. /// Mail address of the account holder. /// Password. /// Session cookie from copri. /// Group holdig info about Group (TINK, Konrad, ...) /// Flag which controls display of debug settings. public Account( string mail, string password, string sessionCookie, IEnumerable bikeGroup, Permissions debugLevel = Permissions.None) { Mail = mail; Pwd = password; 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 p_oSource) : this(p_oSource?.Mail, p_oSource?.Pwd, p_oSource?.SessionCookie, p_oSource?.Group, p_oSource?.DebugLevel ?? Permissions.None) { } /// Mail address of the account holder. public string Mail { get; } /// Password of to authenticate. public string Pwd { 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; } } }