package com.jeequan.jeepay.thirdparty.channel;

import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.interfaces.paychannel.IRepayApiService;
import com.jeequan.jeepay.core.model.df.Account;
import com.jeequan.jeepay.service.impl.SysConfigService;
import com.jeequan.jeepay.thirdparty.service.ConfigContextQueryService;
import com.jeequan.jeepay.thirdparty.util.ChannelCertConfigKitBean;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * TODO
 *
 * @author crystal
 * @date 2024/3/25 10:43
 */
public abstract class AbstractRepayApiService implements IRepayApiService {

    @Autowired
    protected SysConfigService sysConfigService;
    @Autowired protected ChannelCertConfigKitBean channelCertConfigKitBean;
    @Autowired protected ConfigContextQueryService configContextQueryService;

    protected String getPaySiteUrl() {
        return sysConfigService.getDBApplicationConfig().getPaySiteUrl();
    }

    protected String getNotifyUrl(){
        return getPaySiteUrl() + "/api/channel/payment/notify/" + getIfCode();
    }

    /**
     * 校验账户余额
     * @param mchNo
     * @param accountType
     * @param changeAmt
     */
    @Override
    public void checkAccountBalance(String mchNo,byte accountType, Long changeAmt) {
        Account account = this.queryAccountBalance(mchNo, accountType);
        if(account.getBalance() < changeAmt){
            throw new BizException("账户不足，请先在后台充值后再操作");
        }
    }

}
