import {XToken, AccountName, Username} from '@configs/types';
import {VersionType} from '@helper/version';
import {MyUserAccount} from '@user/types';
import {APP_VERSION} from './appNonSaveVar';
import {ThemeMode} from './colors';

export function applyUpdateChanges(appVar: any): Promise<void> {
  return new Promise<void>(function (resolve, reject) {
    appVar.version += 1;

    console.log(appVar.version);

    function finish() {
      resolve();
    }

    switch (appVar.version) {
      case 3: {
        let appVarF = appVar as PREFERENCES_VARS;

        appVar = appVarF;
        finish();
        break;
      }

      case 2: {
        let appVarF = appVar;

        appVar = appVarF;
        finish();
        break;
      }

      default: {
        finish();
        break;
      }
    }
  });
}

//these variables may be changed by the user and will be saved in storage
export interface RegisterProcess {
  //isRegistering: false | 'stepTwo' | 'stepFinal';
  //XToken: XToken | undefined;
  Username: Username;
  Password: string;
  AccountName: AccountName;
}

export interface PREFERENCES_VARS {
  dbek: number; //db encryption key
  version: VersionType;
  theme: ThemeMode;
  RegisterProcess: RegisterProcess;
  selectedAccount: AccountName | 'none';
  accounts: {[key: AccountName]: MyUserAccount};
}

export const preferences_vars_default: PREFERENCES_VARS = {
  dbek: -5,
  version: APP_VERSION, //version of datatypes in storage
  theme: ThemeMode.Dark,
  RegisterProcess: {
    Username: '',
    Password: '',
    //isRegistering: false,
    //XToken: undefined,
    AccountName: '',
  },
  selectedAccount: 'none',
  accounts: {},
};
