import {getEntry} from '../get';
import {DBMigration} from '../migration';
import {setEntry} from '../set';

import {databaseConf, possibleDBKeys} from '../types';

const name = 'chat';
const primaryKey: keyof typeof propsDefault = 'UserId';

const propsType: {[key in keyof typeof propsDefault]: string} = {
  UserId: 'string',
  msg: 'string',
};

const propsDefault = {
  UserId: 'test',
  msg: 'test',
};

const thisSchema: databaseConf<typeof propsDefault> = {
  filePath: name,
  version: 1,
  migration: () => {
    return DBMigration[name](thisSchema);
  },
  setEntry: (val: typeof thisSchema.defaultProps) => {
    return setEntry<typeof thisSchema, typeof thisSchema.defaultProps>(
      thisSchema,
      val,
    );
  },
  getEntry: (key: possibleDBKeys) => {
    return getEntry<typeof thisSchema, typeof thisSchema.defaultProps>(
      thisSchema,
      key,
    );
  },
  defaultProps: propsDefault,
  details: {
    name,
    properties: propsType,
    primaryKey,
  },
};

export default thisSchema;
