/**
 * @aurora-catalyst-generated
 * @source cliter/iam/account.aurora.yaml
 */
import { IamAccount, IamUpdateAccountsInput } from '@api/graphql';
import { IamGetAccountsService, IamUpdateAccountsService } from '@app/iam/account';
import { IamAccountFieldSchema } from '@app/iam/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 IamUpdateAccountsHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdateAccountsService,
    private readonly getService: IamGetAccountsService,
  ) {}

  @EmitEvent('iam.account.updated')
  @ApplySchema(IamAccountFieldSchema)
  async main(
    payload: IamUpdateAccountsInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamAccount[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

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