package lingtao.net.Factory;

import lingtao.net.bean.Product;
import lingtao.net.vo.PricingListVo;
import lingtao.net.vo.ProductVo;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

public class HandFlagPricingStrategy implements PricingStrategy {
    @Override
    public PricingListVo calculatePrice(Product dto, String role) {
        String plantName = dto.getPlantName();
        double width = dto.getWidth();
        double length = dto.getLength();
        int count = dto.getCount();
        int number = dto.getNumber();
        double price = 0.0;
        double basePrice = 0.0;
        List<ProductVo> resultList = new ArrayList<>();
        if ("领鸿".equals(plantName)) {
            //春亚布
            if ("1".equals(dto.getKindValue())) {

                // 合并逻辑，减少嵌套层级
                if (width == 17 && length <= 20) {
                    basePrice = 2.5;
                } else if (width == 24 && length <= 70) {
                    basePrice = 3;
                } else if (length > 70) {
                    basePrice = 4;
                }

            }
            //贡缎布
            if ("2".equals(dto.getKindValue())) {
                if (width == 17 && length <= 20) {
                    basePrice = 4;
                } else if (width == 24 && length <= 70) {
                    basePrice = 5;
                } else if (length > 70) {
                    basePrice = 6;
                }
            }
            if (basePrice == 0) {
                return new PricingListVo(100, "暂无报价。");
            }

            price = new BigDecimal(basePrice * count * number / 10000).setScale(2, RoundingMode.HALF_UP).doubleValue();
        }
        ProductVo pro = new ProductVo();
        pro.setCount(count);
        pro.setPrice(price);
        pro.setNumber(number);
        pro.setWeight(BigDecimal.valueOf(width / 100 * length / 100 * count * 0.07).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
        resultList.add(pro);
        return new PricingListVo(resultList);
    }
}
