using DigitalData.Core.Abstraction.Application.Repository; using DigitalData.Core.Exceptions; using EnvelopeGenerator.Application.Common.Dto; using EnvelopeGenerator.Application.DocReceiverElements.Commands; using EnvelopeGenerator.Domain.Entities; using MediatR; namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors; /// /// Pipeline behavior that saves annotations. /// Executes first in the signing process. /// [Obsolete("The PSPDFKit library is deprecated.")] public class AnnotationBehavior : IPipelineBehavior { private readonly IRepository _repo; /// /// Initializes a new instance of the class. /// /// public AnnotationBehavior(IRepository repository) { _repo = repository; } /// /// /// /// /// /// /// public async Task Handle(SigningCommand request, RequestHandlerDelegate next, CancellationToken cancel) { if(request.ReceiverAppType != ReceiverAppType.LegacyWeb) if(request.PsPdfKitAnnotation is null) return await next(cancel); else throw new BadRequestException("PsPdfKit Annotation are only supported for the legacy web receiver type."); if (request.PsPdfKitAnnotation is PsPdfKitAnnotation annot) await _repo.CreateAsync(annot.Structured, cancel); else throw new BadRequestException("Annotation data is missing or invalid."); return await next(cancel); } }