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

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

    if (!scope) {
      throw new NotFoundException(`OAuthScope not found`);
    }

    return scope;
  }
}
