package de.assecutor.votianlt.model.invoices;

import java.math.BigDecimal;

public class CustomerInvoiceItem {

    private BigDecimal quantity;
    private String unit; // Einheit (Stk., h, kg, etc.)
    private String description;
    private BigDecimal unitPrice; // Einzelpreis netto
    private BigDecimal netTotal; // Gesamtpreis netto
    private BigDecimal vatRate; // Steuersatz
    private BigDecimal vatAmount; // Steuerbetrag
    private BigDecimal grossTotal; // Gesamtpreis brutto

    // Constructors
    public CustomerInvoiceItem() {
    }

    public CustomerInvoiceItem(BigDecimal quantity, String unit, String description, BigDecimal unitPrice,
            BigDecimal vatRate) {
        this.quantity = quantity;
        this.unit = unit;
        this.description = description;
        this.unitPrice = unitPrice;
        this.vatRate = vatRate;
        calculateTotals();
    }

    private void calculateTotals() {
        if (quantity != null && unitPrice != null) {
            this.netTotal = quantity.multiply(unitPrice);
            if (vatRate != null) {
                this.vatAmount = netTotal.multiply(vatRate);
                this.grossTotal = netTotal.add(vatAmount);
            }
        }
    }

    // Getters and Setters
    public BigDecimal getQuantity() {
        return quantity;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
        calculateTotals();
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public BigDecimal getUnitPrice() {
        return unitPrice;
    }

    public void setUnitPrice(BigDecimal unitPrice) {
        this.unitPrice = unitPrice;
        calculateTotals();
    }

    public BigDecimal getNetTotal() {
        return netTotal;
    }

    public void setNetTotal(BigDecimal netTotal) {
        this.netTotal = netTotal;
    }

    public BigDecimal getVatRate() {
        return vatRate;
    }

    public void setVatRate(BigDecimal vatRate) {
        this.vatRate = vatRate;
        calculateTotals();
    }

    public BigDecimal getVatAmount() {
        return vatAmount;
    }

    public void setVatAmount(BigDecimal vatAmount) {
        this.vatAmount = vatAmount;
    }

    public BigDecimal getGrossTotal() {
        return grossTotal;
    }

    public void setGrossTotal(BigDecimal grossTotal) {
        this.grossTotal = grossTotal;
    }

    // Legacy methods for backward compatibility
    public String getPrice() {
        return unitPrice != null ? unitPrice.toString() : "0.00";
    }

    public String getTotal() {
        return grossTotal != null ? grossTotal.toString() : "0.00";
    }
}
