package com.jeequan.jeepay.thirdparty.channel;


import com.jeequan.jeepay.core.entity.*;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.interfaces.paychannel.IDivisionService;
import com.jeequan.jeepay.core.model.context.MchAppConfigContext;
import com.jeequan.jeepay.core.model.rqrs.msg.ChannelRetMsg;
import com.jeequan.jeepay.service.impl.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;

/**
* abstract 分账实现
*
* @author terrfly
*
* @date 2022/6/13 11:09
*/
public abstract class AbstractDivisionService implements IDivisionService {

    @Autowired
    protected SysConfigService sysConfigService;

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

    @Override
    public String getIfCode(MchDivisionReceiver mchDivisionReceiver) {
        return mchDivisionReceiver.getIfCode();
    }

    @Override
    public String getIfCode(PayOrder payOrder) {
        return payOrder.getIfCode();
    }

    @Override
    public String getIfCode(PayOrderDivisionRecord payOrderDivisionRecord) {
        return payOrderDivisionRecord.getIfCode();
    }

    @Override
    public boolean divisionRefundIsOrderRefundAfterProc() {
        return false; // 默认分账业务前发起退分处理。
    }

    @Override
    public HashMap<Long, ChannelRetMsg> queryDivision(PayOrder payOrder, List<? extends PayOrderDivisionRecord> recordList, MchAppConfigContext mchAppConfigContext){
        throw new BizException("接口不支持");
    }

    @Override
    public ChannelRetMsg divisionRefund(PayOrderDivisionRecord payOrderDivisionRecord, PayOrderDivisionRefundRecord payOrderDivisionRefundRecord, RefundOrder refundOrder, PayOrder payOrder, MchAppConfigContext mchAppConfigContext) {
        throw new BizException("接口不支持");
    }

    @Override
    public Long queryBalanceAmount(MchDivisionReceiver mchDivisionReceiver, MchAppConfigContext mchAppConfigContext) {
        throw new BizException("接口不支持");
    }

    @Override
    public ChannelRetMsg cashout(MchDivisionReceiver mchDivisionReceiver, Long amount, MchAppConfigContext mchAppConfigContext) {
        throw new BizException("接口不支持");
    }

    @Override
    public String divisionFinishAfterDivision(PayOrderDivisionRecord divisionRecord, MchAppConfigContext mchAppConfigContext) {
        throw new BizException("接口不支持");
    }

    protected String getNotifyUrl(){
        return getPaySiteUrl() + "/api/divisionRecordChannelNotify/" + getIfCode();
    }
}
