/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/scope.aurora.yaml
 */
import { OAuthScope } from '@api/graphql';
import { OAuthFindScopeByIdService } from '@app/o-auth/scope';
import { OAuthScopeFieldSchema } from '@app/o-auth/scope/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 OAuthFindScopeByIdHandler {
  constructor(private readonly findByIdService: OAuthFindScopeByIdService) {}

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

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

    return scope;
  }
}
