import { LoginState } from "../session-states/login-state.enum" ; import { Database } from "../../database/database" ; import { SyncState } from "../session-states/sync-state.enum" ; import { DatabaseUser } from "./local-user" ; import { BehaviorSubject } from "rxjs" ; /**
 * A session manages user authentication and database connection for the app.
 *
 * To get the current user object in any other class, inject the SessionService.
 *
 * The SessionService also sets up and provides the Database.
 * To access the database in other classes
 * you should rather inject the `Database` or the `EntityMapperService` directly and not the SessionService, however.
 *
 * This SessionService is the abstract base class for the concrete implementations like SyncedSessionService.
 * You should still use `SessionService` as the dependency injection key to get access to the functionality.
 * Providers are set up in a way that you will get the correct implementation during runtime.
 */ export abstract class SessionService { /** StateHandler for login state changes */ private _loginState = new BehaviorSubject ( LoginState . LOGGED_OUT ) ; /** StateHandler for sync state changes */ private _syncState = new BehaviorSubject ( SyncState . UNSYNCED ) ; param username param password abstract login ( username , password ) ; /**
     * Logout the current user.
     */ abstract logout ( ) ; /**
     * Get the current user according to the CouchDB format
     */ abstract getCurrentUser ( ) ; param username param password returns abstract checkPassword ( username , password ) ; /**
     * Get the session status - whether a user is authenticated currently.
     */ public isLoggedIn ( ) { return this . loginState . value === LoginState . LOGGED_IN ; } /**
     * Get the state of the session.
     */ public get loginState ( ) : BehaviorSubject < LoginState > { return this . _loginState ; } /**
     * Get the state of the synchronization with the remote server.
     */ public get syncState ( ) : BehaviorSubject < SyncState > { return this . _syncState ; } /**
     * Start a synchronization process.
     */ abstract sync ( ) ; /**
     * Get the database for the current session.
     */ abstract getDatabase ( ) ; }