/* eslint-disable @typescript-eslint/lines-between-class-members */
import { CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model } from 'sequelize';

export class ArchiveLock extends Model<InferAttributes<ArchiveLock>, InferCreationAttributes<ArchiveLock>> {
  declare id: CreationOptional<string>;
  declare locked_by?: string | null;
  declare locked_at?: number | null;
  declare expires_at?: number | null;
  declare created_at: CreationOptional<Date>;
  declare updated_at: CreationOptional<Date>;

  public static readonly GENESIS_ATTRIBUTES = {
    id: {
      type: DataTypes.STRING(40),
      primaryKey: true,
      allowNull: false,
    },
    locked_by: {
      type: DataTypes.STRING(64),
      allowNull: true,
    },
    locked_at: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    expires_at: {
      type: DataTypes.INTEGER,
      allowNull: true,
    },
    created_at: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      allowNull: false,
    },
    updated_at: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
      allowNull: false,
    },
  };

  public static initialize(sequelize: any) {
    this.init(ArchiveLock.GENESIS_ATTRIBUTES, {
      sequelize,
      modelName: 'ArchiveLock',
      tableName: 'archive_locks',
      createdAt: 'created_at',
      updatedAt: 'updated_at',
    });
  }

  public static associate() {}
}

export type TArchiveLock = InferAttributes<ArchiveLock>;
