using EnvelopeGenerator.Application.Common.Dto;
using EnvelopeGenerator.Application.DocStatus.Commands;
using EnvelopeGenerator.Application.DocReceiverElements.Commands;
using EnvelopeGenerator.Domain.Constants;
using MediatR;
using System.Text.Json;
namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors;
///
/// Pipeline behavior that creates document status.
/// Executes second in the signing process.
///
public class DocStatusBehavior : IPipelineBehavior
{
private const string BlankAnnotationJson = "{}";
private readonly ISender _sender;
///
///
///
///
public DocStatusBehavior(ISender sender)
{
_sender = sender;
}
///
///
///
///
///
///
///
[Obsolete("This notification is deprecated. Use Signature.Commands.SignCommand instead.")]
public async Task Handle(SigningCommand request, RequestHandlerDelegate next, CancellationToken cancellationToken)
{
await _sender.Send(new CreateDocStatusCommand()
{
EnvelopeId = request.EnvelopeReceiver.EnvelopeId,
ReceiverId = request.EnvelopeReceiver.ReceiverId,
Value = request.PsPdfKitAnnotation is PsPdfKitAnnotation annot
? JsonSerializer.Serialize(annot.Instant, Format.Json.ForAnnotations)
: BlankAnnotationJson
}, cancellationToken);
return await next(cancellationToken);
}
}