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

@Injectable()
export class IamFindPermissionRoleHandler {
  constructor(private readonly findService: IamFindPermissionRoleService) {}

  @Format(IamPermissionRoleFieldSchema)
  async main(
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamPermissionRole> {
    const permissionRole = await this.findService.main(queryStatement, constraint, handlerMeta);

    if (!permissionRole) {
      throw new NotFoundException(`IamPermissionRole not found`);
    }

    return permissionRole;
  }
}
