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

@Injectable()
export class IamUpdateRolesHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdateRolesService,
    private readonly getService: IamGetRolesService,
  ) {}

  @EmitEvent('iam.role.updated')
  @ApplySchema(IamRoleFieldSchema)
  async main(
    payload: IamUpdateRolesInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamRole[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

    return await this.getService.main(queryStatement, constraint, handlerMeta);
  }
}
