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

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

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

    return accessToken;
  }
}
