import {ApiService} from './api.service';

export default class AppStorage
{
  private static readonly LAST_VERSION_CHECK: string = 'lastVersionCheck';
  private static readonly IS_UPDATE_NOTIFICATION_DESIRED: string = 'isUpdateNotificationDesired';
  private static readonly TOKEN: string = 'token';
  private static readonly USER_ID: string = 'userId';
  private static readonly CHAT_TOKEN: string = 'chatToken';
  private static readonly LAST_LOGIN_NAME: string = 'lastLoginName';

  public static getChatToken(): string
  {
    return sessionStorage.getItem(this.CHAT_TOKEN);
  }

  public static getLastLoginName(): string
  {
    return localStorage.getItem(this.LAST_LOGIN_NAME);
  }

  public static getLastVersionCheck(): number
  {
    const lastCheck = localStorage.getItem(this.LAST_VERSION_CHECK);

    return lastCheck === null ? null : Number(lastCheck);
  }

  public static getToken(): string
  {
    return sessionStorage.getItem(this.TOKEN);
  }

  public static getUserId(): number
  {
    const userId = sessionStorage.getItem(this.USER_ID);

    return userId === null ? null : Number(userId);
  }

  public static isUpdateNotificationDesired(): boolean
  {
    const isDesired = localStorage.getItem(this.IS_UPDATE_NOTIFICATION_DESIRED);

    return isDesired === null ? true : isDesired === 'true';
  }

  public static setChatToken(chatToken: string): void
  {
    sessionStorage.setItem(this.CHAT_TOKEN, chatToken);
  }

  public static setIsUpdateNotificationDesired(isDesired: boolean): void
  {
    localStorage.setItem(this.IS_UPDATE_NOTIFICATION_DESIRED, isDesired.toString());
  }

  public static setLastLoginName(loginName: string): void
  {
    localStorage.setItem(this.LAST_LOGIN_NAME, loginName);
  }

  public static setLastVersionCheck(versionCheck: number): void
  {
    localStorage.setItem(this.LAST_VERSION_CHECK, versionCheck.toString());
  }

  public static setToken(token: string): void
  {
    sessionStorage.setItem(this.TOKEN, token);
  }

  public static setUserId(userId: number): void
  {
    sessionStorage.setItem(this.USER_ID, userId.toString());
  }
}
