/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/authorization-code.aurora.yaml
 */
import { OAuthAuthorizationCode } from '@api/graphql';
import { OAuthFindAuthorizationCodeService } from '@app/o-auth/authorization-code';
import { OAuthAuthorizationCodeFieldSchema } from '@app/o-auth/authorization-code/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 OAuthFindAuthorizationCodeHandler {
  constructor(private readonly findService: OAuthFindAuthorizationCodeService) {}

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

    if (!authorizationCode) {
      throw new NotFoundException(`OAuthAuthorizationCode not found`);
    }

    return authorizationCode;
  }
}
