package com.ruoyi.utils.lakala.test;

import cn.hutool.core.date.DateUtil;
import com.lkl.laop.sdk.LKLSDK;
import com.lkl.laop.sdk.exception.SDKException;
import com.lkl.laop.sdk.request.V3CcssCounterOrderCreateRequest;
import com.lkl.laop.sdk.request.model.V3CcssOrderSceneFieldInfo;
import com.lkl.laop.sdk.utils.JsonUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class V3CcssCounterOrderCreateRequestExtendDemo extends BaseCommonDemo {

    public static void main(String[] args)  throws SDKException{

        // 1. 配置初始化

        doInit();


        //增加实体一级参数demo

        extendFirstStruct();
//
//        //增加实体二级参数demo
//
//        extendSecondStruct();
//
////        //增加调用sdk未封装接口demo
//
//        extendAllStruct();

    }



    /**

     * 增加实体最外层字段

     * > 重写实体继承原实体

     *

     * @see V3CcssCounterOrderCreateRequestExtend 继承

     * @see V3CcssCounterOrderCreateRequest

     */

    private static void extendFirstStruct() throws SDKException {

        // 创建自定义实体V3CcssCounterOrderCreateRequestExtend 继承V3CcssCounterOrderCreateRequest

        V3CcssCounterOrderCreateRequestExtend req = new V3CcssCounterOrderCreateRequestExtend();

        req.setOutOrderNo("82229007392000A" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));

        req.setMerchantNo("82229007392000A");

        req.setTotalAmount(10L);

        req.setOrderEfficientTime(DateUtil.format(DateUtil.offsetDay(new Date(),1),"yyyyMMddHHmmss"));

        //回调地址
        req.setNotifyUrl("http://yutongbo.natapp1.cc/api/goeasy/lakalaNotifyUrl");

        req.setSupportRefund(1);

        req.setSupportRepeatPay(1);

        //支付类型
//        req.setCounterParam("{\"pay_mode\":\"ALIPAY\"}");

        req.setSupportCancel(0);

//        req.setBusiTypeParam("[{\"busi_type\":\"UPCARD\",\"params\":{\"crd_flg\":\"CRDFLG_D|CRDFLG_C|CRDFLG_OTH\"}},{\"busi_type\":\"SCPAY\",\"params\":{\"pay_mode\":\"WECHAT\",\"crd_flg\":\"CRDFLG_D\"}}]");

        req.setOrderInfo("测试12313131");

        req.setTermNo("D9296400");

        List<String> sgnInfos = new ArrayList<>();

        sgnInfos.add("1");

        req.setSgnInfo(sgnInfos);

//        V3CcssOrderSceneFieldInfo info = new V3CcssOrderSceneFieldInfo();

        V3CcssOrderSceneFieldInfo.HbFqSceneInfo hbFqSceneInfo = new V3CcssOrderSceneFieldInfo.HbFqSceneInfo();

        hbFqSceneInfo.setHbFqNum("3");

        hbFqSceneInfo.setHbFqSellerPercent("0");

//        info.setSceneInfo(JsonUtils.toJSONString(hbFqSceneInfo));

//        info.setOrderSceneType("HB_FQ");

//        req.setOrderSceneField(info);


        //3. 发送请求

        String response = LKLSDK.httpPost(req);



        //4. 响应

        System.out.println(response);

    }



    /**

     * 增加实体内层嵌套实体字段

     * > 重写嵌套实体继承原实体

     *

     * @see V3CcssOrderSceneFieldInfoExtend 继承

     * @see V3CcssOrderSceneFieldInfo

     */

    private static void extendSecondStruct() throws SDKException {



        V3CcssCounterOrderCreateRequest req = new V3CcssCounterOrderCreateRequest();

        req.setOutOrderNo("82229007392000A" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));

        req.setMerchantNo("82229007392000A");

        req.setTotalAmount(10L);

        req.setOrderEfficientTime(DateUtil.format(DateUtil.offsetDay(new Date(),1),"yyyyMMddHHmmss"));

        //回调地址
        req.setNotifyUrl("http://m8nnvt.natappfree.cc/api/goeasy/lakalaNotifyUrl");

        req.setSupportRefund(1);

        req.setSupportRepeatPay(1);

