/**
 * @aurora-catalyst-generated
 * @source cliter/iam/user.aurora.yaml
 */
import { IamUpdateUsersInput, IamUser } from '@api/graphql';
import { IamGetUsersService, IamUpdateUsersService } from '@app/iam/user';
import { IamUserFieldSchema } from '@app/iam/user/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 IamUpdateUsersHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdateUsersService,
    private readonly getService: IamGetUsersService,
  ) {}

  @EmitEvent('iam.user.updated')
  @ApplySchema(IamUserFieldSchema)
  async main(
    payload: IamUpdateUsersInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamUser[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

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