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

@Auditable()
@Table({
  modelName: 'IamRoleAccount',
  tableName: 'iam_role_account',
  freezeTableName: true,
  timestamps: false,
})
export class IamRoleAccountModel extends Model<IamRoleAccountModel> {
  @ForeignKey(() => IamRoleModel)
  @Column({
    field: 'role_id',
    primaryKey: true,
    allowNull: false,
    type: DataTypes.UUID,
  })
  roleId: string;

  @BelongsTo(() => IamRoleModel, {
    constraints: false,
    foreignKey: 'role_id',
  })
  role: IamRoleModel;

  @ForeignKey(() => IamAccountModel)
  @Column({
    field: 'account_id',
    primaryKey: true,
    allowNull: false,
    type: DataTypes.UUID,
  })
  accountId: string;

  @BelongsTo(() => IamAccountModel, {
    constraints: false,
    foreignKey: 'account_id',
  })
  account: IamAccountModel;
}
