package com.ms.biz;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.biz.common.R;
import com.ms.api.dto.ItemDTO;
import com.ms.biz.tool.DsJsonRequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;

@ExtensionService("testSign")
@Slf4j
public class TestSignService implements ExtensionServiceHandler<ItemDTO, JSONObject> {

    @Autowired
    private DsJsonRequestTemplate dsJsonRequestTemplate;

    @Override
    public BaseResponse<JSONObject> handle(BaseRequest<ItemDTO> req) {
        HashMap<String, Object> params = new HashMap<>();

        List<String> arrayString = new ArrayList<>();
        arrayString.add("arrayString1");
        arrayString.add("arrayString2");
        params.put("arrayString", arrayString);
        HashMap<String, String> mapStringString = new HashMap<>();
        mapStringString.put("A","mapStringString1");
        mapStringString.put("B","mapStringString2");
        params.put("mapStringString", mapStringString);

        List<Integer> arrayInt64 = new ArrayList<>();
        arrayInt64.add(10000);
        arrayInt64.add(10000);
        params.put("arrayInt64", arrayInt64);

        params.put("int16", 10000);
        params.put("int32", 10000);
        params.put("int64", 10000);
        params.put("double", 10.1);
        params.put("string", "test");

//        params.put("struct1", new GetCurrentShopMoveSettingRequestDTO());
//        params.put("struct2", new GetMoveHistoryProductListRequestDTO());
//        params.put("struct3", new SaveBatchMoveTaskRequestDTO());

//        List<Object> arrayStruct = new LinkedList<>();
//        arrayStruct.add(new GetCurrentShopMoveSettingRequestDTO());
//        arrayStruct.add(new GetMoveHistoryProductListRequestDTO());
//        arrayStruct.add(new SaveBatchMoveTaskRequestDTO());
//        params.put("arrayStruct", arrayStruct);
//
//        Map<String,Object>  mapStringStruct = new HashMap<>();
//        mapStringStruct.put("mapstruct1", new GetCurrentShopMoveSettingRequestDTO());
//        mapStringStruct.put("mapstruct2", new GetMoveHistoryProductListRequestDTO());
//        mapStringStruct.put("mapstruct3", new SaveBatchMoveTaskRequestDTO());
//        params.put("mapStringStruct", mapStringStruct);

        String res = null;
        try {
            res = dsJsonRequestTemplate.execute("/order/testJava", params);
            log.info(res);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
        return R.ok(JSON.parseObject(res));
    }
}
