/**
 * @aurora-catalyst-generated
 * @source cliter/iam/tenant-account.aurora.yaml
 */
import { IamTenantAccount, IamUpdateTenantsAccountsInput } from '@api/graphql';
import {
  IamGetTenantsAccountsService,
  IamUpdateTenantsAccountsService,
} from '@app/iam/tenant-account';
import { IamTenantAccountFieldSchema } from '@app/iam/tenant-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 IamUpdateTenantsAccountsHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdateTenantsAccountsService,
    private readonly getService: IamGetTenantsAccountsService,
  ) {}

  @EmitEvent('iam.tenantAccount.updated')
  @ApplySchema(IamTenantAccountFieldSchema)
  async main(
    payload: IamUpdateTenantsAccountsInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamTenantAccount[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

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