/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/access-token.aurora.yaml
 */
import { OAuthAccessToken } from '@api/graphql';
import { OAuthFindAccessTokenService } from '@app/o-auth/access-token';
import { OAuthAccessTokenFieldSchema } from '@app/o-auth/access-token/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 OAuthFindAccessTokenHandler {
  constructor(private readonly findService: OAuthFindAccessTokenService) {}

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

    if (!accessToken) {
      throw new NotFoundException(`OAuthAccessToken not found`);
    }

    return accessToken;
  }
}
