/**
 * @aurora-catalyst-generated
 * @source cliter/iam/role.aurora.yaml
 */
import { IamRole } from '@api/graphql';
import { IamFindRoleService } from '@app/iam/role';
import { IamRoleFieldSchema } from '@app/iam/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 IamFindRoleHandler {
  constructor(private readonly findService: IamFindRoleService) {}

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

    if (!role) {
      throw new NotFoundException(`IamRole not found`);
    }

    return role;
  }
}
