/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/application-client.aurora.yaml
 */
import { OAuthApplicationClient } from '@api/graphql';
import { OAuthFindApplicationClientByIdService } from '@app/o-auth/application-client';
import { OAuthApplicationClientFieldSchema } from '@app/o-auth/application-client/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 OAuthFindApplicationClientByIdHandler {
  constructor(private readonly findByIdService: OAuthFindApplicationClientByIdService) {}

  @Format(OAuthApplicationClientFieldSchema)
  async main(
    applicationId: string,
    clientId: string,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<OAuthApplicationClient> {
    const applicationClient = await this.findByIdService.main(
      applicationId,
      clientId,
      constraint,
      handlerMeta,
    );

    if (!applicationClient) {
      throw new NotFoundException(
        `OAuthApplicationClient with applicationId: ${applicationId}, clientId: ${clientId}, not found`,
      );
    }

    return applicationClient;
  }
}
