using CashLineERP.Domain.Common;

namespace CashLineERP.Domain.Finance;

public sealed class CustomerStatementDeliveryLog : Entity
{
    public long Id { get; private set; }

    public long CustomerStatementId { get; private set; }

    public DateTime DeliveredAtUtc { get; private set; }

    public string ChannelCode { get; private set; } = string.Empty;

    public string? RecipientAddress { get; private set; }

    public string DeliveryStatusCode { get; private set; } = string.Empty;

    public string? Notes { get; private set; }

    public CustomerStatementDeliveryLog(
        long customerStatementId,
        DateTime deliveredAtUtc,
        string channelCode,
        string? recipientAddress,
        string deliveryStatusCode,
        string? notes,
        long actorUserId)
    {
        if (string.IsNullOrWhiteSpace(channelCode))
        {
            throw new InvalidOperationException("Customer statement delivery channel is required.");
        }

        if (string.IsNullOrWhiteSpace(deliveryStatusCode))
        {
            throw new InvalidOperationException("Customer statement delivery status is required.");
        }

        CustomerStatementId = customerStatementId;
        DeliveredAtUtc = deliveredAtUtc;
        ChannelCode = channelCode.Trim().ToUpperInvariant();
        RecipientAddress = string.IsNullOrWhiteSpace(recipientAddress) ? null : recipientAddress.Trim();
        DeliveryStatusCode = deliveryStatusCode.Trim().ToUpperInvariant();
        Notes = string.IsNullOrWhiteSpace(notes) ? null : notes.Trim();
        CreatedByUserId = actorUserId;
    }

    private CustomerStatementDeliveryLog()
    {
    }
}