//        req.setCounterParam("{\"pay_mode\":\"ALIPAY\"}");

        req.setSupportCancel(0);

        req.setBusiTypeParam("[{\"busi_type\":\"UPCARD\",\"params\":{\"crd_flg\":\"CRDFLG_D|CRDFLG_C|CRDFLG_OTH\"}},{\"busi_type\":\"SCPAY\",\"params\":{\"pay_mode\":\"WECHAT\",\"crd_flg\":\"CRDFLG_D\"}}]");

        req.setOrderInfo("测试12313131");

        req.setTermNo("D9296400");

        List<String> sgnInfos = new ArrayList<>();

        sgnInfos.add("1");

        req.setSgnInfo(sgnInfos);



        //创建自定义实体继承 V3CcssOrderSceneFieldInfo

        V3CcssOrderSceneFieldInfoExtend info = new V3CcssOrderSceneFieldInfoExtend();

        V3CcssOrderSceneFieldInfo.HbFqSceneInfo hbFqSceneInfo = new V3CcssOrderSceneFieldInfo.HbFqSceneInfo();

        hbFqSceneInfo.setHbFqNum("3");

        hbFqSceneInfo.setHbFqSellerPercent("0");

        info.setSceneInfo(JsonUtils.toJSONString(hbFqSceneInfo));

        info.setOrderSceneType("HB_FQ");



        //----- 增加内部结构字段

//        info.setSecondExtFiled1("内部扩展字段");



        req.setOrderSceneField(info);

        //3. 发送请求

        String response = LKLSDK.httpPost(req);



        //4. 响应

        System.out.println(response);

    }



    /**

     * 增加自定义实体(sdk未封装接口)

     * > v2接口继承

     * @see com.lkl.laop.sdk.request.V2CommRequest

     * > v3接口继承

     * @see com.lkl.laop.sdk.request.V3CommRequest

     */

    private static void extendAllStruct() throws SDKException {

//        //创建 V3ExtendRequest 继承 V3CommRequest
//
//        V3ExtendRequest req = new V3ExtendRequest();
//
//        req.setOutOrderNo("8221210594300JY" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
//
//        req.setMerchantNo("8221210594300JY");
//
//        req.setTotalAmount(10L);
//
//        req.setOrderEfficientTime("20230824155923");
//
//        req.setNotifyUrl("http://run.mocky.io/v3/b02c9448-20a2-4ff6-a678-38ecab30161d");
//
//        req.setSupportRefund(1);
//
//        req.setSupportRepeatPay(1);
//
//        req.setCounterParam("{\"pay_mode\":\"ALIPAY\"}");
//
//        req.setSupportCancel(0);
//
//        req.setBusiTypeParam("[{\"busi_type\":\"UPCARD\",\"params\":{\"crd_flg\":\"CRDFLG_D|CRDFLG_C|CRDFLG_OTH\"}},{\"busi_type\":\"SCPAY\",\"params\":{\"pay_mode\":\"WECHAT\",\"crd_flg\":\"CRDFLG_D\"}}]");
//
//        req.setOrderInfo("测试12313131");
//
//        req.setTermNo("T12331234");
//
//        List<String> sgnInfos = new ArrayList<>();
//
//        sgnInfos.add("1");
//
//        req.setSgnInfo(sgnInfos);
//
//
//
//        V3CcssOrderSceneFieldInfo info = new V3CcssOrderSceneFieldInfo();
//
//        V3CcssOrderSceneFieldInfo.HbFqSceneInfo hbFqSceneInfo = new V3CcssOrderSceneFieldInfo.HbFqSceneInfo();
//
//        hbFqSceneInfo.setHbFqNum("3");
//
//        hbFqSceneInfo.setHbFqSellerPercent("0");
//
//        info.setSceneInfo(JsonUtils.toJSONString(hbFqSceneInfo));
//
//        info.setOrderSceneType("HB_FQ");
//
//        req.setOrderSceneField(info);
//
//        //========================== 发送请求使用此方法  ==========================
//
//        //参数需要加密时 使用 LKLSDK.sm4Encrypt(req.toBody(); 自行加密
//
//        String response = LKLSDK.httpPost("https://test.wsmsd.cn/sit/api/v3/ccss/counter/order/create",req.toBody());
//
//        //解密时 使用 LKLSDK.sm4Decrypt(response); 自行解密
//
//
//
//        //响应
//
//        System.out.println(response);

    }

}
