/**
 * @aurora-catalyst-generated
 * @source cliter/iam/role-account.aurora.yaml
 */
import { IamRoleAccount } from '@api/graphql';
import { IamFindRoleAccountByIdService } from '@app/iam/role-account';
import { IamRoleAccountFieldSchema } from '@app/iam/role-account/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 IamFindRoleAccountByIdHandler {
  constructor(private readonly findByIdService: IamFindRoleAccountByIdService) {}

  @Format(IamRoleAccountFieldSchema)
  async main(
    roleId: string,
    accountId: string,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamRoleAccount> {
    const roleAccount = await this.findByIdService.main(roleId, accountId, constraint, handlerMeta);

    if (!roleAccount) {
      throw new NotFoundException(
        `IamRoleAccount with roleId: ${roleId}, accountId: ${accountId}, not found`,
      );
    }

    return roleAccount;
  }
}
