import {
  Model,
  DataTypes,
  CreationOptional,
  InferAttributes,
  InferCreationAttributes,
} from 'sequelize';
import sequelize from '../sequelizeInstance';

class Dict extends Model<
  // eslint-disable-next-line no-use-before-define
  InferAttributes<Dict>,
  // eslint-disable-next-line no-use-before-define
  InferCreationAttributes<Dict>
> {
  declare id: CreationOptional<number>;

  declare key: string;

  declare val: string;

  declare createdAt: CreationOptional<Date>;

  declare updatedAt: CreationOptional<Date>;
}

Dict.init(
  {
    id: {
      type: DataTypes.INTEGER,
      autoIncrement: true,
      primaryKey: true,
    },
    key: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    val: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    createdAt: DataTypes.DATE,
    updatedAt: DataTypes.DATE,
  },
  {
    sequelize,
    modelName: 'Dict',
    underscored: true,
    tableName: 'dict',
  }
);

export type DictCreationAttributes = InferCreationAttributes<
  Dict,
  { omit: 'id' | 'createdAt' | 'updatedAt' }
>;

export default Dict;
