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

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

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

    return true;
  }
}
