using EnvelopeGenerator.Application.Common.Interfaces.Services.Notification; using EnvelopeGenerator.Application.DocReceiverElements.Commands; using EnvelopeGenerator.Domain.Interfaces; using MediatR; namespace EnvelopeGenerator.Application.DocReceiverElements.Behaviors; /// /// Pipeline behavior that sends signed mail notification. /// Executes LAST in the signing process - only if all previous behaviors succeed. /// /// /// /// /// public class SendSignedMailBehavior(IEnvelopeNotificationService NtfService) : IPipelineBehavior { /// /// /// /// /// /// /// public async Task Handle(SigningCommand request, RequestHandlerDelegate next, CancellationToken cancellationToken) { var email = request.EnvelopeReceiver.Receiver!.EmailAddress; await NtfService.Notify(email, new DocumentSignedNotification() { DocumentTitle = request.EnvelopeReceiver.Envelope?.Title ?? string.Empty, IsReadAndConfirm = request.EnvelopeReceiver.Envelope.IsReadAndConfirm(), NameReceiver = request.EnvelopeReceiver.Name ?? string.Empty, }, cancellationToken); return await next(cancellationToken); } }