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

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

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

    return authorizationCode;
  }
}
