import Store from 'electron-store';

const STORE_KEY_AUTORUN = 'options.autoRun';
const STORE_KEY_AUTOLOGIN = 'options.autoLogin';
const STORE_KEY_STARTUPHIDEWINDOW = 'options.startupHideWindow';
const STORE_KEY_LOGINCOMPANY = 'login.loginCompany';
const STORE_KEY_LOGINID = 'login.loginId';
const STORE_KEY_LOGINPW = 'login.loginPw';

export class Storage extends Store<any> {
  constructor() {
    super({
      schema: {
        options: {
          type: 'object',
          properties: {
            autoRun: {
              type: 'boolean'
            },
            autoLogin: {
              type: 'boolean'
            },
            startupHideWindow: {
              type: 'boolean'
            }
          },
          default: {
            autoRun: false,
            autoLogin: false,
            startupHideWindow: false
          }
        },
        login: {
          type: 'object',
          properties: {
            loginCompany: {
              type: 'string'
            },
            loginId: {
              type: 'string'
            },
            loginPw: {
              type: 'string'
            }
          },
          default: {
            loginCompany: '',
            loginId: '',
            loginPw: ''
          }
        }
      },
      encryptionKey: 'ucap',
      fileExtension: 'dat'
    });
  }

  get autoRun(): boolean {
    return this.get(STORE_KEY_AUTORUN, false);
  }
  set autoRun(autoRun: boolean) {
    this.set(STORE_KEY_AUTORUN, autoRun);
  }

  get autoLogin(): boolean {
    return this.get(STORE_KEY_AUTOLOGIN, false);
  }
  set autoLogin(autoLogin: boolean) {
    this.set(STORE_KEY_AUTOLOGIN, autoLogin);
  }

  get startupHideWindow(): boolean {
    return this.get(STORE_KEY_STARTUPHIDEWINDOW, false);
  }
  set startupHideWindow(startupHideWindow: boolean) {
    this.set(STORE_KEY_STARTUPHIDEWINDOW, startupHideWindow);
  }

  get loginCompany(): string {
    return this.get(STORE_KEY_LOGINCOMPANY, false);
  }
  set loginCompany(loginCompany: string) {
    this.set(STORE_KEY_LOGINCOMPANY, loginCompany);
  }

  get loginId(): string {
    return this.get(STORE_KEY_LOGINID, false);
  }
  set loginId(loginId: string) {
    this.set(STORE_KEY_LOGINID, loginId);
  }

  get loginPw(): string {
    return this.get(STORE_KEY_LOGINPW, false);
  }
  set loginPw(loginPw: string) {
    this.set(STORE_KEY_LOGINPW, loginPw);
  }
}
