/**
 * @aurora-catalyst-generated
 * @source cliter/iam/tenant.aurora.yaml
 */
import { IamTenant, IamUpdateTenantsInput } from '@api/graphql';
import { IamGetTenantsService, IamUpdateTenantsService } from '@app/iam/tenant';
import { IamTenantFieldSchema } from '@app/iam/tenant/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 IamUpdateTenantsHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdateTenantsService,
    private readonly getService: IamGetTenantsService,
  ) {}

  @EmitEvent('iam.tenant.updated')
  @ApplySchema(IamTenantFieldSchema)
  async main(
    payload: IamUpdateTenantsInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamTenant[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

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