package org.ta.pddserver;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.ta.pddserver.model.enums.OrderProblemType;
import org.ta.pddserver.model.pddgd.request.GDTicketListRequest;
import org.ta.pddserver.model.pddgd.request.GDTicketReplyRequest;
import org.ta.pddserver.model.pddgd.request.GDUploadRequest;
import org.ta.pddserver.model.pddgd.response.GDTicketReplyRepsonse;
import org.ta.pddserver.model.pddjy.request.JYBaseRequestModel;
import org.ta.pddserver.model.pddjy.request.PddServiceConsoProblemOrderNotifyRequest;
import org.ta.pddserver.model.pddlg.request.LGBaseModel;
import org.ta.pddserver.utils.ImageUtils;
import org.ta.pddserver.utils.PddHttpTool;
import org.ta.pddserver.utils.PddSignTool;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;

@Slf4j
public class GDTest3 {

    private static final String CLIENT_ID = "7c75c365a1a64036a598ab6b09ce0c06";
    private static final String CLIENT_SECRET = "f0752b6d5d6c214b7e255586fc4dfde382e9a6df";

    @Test
    public void test1() {
        GDTicketListRequest request = new GDTicketListRequest();
        request.setClient_id(CLIENT_ID);

        long end = new Date().getTime() / 1000;
        request.setEnd_updated_at(end);
        request.setStart_updated_at(end - 1800);
        request.setPage(1);
        request.setPage_size(100);
        request.setType("pdd.logistics.ticket.get");
        long time = new Date().getTime() / 1000;
        request.setTimestamp(time);
        request.setSign(PddSignTool.generateSign(request, CLIENT_SECRET));
        String resp = PddHttpTool.sendJsonPostGD(request);
        log.info("resp = {}", resp);

    }

    @Test
    public void Test2(){
        Long ticketId = 176179297549537L;
        String waybill_no = "773484253589148";

        GDTicketReplyRequest replyRequest = new GDTicketReplyRequest();
        replyRequest.setTicket_id(ticketId);
        replyRequest.setWaybill_no(waybill_no);
        replyRequest.setHandle_result("757类型工单测试三次回复内容，赔付100，无附件");
        replyRequest.setSign_state(1);
        replyRequest.setCompensate_state(2);
        replyRequest.setCompensate_amount(100);
        replyRequest.setDuty(1);
        replyRequest.setExpress_dealer("处理人四号");
        replyRequest.setExpress_dealer_contact("15067011004");
        replyRequest.setReply_type(1);
//        replyRequest.setAttach_path_list("[\"https://img-test.pddpic.com/open-gw/2066d9194a/c2c976cc793423a1d413c6395ad225c4.jpg\",\"https://img-test.pddpic.com/open-gw/2066d9194a/ceadf7d50fa2cd9850b10a3c769421e7.jpg\"]");


        replyRequest.setClient_id(CLIENT_ID);

        replyRequest.setType("pdd.logistics.ticket.notify");
        long time = new Date().getTime() / 1000;
        replyRequest.setTimestamp(time);
        replyRequest.setSign(PddSignTool.generateSign(replyRequest, CLIENT_SECRET));
        String resp = PddHttpTool.sendJsonPostGD(replyRequest);
        log.info("resp = {}", resp);

        JSONObject respObj = JSON.parseObject(resp);
        JSONObject respObject = respObj.getJSONObject("logistics_ticket_notify_response");
        if (respObject == null) {
            return;
        }
        GDTicketReplyRepsonse replyRepsonse = respObject.toJavaObject(GDTicketReplyRepsonse.class);
        log.info("replyRepsonse is_success:{}", replyRepsonse.getIs_success());
    }


    @Test
    public void uploadImage() throws IOException {

        GDUploadRequest request = new GDUploadRequest();
        request.setClient_id(CLIENT_ID);

        request.setType("pdd.logistics.ticket.image.upload");
        long time = new Date().getTime() / 1000;
        request.setTimestamp(time);
        request.setImage(new ImageUtils().downloadCompressToBase64("https://images.v2.tradeany.com/files/20251030/5eaac48c24c5427fa9e055d0976d5e89.jpg"));
        request.setSign(PddSignTool.generateSign(request, CLIENT_SECRET));
        String resp = PddHttpTool.sendJsonPostGD(request);
        log.info("resp = {}", resp);
    }
}
