package com.sw.mes.utils;

import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class WeightUtils {
    public static BigDecimal getTheoryWeight(String productTypeSecond, BigDecimal length){

        BigDecimal result = new BigDecimal(0);
        if(length.compareTo(new BigDecimal(0))<=0){
            return result;
        }
        if(StringUtils.isBlank(productTypeSecond)){
            return result;
        }
        if(productTypeSecond.indexOf("210.9")>0){
            result = length.divide(new BigDecimal(12.29),2, RoundingMode.HALF_UP);
        }else if(productTypeSecond.indexOf("210")>0){
            result = length.divide(new BigDecimal(12.39),2, RoundingMode.HALF_UP);
        }else if(productTypeSecond.indexOf("211")>0){
            result = length.divide(new BigDecimal(12.27),2, RoundingMode.HALF_UP);
        }else if(productTypeSecond.indexOf("213")>0){
            result = length.divide(new BigDecimal(12.04),2, RoundingMode.HALF_UP);
        }else if(productTypeSecond.indexOf("220")>0){
            result = length.divide(new BigDecimal(11.29),2, RoundingMode.HALF_UP);
        }else if(productTypeSecond.indexOf("223")>0){
            result = length.divide(new BigDecimal(10.99),2, RoundingMode.HALF_UP);
        }else if(productTypeSecond.indexOf("295")>0){
            result = length.divide(new BigDecimal(6.28),2, RoundingMode.HALF_UP);
        }else if(productTypeSecond.indexOf("247")>0){
            result = length.divide(new BigDecimal(8.96),2, RoundingMode.HALF_UP);
        }
        return result;
    }
}
