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

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

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

    return user;
  }
}
