/**
 * @aurora-catalyst-generated
 * @source cliter/o-auth/credential.aurora.yaml
 */
import { OAuthCredential } from '@api/graphql';
import { OAuthFindCredentialService } from '@app/o-auth/credential';
import { OAuthCredentialFieldSchema } from '@app/o-auth/credential/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 OAuthFindCredentialHandler {
  constructor(private readonly findService: OAuthFindCredentialService) {}

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

    if (!credential) {
      throw new NotFoundException(`OAuthCredential not found`);
    }

    return credential;
  }
}
