/**
 * @aurora-catalyst-generated
 * @source cliter/iam/tenant-account.aurora.yaml
 */
import { IamTenantAccount } from '@api/graphql';
import { IamFindTenantAccountByIdService } from '@app/iam/tenant-account';
import { IamTenantAccountFieldSchema } from '@app/iam/tenant-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 IamFindTenantAccountByIdHandler {
  constructor(private readonly findByIdService: IamFindTenantAccountByIdService) {}

  @Format(IamTenantAccountFieldSchema)
  async main(
    tenantId: string,
    accountId: string,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamTenantAccount> {
    const tenantAccount = await this.findByIdService.main(
      tenantId,
      accountId,
      constraint,
      handlerMeta,
    );

    if (!tenantAccount) {
      throw new NotFoundException(
        `IamTenantAccount with tenantId: ${tenantId}, accountId: ${accountId}, not found`,
      );
    }

    return tenantAccount;
  }
}
