package com.iformall.utils;

import com.iformall.utils.press.stateless.DefaultStatelessReduceRule;
import com.iformall.utils.press.stateless.StatelessPingReduceRule;
import com.iformall.utils.press.stateless.StatelessReduceRule;

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

/**
 * 日期处理
 * 
 * @author stormeye.wu
 * @email wuguoqiang@iformall.com
 * @date 2019年1月5月
 */
public class PressUtils {
	public final static int scale = 2;

    /**
     * randomPressValue
     * @param total 砍价总钱数（分）
     * @param left_total 剩余砍价总钱数（分）
     * @param limit_num   砍价限制次数
     * @param limit_index 砍价index
     * @return
     */
    public static int randomPressValue(int total, int left_total, int limit_num, int limit_index) {
        BigDecimal tt = BigDecimal.valueOf(total * 1.0D / 100).setScale(scale, RoundingMode.HALF_UP);
        BigDecimal lt = BigDecimal.valueOf(left_total* 1.0D / 100);
        StatelessReduceRule rule = new DefaultStatelessReduceRule();
        BigDecimal current = rule.getReduce(tt, lt, limit_num,limit_num - limit_index, scale);
        return current.multiply(BigDecimal.valueOf(100)).intValue();
    }

    /**
     * stateLessPressValue  优先 1/3砍掉一半
     * @param total 砍价总钱数（分）
     * @param left_total 剩余砍价总钱数（分）
     * @param limit_num   砍价限制次数
     * @param limit_index 砍价index
     * @return
     */
    public static int stateLessPressValue(int total, int left_total, int limit_num, int limit_index) {
        BigDecimal tt = BigDecimal.valueOf(total * 1.0D / 100).setScale(scale, RoundingMode.HALF_UP);
        BigDecimal lt = BigDecimal.valueOf(left_total* 1.0D / 100);
        StatelessReduceRule rule = new StatelessPingReduceRule();
        BigDecimal current = rule.getReduce(tt, lt, limit_num, limit_num - limit_index, scale);
        return current.multiply(BigDecimal.valueOf(100)).intValue();
    }

    public static void main(String[] args) {
        int iValue = stateLessPressValue( 2000, 2000, 5, 0);
        System.out.println(iValue);
    }

}
