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

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

    if (!client) {
      throw new NotFoundException(`OAuthClient with id: ${id}, not found`);
    }

    return client;
  }
}
