/**
 * @aurora-catalyst-generated
 * @source cliter/iam/bounded-context.aurora.yaml
 */
import { IamPermissionModel } from '@app/iam/permission';
import { Auditable } from '@aurorajs.dev/core-back';
import { DataTypes } from 'sequelize';
import { Column, HasMany, Model, Table } from 'sequelize-typescript';

@Auditable()
@Table({
  modelName: 'IamBoundedContext',
  tableName: 'iam_bounded_context',
  freezeTableName: true,
  timestamps: false,
  indexes: [
    {
      fields: ['row_id'],
      unique: true,
    },
  ],
})
export class IamBoundedContextModel extends Model<IamBoundedContextModel> {
  @Column({
    field: 'id',
    primaryKey: true,
    allowNull: false,
    type: DataTypes.UUID,
  })
  id: string;

  @Column({
    field: 'row_id',
    autoIncrement: true,
    allowNull: false,
    type: DataTypes.BIGINT,
  })
  rowId: number;

  @Column({
    field: 'name',
    allowNull: false,
    type: DataTypes.STRING(128),
  })
  name: string;

  @Column({
    field: 'root',
    allowNull: false,
    type: DataTypes.STRING(64),
  })
  root: string;

  @Column({
    field: 'sort',
    allowNull: true,
    type: DataTypes.SMALLINT,
  })
  sort: number;

  @Column({
    field: 'is_active',
    allowNull: false,
    type: DataTypes.BOOLEAN,
    defaultValue: false,
  })
  isActive: boolean;

  @HasMany(() => IamPermissionModel, {
    constraints: false,
  })
  permissions: IamPermissionModel[];

  @Column({
    field: 'created_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  createdAt: string;

  @Column({
    field: 'updated_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  updatedAt: string;

  @Column({
    field: 'deleted_at',
    allowNull: true,
    type: DataTypes.DATE,
  })
  deletedAt: string;
}
