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

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

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

    return true;
  }
}
