/**
 * @aurora-catalyst-generated
 * @source cliter/iam/tag.aurora.yaml
 */
import { IamTag } from '@api/graphql';
import { IamFindTagService } from '@app/iam/tag';
import { IamTagFieldSchema } from '@app/iam/tag/domain';
import { Format, HandlerMeta } from '@aurorajs.dev/core-back';
import { QueryStatement } from '@aurorajs.dev/core-common';
import { Injectable, NotFoundException } from '@nestjs/common';

@Injectable()
export class IamFindTagHandler {
  constructor(private readonly findService: IamFindTagService) {}

  @Format(IamTagFieldSchema)
  async main(
    queryStatement?: QueryStatement,
    constraint?: QueryStatement,
    handlerMeta?: HandlerMeta,
  ): Promise<IamTag> {
    const tag = await this.findService.main(queryStatement, constraint, handlerMeta);

    if (!tag) {
      throw new NotFoundException(`IamTag not found`);
    }

    return tag;
  }
}
