/**
 * @aurora-catalyst-generated
 * @source cliter/iam/tag.aurora.yaml
 */
import { IamCreateTagInput, IamTag } from '@api/graphql';
import { IamCreateTagService, IamFindTagByIdService } from '@app/iam/tag';
import { IamTagFieldSchema } from '@app/iam/tag/domain';
import { ApplySchema, EmitEvent, HandlerMeta } from '@aurorajs.dev/core-back';
import { Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';

@Injectable()
export class IamCreateTagHandler {
  constructor(
    private readonly eventEmitter: EventEmitter2,
    private readonly createService: IamCreateTagService,
    private readonly findByIdService: IamFindTagByIdService,
  ) {}

  @EmitEvent('iam.tag.created')
  @ApplySchema(IamTagFieldSchema)
  async main(payload: IamCreateTagInput, handlerMeta?: HandlerMeta): Promise<IamTag> {
    await this.createService.main(payload, handlerMeta);

    return await this.findByIdService.main(payload.id, {}, handlerMeta);
  }
}
