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 = "d0217707e1194c46b57e696ac7619a06";
    private static final String CLIENT_SECRET = "a5aba84483d8387030899f01276b06a194942470";

    @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;
    }
}
