package co.yixiang.yshop.module.member.service.integralrule.strategy.impl;

import cn.hutool.core.util.NumberUtil;
import co.yixiang.yshop.module.member.api.integralRule.IntegralRuleDTO;
import co.yixiang.yshop.module.member.service.integralrule.strategy.AbstractIntegralRuleStrategy;
import co.yixiang.yshop.module.member.service.user.MemberUserService;
import co.yixiang.yshop.module.member.service.userbill.UserBillService;
import org.springframework.stereotype.Component;

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

/**
 * @author pepis
 * @apiNote
 **/
@Component("consume")
public class ConsumeIntegralRuleStrategy extends AbstractIntegralRuleStrategy {
    public ConsumeIntegralRuleStrategy(MemberUserService userService, UserBillService userBillService) {
        super(userService, userBillService);
    }

    @Override
    public BigDecimal calculate(IntegralRuleDTO rule) {
        //消费xx元获得一积分
        Integer integral = rule.getIntegral();
        //消费金额
        BigDecimal consumeAmount = rule.getConsumeAmount();
        return NumberUtil.div(consumeAmount, integral).setScale(0, RoundingMode.DOWN);
    }
}
