using DigitalData.Core.Exceptions;
using EnvelopeGenerator.Domain;
using EnvelopeGenerator.Extensions;
namespace EnvelopeGenerator.Application.DocStatus.Commands;
///
///
///
public record ModifyDocStatusCommandBase
{
///
///
///
public string? Key
{
get => Envelope?.Uuid is string uuid && Receiver?.Signature is string signature
? (uuid, signature).EncodeEnvelopeReceiverId()
: null;
init
{
if (value is null)
return;
(string? EnvelopeUuid, string? ReceiverSignature) = value.DecodeEnvelopeReceiverId();
if (string.IsNullOrEmpty(EnvelopeUuid) || string.IsNullOrEmpty(ReceiverSignature))
{
throw new BadRequestException("Der EnvelopeReceiverKey muss ein gültiger Base64-kodierter String sein, der die EnvelopeUuid und die ReceiverSignature enthält.");
}
Envelope.Uuid = EnvelopeUuid;
Receiver.Signature = ReceiverSignature;
}
}
///
/// Der Umschlag, der mit dem Empfänger verknüpft ist.
///
public EnvelopeQuery Envelope { get; set; } = new();
///
/// Der Empfänger, der mit dem Umschlag verknüpft ist.
///
public ReceiverQuery Receiver { get; set; } = new();
///
/// Gets the current status code.
///
public Constants.DocumentStatus Status => Value is null ? Constants.DocumentStatus.Created : Constants.DocumentStatus.Signed;
///
/// Gets or sets the display value associated with the status.
///
public string? Value { get; set; }
///
/// Gets timestamp when this record was added.
///
public DateTime StatusChangedWhen { get; } = DateTime.Now;
///
/// Maps the current command to a new instance of the specified type.
///
///
///
public TDest To() where TDest : ModifyDocStatusCommandBase, new()
=> new()
{
Key = Key,
Envelope = Envelope,
Receiver = Receiver,
Value = Value
};
}
#region Queries
///
/// Repräsentiert eine Abfrage für Umschläge.
///
public record EnvelopeQuery
{
///
/// Die eindeutige Kennung des Umschlags.
///
public int? Id { get; init; }
///
/// Die universell eindeutige Kennung des Umschlags.
///
public string? Uuid { get; set; }
}
///
/// Stellt eine Abfrage dar, um die Details eines Empfängers zu lesen.
/// um spezifische Informationen über einen Empfänger abzurufen.
///
public record ReceiverQuery
{
///
/// ID des Empfängers
///
public int? Id { get; init; }
///
/// E-Mail Adresse des Empfängers
///
public string? EmailAddress { get; init; }
///
/// Eindeutige Signatur des Empfängers
///
public string? Signature { get; set; }
}
#endregion