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

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

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

    return true;
  }
}
