package com.hfkj.common.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mysql.jdbc.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class StarbucksUtil {

    private static String tall = "starbucks/tall.png";
    private static String tallSelect = "starbucks/tallSelect.png";
    private static String grande = "starbucks/grande.png";
    private static String grandeSelect = "starbucks/grandeSelect.png";
    private static String venti = "starbucks/venti.png";
    private static String ventiSelect = "starbucks/ventiSelect.png";

    /**
     * @MethodName unitLengthTransform
     * @Description: 组装数据
     * @param cupSize 杯型
     * @param tallPrice 中杯价格
     * @param grandePrice 大杯价格
     * @param ventiPrice  超大杯价格
     * @return: java.util.List<com.alibaba.fastjson.JSONObject>
     * @Author: Sum1Dream
     * @Date: 2024/8/2 上午11:33
     */
    public static List<JSONObject> unitLengthTransform(String cupSize , BigDecimal tallPrice , BigDecimal grandePrice , BigDecimal ventiPrice){

        List<JSONObject> list = new ArrayList<>();

        String[] cpuS = cupSize.split(",");

        for (String cup : cpuS) {
            JSONObject obj = new JSONObject();
            if (cup.equals("中杯") && tallPrice.compareTo(new BigDecimal(1000)) < 0) {
                obj.put("cpu" , "中杯");
                obj.put("notSelect" , tall);
                obj.put("select" , tallSelect);
                obj.put("volume" , "355ml");
                obj.put("price", tallPrice);
            } else if (cup.equals("大杯") && grandePrice.compareTo(new BigDecimal(1000)) < 0) {
                obj.put("cpu" , "大杯");
                obj.put("notSelect" , grande);
                obj.put("select" , grandeSelect);
                obj.put("volume" , "473ml");
                obj.put("price", grandePrice);
            } else if (cup.equals("超大杯") && ventiPrice.compareTo(new BigDecimal(1000)) < 0) {
                obj.put("cpu" , "超大杯");
                obj.put("notSelect" , venti);
                obj.put("select" , ventiSelect);
                obj.put("volume" , "592ml");
                obj.put("price", ventiPrice);
            } else {
                obj.put("cpu" , "特殊杯");
                obj.put("notSelect" , venti);
                obj.put("select" , ventiSelect);
                obj.put("volume" , "∞ml");
                obj.put("price", ventiPrice);
            }
//            switch (cup) {
//                case "中杯":
//                    obj.put("cpu", "中杯");
//                    obj.put("notSelect", tall);
//                    obj.put("select", tallSelect);
//                    obj.put("volume", "355ml");
//                    obj.put("price", tallPrice);
//                    break;
//                case "大杯":
//                    obj.put("cpu", "大杯");
//                    obj.put("notSelect", grande);
//                    obj.put("select", grandeSelect);
//                    obj.put("volume", "473ml");
//                    obj.put("price", grandePrice);
//                    break;
//                case "超大杯":
//                    obj.put("cpu", "超大杯");
//                    obj.put("notSelect", venti);
//                    obj.put("select", ventiSelect);
//                    obj.put("volume", "592ml");
//                    obj.put("price", ventiPrice);
//                    break;
//                default:
//                    obj.put("cpu", "特殊杯");
//                    obj.put("notSelect", venti);
//                    obj.put("select", ventiSelect);
//                    obj.put("volume", "∞ml");
//                    obj.put("price", ventiPrice);
//                    break;
//            }
            list.add(obj);
        }

        return list;
    }

    /**
     * @MethodName calculatePrice
     * @Description: 计算售卖价格
     * @param discount 利润
     * @param Price 成本价
     * @return: java.math.BigDecimal
     * @Author: Sum1Dream
     * @Date: 2024/8/2 上午11:32
     */
    public static BigDecimal  calculatePrice(BigDecimal discount , BigDecimal Price) {
       return Price.add(Price.multiply(discount).divide(new BigDecimal(100) , 2, RoundingMode.HALF_UP));
    }

    /**
     * @MethodName findPrice
     * @Description: 查询价格
     * @param item
     * @param cupSize
     * @return: java.math.BigDecimal
     * @Author: Sum1Dream
     * @Date: 2024/8/5 下午3:42
     */
    public static BigDecimal findPrice(JSONObject item , String cupSize) {
        if (Objects.equals(cupSize, "中杯")) {
            return item.getBigDecimal("salesTallPrice");
        }
        if (Objects.equals(cupSize, "大杯")) {
            return item.getBigDecimal("salesGrandePrice");
        }
        if (Objects.equals(cupSize, "超大杯")) {
            return item.getBigDecimal("salesVentiPrice");
        }
        return null;

    }

    /**
     * @MethodName speString
     * @Description: 规格
     * @param cupSize
     * @param temperature
     * @param cream
     * @param espresso
     * @param milk
     * @param milkBubble
     * @param separation
     * @return: java.lang.String
     * @Author: Sum1Dream
     * @Date: 2024/8/6 下午2:54
     */
    public static String speString(String cupSize , String temperature , String cream , String espresso , String milk	, String milkBubble , String separation) {
        StringBuilder sb = new StringBuilder();
        if (!StringUtils.isNullOrEmpty(cupSize)) {
            sb.append(cupSize).append(temperature).append(separation);
        }
        if (!StringUtils.isNullOrEmpty(cream)) {
            sb.append(cupSize).append(separation);
        }
        if (!StringUtils.isNullOrEmpty(espresso)) {
            sb.append(espresso).append(separation);
        }
        if (!StringUtils.isNullOrEmpty(milk)) {
            sb.append(milk).append(separation);
        }
        if (!StringUtils.isNullOrEmpty(milkBubble)) {
            sb.append(milkBubble).append(separation);
        }

        sb.delete(sb.length()- separation.length() , sb.length());
        return sb.toString();
    }
}
