package cn.iocoder.yudao.module.member.api.card;

import cn.hutool.core.util.ObjectUtil;
import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO;
import cn.iocoder.yudao.module.member.dal.dataobject.rechargeamount.RechargeAmountDO;
import cn.iocoder.yudao.module.member.service.amount.DeductionService;
import cn.iocoder.yudao.module.member.service.amount.WxRechargeService;
import cn.iocoder.yudao.module.member.service.card.CardService;
import cn.iocoder.yudao.module.member.service.rechargeamount.RechargeAmountService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author zt
 * @description <description class purpose>
 * @since 2024/10/9
 */
@Service
public class CardApiImpl implements CardApi{

    @Resource
    private RechargeAmountService rechargeAmountService;
    @Resource
    private DeductionService deductionService;

    @Resource
    private WxRechargeService wxRechargeService;

    @Override
    public void recharge(BigDecimal money,Long userId){
        money = money.divide(new BigDecimal("100"));
        RechargeAmountDO recharge = rechargeAmountService.getRecharge(money);
        BigDecimal giftMoney = BigDecimal.ZERO;
        if(ObjectUtil.isNotEmpty(recharge.getDonateMoney())){
            giftMoney = giftMoney.add(recharge.getDonateMoney());
        }

        wxRechargeService.wxRecharge(money.add(giftMoney), money,giftMoney,userId);
    }

    @Override
    public void wxDraw(Integer amount, Long userId) {
        deductionService.wxDraw(amount,userId);
    }
}
