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

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

    if (!tenantAccount) {
      throw new NotFoundException(`IamTenantAccount not found`);
    }

    return tenantAccount;
  }
}
