package com.lakala.zf.laop.java.sdk.demo.utils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.lakala.zf.laop.java.sdk.demo.BaseCommonDemo;
import com.lkl.laop.sdk.LKLSDK;
import com.lkl.laop.sdk.request.*;
import com.lkl.laop.sdk.utils.CommonUtil;

import javax.servlet.ServletException;

/**
 * @author Maosw
 */
public class V3LakalaUserUtils extends BaseCommonDemo {


    /**
     * 根据卡号查询卡BIN信息
     */
    public static JSONObject cardBin(String acctNo) throws Exception {
        doInit();
        if (acctNo == null) {
            throw new ServletException("acctNo不能为空");
        }
        V2MmsOpenApiCardBin cardBin = new V2MmsOpenApiCardBin();
        cardBin.setVersion(KlkConstant.VERSION);
        cardBin.setOrderNo(CommonUtil.getOrderNo());
        cardBin.setOrgCode(KlkConstant.ORG_CODE);
        cardBin.setCardNo(acctNo);
        String cardBinResponse = LKLSDK.httpPost(cardBin);
        return JSON.parseObject(cardBinResponse);
    }

    /**
     *附件上传
     */
    public static JSONObject uploadFile(V2MmsOpenApiUploadFile uploadFile) throws Exception {
        doInit();
        if (uploadFile == null) {
            throw new ServletException("fileBo不能为空");
        }
//        V2MmsOpenApiUploadFile uploadFile = new V2MmsOpenApiUploadFile();
        uploadFile.setVersion(KlkConstant.VERSION);
        uploadFile.setOrderNo(CommonUtil.getOrderNo());
        uploadFile.setOrgCode(KlkConstant.ORG_CODE);
        uploadFile.setAttType(uploadFile.getAttType());
        uploadFile.setAttExtName(uploadFile.getAttExtName());
        uploadFile.setAttContext(uploadFile.getAttContext());
        String uploadFileResponse = LKLSDK.httpPost(uploadFile);
        return JSON.parseObject(uploadFileResponse);
    }

    /**
     * 分账接收方创建申请
     */
    public static JSONObject applyLedgerReceiver(V2MmsApplyLedgerReceiverRequest ledgerReceiver) throws Exception {
        doInit();
        if (ledgerReceiver == null) {
            throw new ServletException("ledgerReceiver不能为空");
        }
        ledgerReceiver.setVersion(KlkConstant.VERSION);
        ledgerReceiver.setOrderNo(CommonUtil.getOrderNo());
        ledgerReceiver.setOrgCode(KlkConstant.ORG_CODE);
        String uploadFileResponse = LKLSDK.httpPost(ledgerReceiver);
        return JSON.parseObject(uploadFileResponse);
    }

    /**
     * 查询提现申请详情
     */
    public static JSONObject queryWithdraw(V3SacsQueryRequest queryRequest) throws Exception {
        doInit();
        if (queryRequest == null) {
            throw new ServletException("queryRequest不能为空");
        }
        String response = LKLSDK.httpPost(queryRequest);
        return JSON.parseObject(response);
    }

    /**
     * 提现申请
     */
    public static JSONObject withdraw(V3SacsBalanceSeparateRequest separateRequest) throws Exception {
        doInit();
        if (separateRequest == null) {
            throw new ServletException("separateRequest不能为空");
        }
        String response = LKLSDK.httpPost(separateRequest);
        return JSON.parseObject(response);
    }

    /**
     *提款模式设置
     */
    public static JSONObject setWithdrawMode(V2LaepIndustryEwalletSettleProfileRequest ewalletSettleProfileRequest) throws Exception {
        doInit();
        if (ewalletSettleProfileRequest == null) {
            throw new ServletException("ewalletSettleProfileRequest不能为空");
        }
        String response = LKLSDK.httpPost(ewalletSettleProfileRequest);
        return JSON.parseObject(response);
    }

/*    *//**
     * 退款
     *//*
    public static JSONObject relationRefund(V3LabsRelationRefundRequest v3LabsRelationRefundRequest) throws Exception {
        // 1. 配置初始化
        doInit();
        if (v3LabsRelationRefundRequest == null) {
            throw new ServletException("v3LabsRelationRefundRequest不能为空");
        }
        //3. 发送请求
        String response = LKLSDK.httpPost(v3LabsRelationRefundRequest);
        //4. 响应
        System.out.println(response);
        return JSON.parseObject(response);
    }*/

}
