// service/KongfzItemService.java
package org.dromara.zhishu.service.impl;


import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import kotlin.Result;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hpsf.Decimal;
import org.dromara.zhishu.domain.ZhishuShopGoods;
import org.dromara.zhishu.domain.dto.KongfzRequestDto;
import org.dromara.zhishu.domain.vo.ZhishuShopGoodsVo;
import org.dromara.zhishu.mapper.ShopMapper;
import org.dromara.zhishu.mapper.ZhishuShopGoodsMapper;
import org.dromara.zhishu.util.HttpUtils;
import org.dromara.zhishu.util.KongfzApiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONException;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

@Slf4j
@Service
public class KongfzItemService {

    @Autowired
    private KongfzApiUtils kongfzApiUtils;
    @Autowired
    private ZhishuShopGoodsMapper zhishuShopGoodsMapper;
    @Autowired
    private ObjectMapper objectMapper;

    public String getShopInfo(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url, headers, requestBody);
    }


    public String listing(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);

    }

    public String delisting(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);
    }

    public String shopList(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);
    }

    public String updateItemNumber(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);
    }


    public String updateItemPrice(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);
    }

    public String updateItemName(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);
    }

    public String updateItemsn(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);
    }

    public String deleteItem(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);
        return HttpUtils.sendPost(url,headers,requestBody);
    }

    public String batchDeleteItem(Map<String, String> params) throws Exception {
        String url = "https://kongfz-api.kongfz.com";
        Map<String, String> headers = new HashMap<>();
        headers.put("Content-Type", "application/json");
        String requestBody = HttpUtils.convertObjectToJson(params);

        return HttpUtils.sendPost(url,headers,requestBody);
    }

}

