using CashLineERP.SharedKernel.Tax;

namespace CashLineERP.Domain.Finance;

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

    public long AccountsReceivableInvoiceId { get; private set; }

    public int LineNumber { get; private set; }

    public long? SalesOrderLineId { get; private set; }

    public long? ItemId { get; private set; }

    public decimal QuantityInvoiced { get; private set; }

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

    public decimal UnitPrice { get; private set; }

    public string? TaxCode { get; private set; }

    public decimal LineNetAmount { get; private set; }

    public decimal LineTaxAmount { get; private set; }

    public decimal LineTotalAmount { get; private set; }

    public AccountsReceivableInvoiceLine(
        long accountsReceivableInvoiceId,
        int lineNumber,
        long? salesOrderLineId,
        long? itemId,
        decimal quantityInvoiced,
        string unitOfMeasureCode,
        decimal unitPrice,
        string? taxCode)
    {
        AccountsReceivableInvoiceId = accountsReceivableInvoiceId;
        LineNumber = lineNumber;
        SalesOrderLineId = salesOrderLineId;
        ItemId = itemId;
        QuantityInvoiced = quantityInvoiced;
        UnitOfMeasureCode = unitOfMeasureCode;
        UnitPrice = unitPrice;
        TaxCode = taxCode;
        LineNetAmount = quantityInvoiced * unitPrice;
        LineTaxAmount = StatutoryTaxPolicy.CalculateTax(LineNetAmount, TaxCode);
        LineTotalAmount = LineNetAmount + LineTaxAmount;
    }

    private AccountsReceivableInvoiceLine()
    {
    }
}
