/**
 * @aurora-catalyst-generated
 * @source cliter/iam/user.aurora.yaml
 */
import { IamCreateUserInput } from '@api/graphql';
import { IamCreateUsersService } from '@app/iam/user';
import { IamUserFieldSchema } from '@app/iam/user/domain';
import { ApplySchema, EmitEvent, HandlerMeta } from '@aurorajs.dev/core-back';
import { Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';

@Injectable()
export class IamCreateUsersHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly createService: IamCreateUsersService,
  ) {}

  @EmitEvent('iam.user.created', { returnInputPayload: true })
  @ApplySchema(IamUserFieldSchema)
  async main(payload: IamCreateUserInput[], handlerMeta?: HandlerMeta): Promise<boolean> {
    await this.createService.main(payload, handlerMeta);

    return true;
  }
}
