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

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

    if (!role) {
      throw new NotFoundException(`IamRole with id: ${id}, not found`);
    }

    return role;
  }
}
