/**
 * @aurora-catalyst-generated
 * @source cliter/iam/role.aurora.yaml
 */
import { IamAccountModel } from '@app/iam/account';
import { IamPermissionModel } from '@app/iam/permission';
import { IamPermissionRoleModel } from '@app/iam/permission-role';
import { IamRoleAccountModel } from '@app/iam/role-account';
import { Auditable } from '@aurorajs.dev/core-back';
import { DataTypes } from 'sequelize';
import { BelongsToMany, Column, Model, Table } from 'sequelize-typescript';

@Auditable()
@Table({
  modelName: 'IamRole',
  tableName: 'iam_role',
  freezeTableName: true,
  timestamps: false,
  indexes: [
    {
      fields: ['row_id'],
      unique: true,
    },
    {
      fields: ['code'],
      unique: true,
    },
  ],
})
export class IamRoleModel extends Model<IamRoleModel> {
  @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: 'code',
    allowNull: true,
    type: DataTypes.STRING(64),
  })
  code: string;

  @Column({
    field: 'default_redirection',
    allowNull: true,
    type: DataTypes.STRING(2046),
  })
  defaultRedirection: string;

  @Column({
    field: 'has_hidden_vertical_navigation',
    allowNull: true,
    type: DataTypes.BOOLEAN,
    defaultValue: false,
  })
  hasHiddenVerticalNavigation: boolean;

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

  @BelongsToMany(() => IamPermissionModel, {
    through: () => IamPermissionRoleModel,
    uniqueKey: 'Uq01IamPermissionRole',
  })
  permissions: IamPermissionModel[];

  @BelongsToMany(() => IamAccountModel, {
    through: () => IamRoleAccountModel,
    uniqueKey: 'Uq01IamRoleAccount',
  })
  accounts: IamAccountModel[];

  @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;
}
