/**
 * @aurora-catalyst-generated
 * @source cliter/iam/permission-role.aurora.yaml
 */
import { IamPermissionModel } from '@app/iam/permission';
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: 'IamPermissionRole',
  tableName: 'iam_permission_role',
  freezeTableName: true,
  timestamps: false,
})
export class IamPermissionRoleModel extends Model<IamPermissionRoleModel> {
  @ForeignKey(() => IamPermissionModel)
  @Column({
    field: 'permission_id',
    primaryKey: true,
    allowNull: false,
    type: DataTypes.UUID,
  })
  permissionId: string;

  @BelongsTo(() => IamPermissionModel, {
    constraints: false,
    foreignKey: 'permission_id',
  })
  permission: IamPermissionModel;

  @ForeignKey(() => IamRoleModel)
  @Column({
    field: 'role_id',
    primaryKey: true,
    allowNull: false,
    type: DataTypes.UUID,
  })
  roleId: string;

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