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

  @EmitEvent('iam.boundedContext.deleted')
  @Format(IamBoundedContextFieldSchema)
  async main(
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamBoundedContext[]> {
    const boundedContexts = await this.getService.main(queryStatement, constraint, handlerMeta);

    await this.deleteService.main(queryStatement, constraint, handlerMeta);

    return boundedContexts;
  }
}
