import { openDB } from 'idb';
import { IDB_NAME, IDB_T_NAME__ACCESS_TOKEN, IDB_T_NAME__USER_DATA, IDB_T_NAME__PRIVILEGE } from './storage.key';

export const appConfig = openDB(IDB_NAME, 3, {
  upgrade(db) {
    if (!db.objectStoreNames.contains(IDB_T_NAME__ACCESS_TOKEN)) {
      db.createObjectStore(IDB_T_NAME__ACCESS_TOKEN, {
        keyPath: 'id',
        autoIncrement: false,
      });
    }

    if (!db.objectStoreNames.contains(IDB_T_NAME__USER_DATA)) {
      db.createObjectStore(IDB_T_NAME__USER_DATA, {
        keyPath: 'id',
        autoIncrement: false,
      });
    }

    if (!db.objectStoreNames.contains(IDB_T_NAME__PRIVILEGE)) {
      db.createObjectStore(IDB_T_NAME__PRIVILEGE, {
        keyPath: 'id',
        autoIncrement: false,
      });
    }
  },
});
