package com.hfkj.channel.tianque.service;

import com.alibaba.fastjson.JSONObject;
import com.hfkj.channel.tianque.config.TianQueConfig;
import com.hfkj.channel.tianque.utils.RequestUtil;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.RequestUtils;
import com.hfkj.config.CommonSysConst;
import com.hfkj.entity.BsMerContractRecord;
import com.hfkj.entity.BsMerContractRecordMsg;
import com.hfkj.entity.BsMerPlatformNo;
import com.hfkj.entity.BsMerRate;
import com.hfkj.model.MerBasisModel;
import com.hfkj.service.BsMerContractRecordMsgService;
import com.hfkj.service.BsMerContractRecordService;
import com.hfkj.service.BsMerPlatformNoService;
import com.hfkj.service.BsMerService;
import com.hfkj.sysenum.MerSettleType;
import com.hfkj.sysenum.MerTypeEnum;
import com.hfkj.sysenum.PlatformTypeEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商户入网电子协议服务
 * @className: TianQueMerElecSignService
 * @author: HuRui
 * @date: 2023/8/28
 **/
@Component
public class TianQueMerElecSignService {

    /**
     * 签署协议
     * @param platformMerNo 平台商户号
     * @throws Exception
     */
    public JSONObject openElecSignature(String platformMerNo) {
        try {
            Map<String,Object> param = new HashMap<>();
            param.put("mno", platformMerNo);
            param.put("signType", "01");  // 签署方式，取值范围：00 页面签署,01 接口签署
            param.put("signIp", InetAddress.getLocalHost().getHostAddress());
            return RequestUtil.request(TianQueConfig.requestUrl + "/merchant/elecSignature/openElecSignature", param);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 商户协议签署查询
     * @param platformMerNo 平台商户号
     * @throws Exception
     */
    public JSONObject selectSign(String platformMerNo) {
        Map<String,Object> param = new HashMap<>();
        param.put("mno", platformMerNo);
        return RequestUtil.request(TianQueConfig.requestUrl + "/merchant/elecSignature/selectSign", param);
    }

    /**
     * 商户协议下载
     * @param platformMerNo 平台商户号
     * @throws Exception
     */
    public JSONObject downFile(String platformMerNo) {
        Map<String,Object> param = new HashMap<>();
        param.put("mno", platformMerNo);
        return RequestUtil.request(TianQueConfig.requestUrl + "/merchant/elecSignature/downFile", param);
    }

}
