package lingtao.net.util;

import lingtao.net.bean.Product;

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

public class CanopyUtil {

    public static List<Product> getPrice(Double area, int count, List<Product> priceList, String kindvalue, List<String> craft_list) {
        Product pro = null;
        double price = 0;
        area = area * count;//计算总面积
        double basePrice = 0;
        double[] priceArr = getBasePrice(kindvalue, craft_list);
        if (priceArr.length == 0) {
            return priceList;
        }
        if (area <= 4) {
            basePrice = priceArr[0];
        } else if (area <= 6) {
            basePrice = priceArr[1];
        } else if (area <= 9) {
            basePrice = priceArr[2];
        } else {
            basePrice = priceArr[3];
        }
        double mince = getMinPrice(kindvalue, craft_list);
        price = Math.ceil(basePrice * area);
        pro = new Product();
        pro.setCount(count);
        pro.setPrice(Math.max(price, mince));
        pro.setWeight(String.valueOf(area * 0.18));
        priceList.add(pro);

        return priceList;
    }

    private static double[] getBasePrice(String kindvalue, List<String> craft) {
        if ("银胶涤纶布".equals(kindvalue)) {
            if (craft.contains("定制")) {
                return new double[]{27, 26, 25, 24.5};
            } else {
                return new double[]{12.5, 11.5, 11, 10};
            }
        }
        if ("黑胶涤纶布".equals(kindvalue)) {
            if (craft.contains("定制")) {
                return new double[]{29, 28, 27, 26};
            } else {
                return new double[]{14.5, 13.5, 13, 12};
            }
        }
        return new double[]{};
    }

    private static double getMinPrice(String kindvalue, List<String> craft) {
        if ("银胶涤纶布".equals(kindvalue)) {
            if (craft.contains("定制")) {
                return 80;
            } else {
                return 60;
            }
        }
        if ("黑胶涤纶布".equals(kindvalue)) {
            if (craft.contains("定制")) {
                return 80;
            } else {
                return 50;
            }
        }
        return 0;
    }
}
