package lingtao.net.util;

import lingtao.net.bean.Product;

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

/**
 * A级铜版纸不干胶价格
 */
public class StickersDoublePrice {

    static int bigCountArr[] = {500, 1000, 2000, 3000, 5000, 10000, 20000};

    // 双面印刷不干胶报价
    public static List<Product> getPrice(double length, double width, int count, int number) {
        List<Product> list = new ArrayList<Product>();
        Product pro = new Product();
        double area = length * width;
        double[] priceArr = getBasePrice(area);

        for (int i = 0; i < bigCountArr.length; i++) {
            if (bigCountArr[i] < count || list.size() > 3) {
                continue;
            }
            pro = new Product();
            pro.setCount(bigCountArr[i]);
            pro.setPrice(priceArr[i]);//不够140元按照140元算
            list.add(pro);
        }

        //多款计算
        if (number > 1) {
            for (Product product : list) {
                product.setPrice(product.getPrice() * number);
            }
        }

        return list;
    }

    private static double[] getBasePrice(double area) {
        double[] startPriceArr = null;
        double[] endPriceArr = null;
        double avgArea = 0;
        if (area < 25) {
            return new double[]{70, 92, 164, 236, 370, 740, 1480};
        } else if (area >= 25 && area < 48.6) {
            if (area == 25) {
                return new double[]{70, 92, 164, 236, 370, 740, 1480};
            }
            avgArea = 25 + 48.6;
            startPriceArr = new double[]{70, 92, 164, 236, 370, 740, 1480};
            endPriceArr = new double[]{130, 180, 320, 440, 700, 1400, 2700};
        } else if (area >= 48.6 && area < 81) {
            if (area == 48.6) {
                return new double[]{130, 180, 320, 440, 700, 1400, 2700};
            }
            avgArea = 81 + 48.6;
            startPriceArr = new double[]{130, 180, 320, 440, 700, 1400, 2700};
            endPriceArr = new double[]{220, 310, 572, 824, 1230, 2400, 4710};
        } else if (area >= 81 && area < 126) {
            if (area == 81) {
                return new double[]{220, 310, 572, 824, 1230, 2400, 4710};
            }
            avgArea = 81 + 126;
            startPriceArr = new double[]{220, 310, 572, 824, 1230, 2400, 4710};
            endPriceArr = new double[]{370, 436, 760, 1086, 1740, 3460, 6920};
        } else if (area >= 126 && area < 170) {
            if (area == 126) {
                return new double[]{370, 436, 760, 1086, 1740, 3460, 6920};
            }
            avgArea = 126 + 170;
            startPriceArr = new double[]{370, 436, 760, 1086, 1740, 3460, 6920};
            endPriceArr = new double[]{516, 594, 1050, 1500, 2400, 4800, 9600};
        } else if (area >= 170 && area < 210) {
            if (area == 170) {
                return new double[]{516, 594, 1050, 1500, 2400, 4800, 9600};
            }
            avgArea = 170 + 210;
            startPriceArr = new double[]{516, 594, 1050, 1500, 2400, 4800, 9600};
            endPriceArr = new double[]{630, 772, 1360, 1948, 3124, 6248, 12496};
        } else if (area >= 210 && area < 230) {
            if (area == 210) {
                return new double[]{630, 772, 1360, 1948, 3124, 6248, 12496};
            }
            avgArea = 210 + 230;
            startPriceArr = new double[]{630, 772, 1360, 1948, 3124, 6248, 12496};
            endPriceArr = new double[]{770, 860, 1512, 2170, 3470, 4940, 11880};
        } else if (area >= 230 && area < 294) {
            if (area == 230) {
                return new double[]{770, 860, 1512, 2170, 3470, 4940, 11880};
            }
            avgArea = 230 + 294;
            startPriceArr = new double[]{770, 860, 1512, 2170, 3470, 4940, 11880};
            endPriceArr = new double[]{840, 970, 1700, 2434, 3904, 7800, 15600};
        } else {
            return new double[]{840, 970, 1700, 2434, 3904, 7800, 15600};
        }
        double[] priceArr = new double[bigCountArr.length];
        for (int i = 0; i < bigCountArr.length; i++) {
            priceArr[i] = Math.ceil((startPriceArr[i] + endPriceArr[i]) / avgArea * area);
        }

        return priceArr;
    }

}
