/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/client.aurora.yaml
 */
import { OAuthClient } from '@api/graphql';
import { OAuthFindClientService } from '@app/o-auth/client';
import { OAuthClientFieldSchema } from '@app/o-auth/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 OAuthFindClientHandler {
  constructor(private readonly findService: OAuthFindClientService) {}

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

    if (!client) {
      throw new NotFoundException(`OAuthClient not found`);
    }

    return client;
  }
}
