package org.ta.pddserver;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.ta.pddserver.model.pddlg.common.TraceObject;
import org.ta.pddserver.model.pddlg.request.PddLogisticsCoTrackNotifyRequest;
import org.ta.pddserver.model.pddlg.request.PddLogisticsSecondaryCityGetRequest;
import org.ta.pddserver.model.pddlg.response.PddLogisticsCoTrackNotifyResponse;
import org.ta.pddserver.utils.PddHttpTool;
import org.ta.pddserver.utils.PddSignTool;

import java.util.ArrayList;

@Slf4j
public class LGTest2 {

    private static final String CLIENT_ID = "8f5f3f9c92e847b2894fc9c0afce3d61";
    private static final String CLIENT_SECRET = "281d79ad5117d20a51efb9e7b0d5f7ee336399b0";

    @Test
    public void test1() {
        PddLogisticsCoTrackNotifyRequest request = new PddLogisticsCoTrackNotifyRequest();
        request.setClient_id(CLIENT_ID);
        request.setShip_id("567");
        request.setTarget_client_id(CLIENT_ID);
        request.setTimestamp(System.currentTimeMillis() / 1000);
        PddLogisticsCoTrackNotifyRequest.DataObject dataObject = getDataObject();
        request.setDataObject(dataObject);
        request.encodeData();
        request.setSign(PddSignTool.generateSign(request, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(request));
        String resp = PddHttpTool.sendJsonPost(request);
        log.info("resp = {}", resp);
        PddLogisticsCoTrackNotifyResponse response = JSON.parseObject(resp, PddLogisticsCoTrackNotifyResponse.class);
        log.info("response = {}", JSON.toJSONString(response));
    }

    @Test
    public void test2() {
        PddLogisticsSecondaryCityGetRequest request = new PddLogisticsSecondaryCityGetRequest();
        request.setClient_id(CLIENT_ID);
        request.setShip_id("567");
        request.setTarget_client_id(CLIENT_ID);
        request.setTimestamp(System.currentTimeMillis() / 1000);
        request.setSign(PddSignTool.generateSign(request, CLIENT_SECRET));
        log.info("requestModel:{}", JSON.toJSONString(request));
        String resp = PddHttpTool.sendJsonPost(request);
        log.info("resp = {}", resp);
//        PddLogisticsCoTrackNotifyResponse response = JSON.parseObject(resp, PddLogisticsCoTrackNotifyResponse.class);
//        log.info("response = {}", JSON.toJSONString(response));
    }

    private static PddLogisticsCoTrackNotifyRequest.DataObject getDataObject() {
        PddLogisticsCoTrackNotifyRequest.DataObject dataObjects = new PddLogisticsCoTrackNotifyRequest.DataObject();
        dataObjects.setTraces(new ArrayList<>());
        TraceObject traceObject = new TraceObject();
        dataObjects.getTraces().add(traceObject);
        traceObject.setCity("310000");
        traceObject.setContact("萌小二");
        traceObject.setContactInfo("13123456789");
        traceObject.setCountry("CN");
        traceObject.setOperationTime("2025-10-28 09:51:11");
        traceObject.setDescription("[上海市][华新网点]快递员 萌小二(13123456789) 正在派送中");
        traceObject.setDistrict("青浦区");
        traceObject.setId("cf12a50ced6df4ba41a52aa313107a2f");
        traceObject.setProvince("上海市");
        traceObject.setRemark("<routeCode>005</routeCode><courierCode>123456</courierCode><courierName>萌小一</courierName>");
        traceObject.setSiteName("华新网点");
        traceObject.setSiteNo("100060");
        traceObject.setSiteType(1);
        traceObject.setStatus("SEND");
        traceObject.setTimeZone("+08:00");
        traceObject.setTrackingNumber("1234567890");
        traceObject.setTransferFlag(0);
        return dataObjects;
    }
}
