import {
  CreationOptional,
  DataTypes,
  InferAttributes,
  InferCreationAttributes,
  Model,
  Sequelize,
} from "sequelize";

export type {{pascalCase name}}CreationAttributes = InferCreationAttributes<{{pascalCase name}}Model, {}> & {};

/**
 * Modelo Sequelize (infraestructura, no dominio)
 */
export class {{pascalCase name}}Model extends Model<
  InferAttributes<{{pascalCase name}}Model>,
  InferCreationAttributes<{{pascalCase name}}Model>
> {
  declare id: string;
  declare company_id: string;
  declare status: CreationOptional<string>;
  declare created_at: CreationOptional<Date>;
  declare updated_at: CreationOptional<Date>;
  declare deleted_at: CreationOptional<Date | null>;

  static associate(database: Sequelize) {
    // TODO: definir relaciones si aplica
  }

  static hooks(database: Sequelize) {
    // TODO: definir hooks si aplica
  }
}

export default (database: Sequelize) => {
  {{pascalCase name}}Model.init(
    {
      id: { type: DataTypes.UUID, primaryKey: true },
      company_id: { type: DataTypes.UUID, allowNull: false },
      status: { type: DataTypes.STRING, allowNull: false, defaultValue: "active" },
      created_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
      updated_at: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
      deleted_at: { type: DataTypes.DATE, allowNull: true, defaultValue: null },
    },
    {
      sequelize: database,
      tableName: "{{snakeCase plural}}",
      underscored: true,
      paranoid: true,
      timestamps: true,
      createdAt: "created_at",
      updatedAt: "updated_at",
      deletedAt: "deleted_at",
      indexes: [
        { name: "company_idx", fields: ["company_id"], unique: false },
        { name: "idx_company_idx", fields: ["id", "company_id"], unique: true },
      ],
      whereMergeStrategy: "and",
      defaultScope: {},
      scopes: {},
    }
  );
  return {{pascalCase name}}Model;
};
