using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver; using EnvelopeGenerator.Domain.Constants; using MediatR; using Newtonsoft.Json; using System.Dynamic; namespace EnvelopeGenerator.Application.Common.Notifications.DocSigned; /// /// /// /// public record DocSignedNotification(EnvelopeReceiverDto Original) : EnvelopeReceiverDto(Original), INotification, ISendMailNotification { /// /// /// public required ExpandoObject Annotations { get; init; } /// /// /// public EmailTemplateType TemplateType => EmailTemplateType.DocumentSigned; /// /// /// public string EmailAddress => Receiver?.EmailAddress ?? throw new InvalidOperationException($"Receiver is null." + $"DocSignedNotification:\n{JsonConvert.SerializeObject(this, Format.Json.ForDiagnostics)}"); } /// /// /// public static class DocSignedNotificationExtensions { /// /// Converts an to a . /// /// The DTO to convert. /// /// A new instance. public static DocSignedNotification ToDocSignedNotification(this EnvelopeReceiverDto dto, ExpandoObject annotations) => new(dto) { Annotations = annotations }; /// /// Asynchronously converts a to a . /// /// The task that returns the DTO to convert. /// /// A task that represents the asynchronous conversion operation. public static async Task ToDocSignedNotification(this Task dtoTask, ExpandoObject annotations) => await dtoTask is EnvelopeReceiverDto dto ? new(dto) { Annotations = annotations } : null; }