/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/refresh-token.aurora.yaml
 */
import { OAuthRefreshToken } from '@api/graphql';
import { OAuthFindRefreshTokenByIdService } from '@app/o-auth/refresh-token';
import { OAuthRefreshTokenFieldSchema } from '@app/o-auth/refresh-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 OAuthFindRefreshTokenByIdHandler {
  constructor(private readonly findByIdService: OAuthFindRefreshTokenByIdService) {}

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

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

    return refreshToken;
  }
}
