/**
 * @aurora-catalyst-generated
 * @source cliter/iam/permission-role.aurora.yaml
 */
import { IamPermissionRole } from '@api/graphql';
import { IamSequelizePermissionRoleRepository } from '@app/iam/permission-role';
import { HandlerMeta } from '@aurorajs.dev/core-back';
import { Injectable } from '@nestjs/common';

@Injectable()
export class IamCreatePermissionRoleService {
  constructor(private readonly repository: IamSequelizePermissionRoleRepository) {}

  async main(payload: any, handlerMeta?: HandlerMeta): Promise<void> {
    await this.repository.create(payload, {
      createOptions: handlerMeta?.repositoryOptions,
      finderQueryStatement: (aggregate: IamPermissionRole) => ({
        where: {
          permissionId: aggregate.permissionId,
          roleId: aggregate.roleId,
        },
      }),
    });
  }
}
