package de.assecutor.votianlt.model.invoices;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.List;
import java.util.Locale;

public class CustomerInvoiceData {

    private String invoiceNumber;
    private LocalDate invoiceDate;
    private LocalDate deliveryDate;
    private String description;

    // Rechnungssteller
    private String senderName;
    private String senderAddress;
    private String senderPostcode;
    private String senderCity;
    private String senderCountry;
    private String senderTaxNumber;
    private String senderVatId;
    private String senderPhone;
    private String senderEmail;
    private String senderWebsite;

    // Rechnungsempfänger
    private String recipientName;
    private String recipientCompany;
    private String recipientAddress;
    private String recipientPostcode;
    private String recipientCity;
    private String recipientCountry;
    private String recipientVatId;

    private List<CustomerInvoiceItem> items;

    private BigDecimal netAmount;
    private BigDecimal vatRate;
    private BigDecimal vatAmount;
    private BigDecimal totalAmount;

    // Zahlungsdetails
    private String paymentTerms;
    private LocalDate paymentDueDate;
    private String bankAccount;
    private String iban;
    private String bic;

    // Rechtliche Angaben
    private String legalNotes;
    private String reverseChargeNote;

    // Number formatter for German locale
    private static final NumberFormat CURRENCY_FORMAT = NumberFormat.getCurrencyInstance(Locale.GERMANY);
    private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("dd.MM.yyyy");

    // Constructors
    public CustomerInvoiceData() {
    }

    public CustomerInvoiceData(String invoiceNumber, LocalDate invoiceDate, String description) {
        this.invoiceNumber = invoiceNumber;
        this.invoiceDate = invoiceDate;
        this.description = description;
    }

    // Getters and Setters
    public String getInvoiceNumber() {
        return invoiceNumber;
    }

    public void setInvoiceNumber(String invoiceNumber) {
        this.invoiceNumber = invoiceNumber;
    }

    public LocalDate getInvoiceDate() {
        return invoiceDate;
    }

    public void setInvoiceDate(LocalDate invoiceDate) {
        this.invoiceDate = invoiceDate;
    }

    public LocalDate getDeliveryDate() {
        return deliveryDate;
    }

    public void setDeliveryDate(LocalDate deliveryDate) {
        this.deliveryDate = deliveryDate;
    }

    public String getDescription() {
        return description;
    }

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

    public String getSenderName() {
        return senderName;
    }

    public void setSenderName(String senderName) {
        this.senderName = senderName;
    }

    public String getSenderAddress() {
        return senderAddress;
    }

    public void setSenderAddress(String senderAddress) {
        this.senderAddress = senderAddress;
    }

    public String getSenderPostcode() {
        return senderPostcode;
    }

    public void setSenderPostcode(String senderPostcode) {
        this.senderPostcode = senderPostcode;
    }

    public String getSenderCity() {
        return senderCity;
    }

    public void setSenderCity(String senderCity) {
        this.senderCity = senderCity;
    }

    public String getSenderCountry() {
        return senderCountry;
    }

    public void setSenderCountry(String senderCountry) {
        this.senderCountry = senderCountry;
    }

    public String getSenderTaxNumber() {
        return senderTaxNumber;
    }

    public void setSenderTaxNumber(String senderTaxNumber) {
        this.senderTaxNumber = senderTaxNumber;
    }

    public String getSenderVatId() {
        return senderVatId;
    }

    public void setSenderVatId(String senderVatId) {
        this.senderVatId = senderVatId;
    }

    public String getSenderPhone() {
        return senderPhone;
    }

    public void setSenderPhone(String senderPhone) {
        this.senderPhone = senderPhone;
    }

    public String getSenderEmail() {
        return senderEmail;
    }

    public void setSenderEmail(String senderEmail) {
        this.senderEmail = senderEmail;
    }

    public String getSenderWebsite() {
        return senderWebsite;
    }

    public void setSenderWebsite(String senderWebsite) {
        this.senderWebsite = senderWebsite;
    }

    public String getRecipientName() {
        return recipientName;
    }

    public void setRecipientName(String recipientName) {
        this.recipientName = recipientName;
    }

