/**
 * @aurora-catalyst-generated
 * @source cliter/iam/user.aurora.yaml
 */
import { IamUser } from '@api/graphql';
import { IamFindUserService } from '@app/iam/user';
import { IamUserFieldSchema } from '@app/iam/user/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 IamFindUserHandler {
  constructor(private readonly findService: IamFindUserService) {}

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

    if (!user) {
      throw new NotFoundException(`IamUser not found`);
    }

    return user;
  }
}
