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

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

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

    return true;
  }
}