    public String getRecipientCompany() {
        return recipientCompany;
    }

    public void setRecipientCompany(String recipientCompany) {
        this.recipientCompany = recipientCompany;
    }

    public String getRecipientAddress() {
        return recipientAddress;
    }

    public void setRecipientAddress(String recipientAddress) {
        this.recipientAddress = recipientAddress;
    }

    public String getRecipientPostcode() {
        return recipientPostcode;
    }

    public void setRecipientPostcode(String recipientPostcode) {
        this.recipientPostcode = recipientPostcode;
    }

    public String getRecipientCity() {
        return recipientCity;
    }

    public void setRecipientCity(String recipientCity) {
        this.recipientCity = recipientCity;
    }

    public String getRecipientCountry() {
        return recipientCountry;
    }

    public void setRecipientCountry(String recipientCountry) {
        this.recipientCountry = recipientCountry;
    }

    public String getRecipientVatId() {
        return recipientVatId;
    }

    public void setRecipientVatId(String recipientVatId) {
        this.recipientVatId = recipientVatId;
    }

    public List<CustomerInvoiceItem> getItems() {
        return items;
    }

    public void setItems(List<CustomerInvoiceItem> items) {
        this.items = items;
    }

    public BigDecimal getNetAmount() {
        return netAmount;
    }

    public void setNetAmount(BigDecimal netAmount) {
        this.netAmount = netAmount;
    }

    public BigDecimal getVatRate() {
        return vatRate;
    }

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

    public BigDecimal getVatAmount() {
        return vatAmount;
    }

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

    public BigDecimal getTotalAmount() {
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public String getPaymentTerms() {
        return paymentTerms;
    }

    public void setPaymentTerms(String paymentTerms) {
        this.paymentTerms = paymentTerms;
    }

    public LocalDate getPaymentDueDate() {
        return paymentDueDate;
    }

    public void setPaymentDueDate(LocalDate paymentDueDate) {
        this.paymentDueDate = paymentDueDate;
    }

    public String getBankAccount() {
        return bankAccount;
    }

    public void setBankAccount(String bankAccount) {
        this.bankAccount = bankAccount;
    }

    public String getIban() {
        return iban;
    }

    public void setIban(String iban) {
        this.iban = iban;
    }

    public String getBic() {
        return bic;
    }

    public void setBic(String bic) {
        this.bic = bic;
    }

    public String getLegalNotes() {
        return legalNotes;
    }

    public void setLegalNotes(String legalNotes) {
        this.legalNotes = legalNotes;
    }

    public String getReverseChargeNote() {
        return reverseChargeNote;
    }

    public void setReverseChargeNote(String reverseChargeNote) {
        this.reverseChargeNote = reverseChargeNote;
    }

    // Formatting methods for PDF generation
    public String getFormattedInvoiceDate() {
        return invoiceDate != null ? invoiceDate.format(DATE_FORMAT) : "";
    }

    public String getFormattedDeliveryDate() {
        return deliveryDate != null ? deliveryDate.format(DATE_FORMAT) : "";
    }

    public String getFormattedPaymentDueDate() {
        return paymentDueDate != null ? paymentDueDate.format(DATE_FORMAT) : "";
    }

    public String getFormattedNetAmount() {
        return netAmount != null ? CURRENCY_FORMAT.format(netAmount) : "0,00 €";
    }

    public String getFormattedVatAmount() {
        return vatAmount != null ? CURRENCY_FORMAT.format(vatAmount) : "0,00 €";
    }

    public String getFormattedTotalAmount() {
        return totalAmount != null ? CURRENCY_FORMAT.format(totalAmount) : "0,00 €";
    }

    public String getFormattedVatRate() {
        if (vatRate != null) {
            return String.format("%.0f%%", vatRate.multiply(new BigDecimal("100")));
        }
        return "19%";
    }

    // Legacy methods for backward compatibility
    public String getDate() {
        return getFormattedInvoiceDate();
    }

    public String getText() {
        return description;
    }

    public String getRecipientDepartment() {
        return recipientCompany;
    }

    public String getRecipientStreet() {
        return recipientAddress;
    }
}
