using CashLineERP.SharedKernel.Tax;

namespace CashLineERP.Domain.Procurement;

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

    public long SupplierQuotationId { get; private set; }

    public int LineNumber { get; private set; }

    public long RequestForQuotationLineId { get; private set; }

    public long? ItemId { get; private set; }

    public decimal QuotedQuantity { get; private set; }

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

    public decimal UnitPrice { get; private set; }

    public decimal DiscountPercent { get; private set; }

    public decimal DiscountAmount { 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 int? LeadTimeDays { get; private set; }

    public SupplierQuotationLine(
        long quotationId,
        int lineNumber,
        long requestForQuotationLineId,
        long? itemId,
        decimal quotedQuantity,
        string unitOfMeasureCode,
        decimal unitPrice,
        decimal discountPercent,
        decimal discountAmount,
        string? taxCode,
        int? leadTimeDays)
    {
        SupplierQuotationId = quotationId;
        LineNumber = lineNumber;
        RequestForQuotationLineId = requestForQuotationLineId;
        ItemId = itemId;
        QuotedQuantity = quotedQuantity;
        UnitOfMeasureCode = unitOfMeasureCode;
        UnitPrice = unitPrice;
        DiscountPercent = discountPercent;
        DiscountAmount = discountAmount;
        TaxCode = taxCode;
        LeadTimeDays = leadTimeDays;

        LineNetAmount = (QuotedQuantity * UnitPrice) - DiscountAmount;
        LineTaxAmount = StatutoryTaxPolicy.CalculateTax(LineNetAmount, TaxCode);
        LineTotalAmount = LineNetAmount + LineTaxAmount;
    }

    private SupplierQuotationLine()
    {
    }
}
