package org.ta.pddserver.utils;

public class PddOverseaPriceTool {

    // 首重重量
    private static int initialWeight = 1000;
    // 基础上限重量
    private static int baseMaxWeight = 20000;
    // 最大重量
    private static int maxWeight = 300000;

    // 普货首重价格
    private static int gInitalPrice = 1850;

    // 特货首重价格
    private static int sInitalPrice = 2800;

    //超重计费标准
    private static int excessWeight = 500;

    //超重价格
    private static int excessPrice = 175;

    //标椎单边长度
    private static int baseSingleLength = 100;

    //标准三边之和
    private static int baseSumLength = 160;

    //最大单边长度
    private static int maxSingleLength = 250;

    //最大三边之和
    private static int maxSumLength = 250;


    /*
     * 根据类型、重量（g） 计算运费
     * */
    public static PddJYPriceTool.FeeResult FreightCostCalculation(String type, int length, int width, int height, int weight, int exchange) {

        int max = length + width + height;
        if (length > maxSingleLength || width > maxSingleLength || height > maxSingleLength || max > maxSumLength) {
            //三边各超100或者和超160
            return null;
        }
        if (weight > maxWeight) {
            //超重无法计算
            return null;
        }

        PddJYPriceTool.FeeResult result = new PddJYPriceTool.FeeResult();

        int price = 0;
        if (exchange == 2) {
            // 改派
            price = 2400;
        }
        if (exchange == 3) {
            price = 1200;
        }

        int compWeight = weight;
        if (weight > baseMaxWeight || length > baseSingleLength || width > baseSingleLength || height > baseSingleLength || max > baseSumLength) {
            //三边各超100或者和超160
            int newWeight = length * width * height / 6000 + 1;
            compWeight = Math.max(compWeight, newWeight);
        }
        result.setWeight(compWeight);
        int excess = 0;

        // 判断重量是否超重
        //分析重量
        if (compWeight > initialWeight) {
            //计算超出重量
            compWeight = compWeight - initialWeight;
            excess = excessPrice * ((int) Math.ceil(compWeight / excessWeight));
        }

        //计算价格
        if (type.equals("NORMAL")) {
            //普货
            price = price + gInitalPrice + excess;

        } else {
            price = price + sInitalPrice + excess;
        }
        result.setRentFee(0);
        result.setFreightFee(price);
        return result;
    }
}
