/**
 * @aurora-catalyst-generated
 * @source cliter/iam/permission-role.aurora.yaml
 */
import { IamPermissionRole, IamUpdatePermissionsRolesInput } from '@api/graphql';
import {
  IamGetPermissionsRolesService,
  IamUpdatePermissionsRolesService,
} from '@app/iam/permission-role';
import { IamPermissionRoleFieldSchema } from '@app/iam/permission-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 IamUpdatePermissionsRolesHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdatePermissionsRolesService,
    private readonly getService: IamGetPermissionsRolesService,
  ) {}

  @EmitEvent('iam.permissionRole.updated')
  @ApplySchema(IamPermissionRoleFieldSchema)
  async main(
    payload: IamUpdatePermissionsRolesInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamPermissionRole[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

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