namespace CashLineERP.Domain.Finance;

public sealed class SupplierStatementLine
{
    public long Id { get; private set; }

    public long SupplierStatementId { get; private set; }

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

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

    public long DocumentId { get; private set; }

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

    public DateOnly BusinessDate { get; private set; }

    public DateOnly? DueDate { get; private set; }

    public string CurrencyCode { get; private set; } = "EGP";

    public decimal ChargeAmount { get; private set; }

    public decimal SettlementAmount { get; private set; }

    public decimal RunningBalanceAmount { get; private set; }

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

    public string? ReferenceText { get; private set; }

    public SupplierStatementLine(
        long supplierStatementId,
        string entryType,
        string documentType,
        long documentId,
        string documentNumber,
        DateOnly businessDate,
        DateOnly? dueDate,
        string currencyCode,
        decimal chargeAmount,
        decimal settlementAmount,
        decimal runningBalanceAmount,
        string statusCode,
        string? referenceText)
    {
        if (string.IsNullOrWhiteSpace(entryType))
        {
            throw new InvalidOperationException("Supplier statement line entry type is required.");
        }

        if (string.IsNullOrWhiteSpace(documentType))
        {
            throw new InvalidOperationException("Supplier statement line document type is required.");
        }

        if (string.IsNullOrWhiteSpace(documentNumber))
        {
            throw new InvalidOperationException("Supplier statement line document number is required.");
        }

        if (string.IsNullOrWhiteSpace(currencyCode))
        {
            throw new InvalidOperationException("Supplier statement line currency is required.");
        }

        if (string.IsNullOrWhiteSpace(statusCode))
        {
            throw new InvalidOperationException("Supplier statement line status code is required.");
        }

        SupplierStatementId = supplierStatementId;
        EntryType = entryType.Trim().ToUpperInvariant();
        DocumentType = documentType.Trim().ToUpperInvariant();
        DocumentId = documentId;
        DocumentNumber = documentNumber.Trim().ToUpperInvariant();
        BusinessDate = businessDate;
        DueDate = dueDate;
        CurrencyCode = currencyCode.Trim().ToUpperInvariant();
        ChargeAmount = chargeAmount;
        SettlementAmount = settlementAmount;
        RunningBalanceAmount = runningBalanceAmount;
        StatusCode = statusCode.Trim().ToUpperInvariant();
        ReferenceText = string.IsNullOrWhiteSpace(referenceText) ? null : referenceText.Trim();
    }

    private SupplierStatementLine()
    {
    }
}
