/**
 * @aurora-catalyst-generated
 * @source cliter/iam/role-account.aurora.yaml
 */
import { IamRoleAccount, IamUpdateRolesAccountsInput } from '@api/graphql';
import { IamGetRolesAccountsService, IamUpdateRolesAccountsService } from '@app/iam/role-account';
import { IamRoleAccountFieldSchema } from '@app/iam/role-account/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 IamUpdateRolesAccountsHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdateRolesAccountsService,
    private readonly getService: IamGetRolesAccountsService,
  ) {}

  @EmitEvent('iam.roleAccount.updated')
  @ApplySchema(IamRoleAccountFieldSchema)
  async main(
    payload: IamUpdateRolesAccountsInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamRoleAccount[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

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