package shop.backend;

import shop.backend.CartPosition;

import java.util.ArrayList;
import java.util.List;

public class Order {
    private String customerName;
    private String address;
    private List<CartPosition> positions;
    private double totalNet;
    private double totalBrutto;
    private double shippingCost;
    private double finalTotal;
    //KI
    private double mwstAmount7;
    private double mwstAmount19;


    public Order(String customerName, String address, List<CartPosition> positions) {
        this.customerName = customerName;
        this.address = address;
        this.positions = new ArrayList<>();

        //KI Bug fix
        for (CartPosition pos : positions) {
            this.positions.add(new CartPosition(pos.getProduct(), pos.getQuantity()));
        }

    }


    private void calculateShippingCost() {
       //wenn ü 500 dann ist free
        if (totalBrutto >= 500) {
            shippingCost = 0.0;
            return;
        }
        double weight = 0;
        for (CartPosition pos : positions) {
            weight += pos.getProductWeight();
        }

        //Denk anstoss
        if (weight <= 0.1) {
            shippingCost = 3.95;
        } else if (weight <= 1.0) {
            shippingCost = 4.95;
        } else if (weight <= 5.0) {
            shippingCost = 5.95;
        } else {
            shippingCost = 19.95;
        }
    }


    public void printConfirmation() {
        IO.println("----------------------------------------");
        IO.println("          ORDER CONFIRMATION           ");
        IO.println("----------------------------------------");
        IO.println("Customer: " + customerName);
        IO.println("Delivery address: " + address);
        IO.println("----------------------------------------");
        IO.println("Your order:");

        for (CartPosition pos : positions) {
            IO.println("  " + pos.getProduct().getName() + " x " + pos.getQuantity());
        }

        IO.println("----------------------------------------");
        IO.println(String.format("Product value:             %6.2f €", totalNet));
        IO.println("----------------------------------------");
        IO.println("Thank you for your order, lil bro!");
        IO.println("----------------------------------------");
    }


    public String getCustomerName() {
        return customerName;
    }

    public String getAddress() {
        return address;
    }

    public List<CartPosition> getPositions() {
        return positions;
    }

    public double getTotalNet() {
        return totalNet;
    }

    public double getFinalTotal() {
        return finalTotal;
    }


}