/**
 * @aurora-catalyst-generated
 * @source cliter/iam/bounded-context.aurora.yaml
 */
import { IamBoundedContext, IamUpdateBoundedContextsInput } from '@api/graphql';
import {
  IamGetBoundedContextsService,
  IamUpdateBoundedContextsService,
} from '@app/iam/bounded-context';
import { IamBoundedContextFieldSchema } from '@app/iam/bounded-context/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 IamUpdateBoundedContextsHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly updateService: IamUpdateBoundedContextsService,
    private readonly getService: IamGetBoundedContextsService,
  ) {}

  @EmitEvent('iam.boundedContext.updated')
  @ApplySchema(IamBoundedContextFieldSchema)
  async main(
    payload: IamUpdateBoundedContextsInput,
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamBoundedContext[]> {
    await this.updateService.main(payload, queryStatement, constraint, handlerMeta);

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