package org.example.petshopdesktop.models;

import javafx.collections.ObservableList;
import java.time.LocalDateTime;

public class SaleDetail {
    private final int saleId;
    private final LocalDateTime saleDate;
    private final double totalAmount;
    private final String paymentMethod;
    private final String employeeName;
    private final boolean refund;
    private final ObservableList<SaleDetailItem> items;
    private final String customerName;
    private final double subtotalAmount;
    private final double couponDiscountAmount;
    private final double loyaltyDiscountAmount;
    private final int pointsUsed;

    public SaleDetail(int saleId, LocalDateTime saleDate, double totalAmount, String paymentMethod, String employeeName, boolean refund, ObservableList<SaleDetailItem> items, String customerName, double subtotalAmount, double couponDiscountAmount, double loyaltyDiscountAmount, int pointsUsed) {
        this.saleId = saleId;
        this.saleDate = saleDate;
        this.totalAmount = totalAmount;
        this.paymentMethod = paymentMethod;
        this.employeeName = employeeName;
        this.refund = refund;
        this.items = items;
        this.customerName = customerName != null ? customerName : "";
        this.subtotalAmount = subtotalAmount;
        this.couponDiscountAmount = couponDiscountAmount;
        this.loyaltyDiscountAmount = loyaltyDiscountAmount;
        this.pointsUsed = pointsUsed;
    }

    public int getSaleId() {
        return saleId;
    }

    public LocalDateTime getSaleDate() {
        return saleDate;
    }

    public double getTotalAmount() {
        return totalAmount;
    }

    public String getPaymentMethod() {
        return paymentMethod;
    }

    public String getEmployeeName() {
        return employeeName;
    }

    public boolean isRefund() {
        return refund;
    }

    public ObservableList<SaleDetailItem> getItems() {
        return items;
    }

    public String getCustomerName() {
        return customerName;
    }

    public double getSubtotalAmount() {
        return subtotalAmount;
    }

    public double getCouponDiscountAmount() {
        return couponDiscountAmount;
    }

    public double getLoyaltyDiscountAmount() {
        return loyaltyDiscountAmount;
    }

    public int getPointsUsed() {
        return pointsUsed;
    }

    public static class SaleDetailItem {
        private final int prodId;
        private final String productName;
        private final int quantity;
        private final double unitPrice;
        private final double total;

        public SaleDetailItem(int prodId, String productName, int quantity, double unitPrice, double total) {
            this.prodId = prodId;
            this.productName = productName;
            this.quantity = quantity;
            this.unitPrice = unitPrice;
            this.total = total;
        }

        public int getProdId() {
            return prodId;
        }

        public String getProductName() {
            return productName;
        }

        public int getQuantity() {
            return quantity;
        }

        public double getUnitPrice() {
            return unitPrice;
        }

        public double getTotal() {
            return total;
        }
    }
}
