package cn.axzo.msg.center.webapi;

import cn.axzo.msg.center.wx.notices.cp.WxCpMessageHandler;
import cn.axzo.msg.center.wx.notices.miniapp.WxMiniMessageHandler;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.templatecard.ActionMenuItem;
import me.chanjar.weixin.cp.bean.templatecard.QuoteArea;
import me.chanjar.weixin.cp.bean.templatecard.TemplateCardButtonSelection;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 2023/5/30 13:49
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("test")
public class TestController {

    private final WxMiniMessageHandler wxMiniMessageHandler;
    private final WxCpMessageHandler wxCpMessageHandler;

    @GetMapping("/mini")
    public void testMiniMessage() throws WxErrorException {
        WxMaSubscribeMessage wxMaSubscribeMessage = new WxMaSubscribeMessage();
        wxMaSubscribeMessage.setToUser("o2cj55Ov0ObbG9gnvnXiN92uzimg");
        wxMaSubscribeMessage.setTemplateId("Vuj7zSwCHqh4nkhw0hCp0z385e6NDUFUe90VLQk5zbM");
        wxMaSubscribeMessage.setPage("");
        wxMaSubscribeMessage.setMiniprogramState("");
        ArrayList<WxMaSubscribeMessage.MsgData> objects = new ArrayList<>();
        WxMaSubscribeMessage.MsgData msgData = new WxMaSubscribeMessage.MsgData();
        msgData.setName("thing1");
        msgData.setValue("{\"value\": 测试, \"color\": \"#173177\"}");
        objects.add(msgData);
        WxMaSubscribeMessage.MsgData msgData1 = new WxMaSubscribeMessage.MsgData();
        msgData1.setName("time2");
        msgData1.setValue("{\"value\": 2023年5月30号 14:28, \"color\": \"#173177\"}");
        objects.add(msgData1);
        WxMaSubscribeMessage.MsgData msgData2 = new WxMaSubscribeMessage.MsgData();
        msgData2.setName("thing3");
        msgData2.setValue("{\"value\":流比plus, \"color\": \"#173177\"}");
        objects.add(msgData2);
        wxMaSubscribeMessage.setData(objects);
        wxMiniMessageHandler.switchConfig("wxa7568e4542244b54", "d8613a498e8e384de9790422e90278af")
                .sendSubscribeMsg(wxMaSubscribeMessage);

    }

    public void testCpMessage() throws WxErrorException {
        WxCpMessage wxCpMessage = new WxCpMessage();
        wxCpMessage.setMsgType(me.chanjar.weixin.common.api.WxConsts.KefuMsgType.TEMPLATE_CARD);
        wxCpMessage.setToUser("");
        wxCpMessage.setToParty("");
        wxCpMessage.setToTag("");
        wxCpMessage.setAgentId(0);
        wxCpMessage.setContent("");
        wxCpMessage.setMediaId("");
        wxCpMessage.setThumbMediaId("");
        wxCpMessage.setTitle("");
        wxCpMessage.setDescription("");
        wxCpMessage.setMusicUrl("");
        wxCpMessage.setHqMusicUrl("");
        wxCpMessage.setSafe("");
        wxCpMessage.setUrl("");
        wxCpMessage.setBtnTxt("");
        wxCpMessage.setArticles(Lists.newArrayList());
        wxCpMessage.setMpnewsArticles(Lists.newArrayList());
        wxCpMessage.setAppId("");
        wxCpMessage.setPage("");
        wxCpMessage.setEmphasisFirstItem(false);
        wxCpMessage.setContentItems(Maps.newHashMap());
        wxCpMessage.setEnableIdTrans(false);
        wxCpMessage.setEnableDuplicateCheck(false);
        wxCpMessage.setDuplicateCheckInterval(0);
        wxCpMessage.setTaskId("");
        wxCpMessage.setTaskButtons(Lists.newArrayList());
        wxCpMessage.setCardType("button_interaction");
        wxCpMessage.setSourceIconUrl("");
        wxCpMessage.setSourceDesc("");
        wxCpMessage.setSourceDescColor(0);
        wxCpMessage.setActionMenuDesc("更多测试");
        wxCpMessage.setActionMenuActionList(Lists.newArrayList(ActionMenuItem.builder()
                .text("测试1").key("test").build()));
        wxCpMessage.setMainTitleTitle("测试交互卡片");
        wxCpMessage.setMainTitleDesc("这是一个测试交互卡片消息");
//        wxCpMessage.setImageTextArea(new TemplateCardImageTextArea());
        wxCpMessage.setCardImageUrl("");
        wxCpMessage.setCardImageAspectRatio(0.0F);
        wxCpMessage.setEmphasisContentTitle("");
        wxCpMessage.setEmphasisContentDesc("");
        wxCpMessage.setSubTitleText("测试交互卡片二级标题");
        wxCpMessage.setVerticalContents(Lists.newArrayList());
        wxCpMessage.setHorizontalContents(Lists.newArrayList());
        wxCpMessage.setJumps(Lists.newArrayList());
        wxCpMessage.setCardActionType(0);
        wxCpMessage.setCardActionUrl("");
        wxCpMessage.setCardActionAppid("");
        wxCpMessage.setCardActionPagepath("");
        wxCpMessage.setButtonSelection(new TemplateCardButtonSelection());
        wxCpMessage.setButtons(Lists.newArrayList());
        wxCpMessage.setCheckboxQuestionKey("");
        wxCpMessage.setCheckboxMode(0);
        wxCpMessage.setOptions(Lists.newArrayList());
        wxCpMessage.setSubmitButtonText("");
        wxCpMessage.setSubmitButtonKey("");
        wxCpMessage.setSelects(Lists.newArrayList());
        wxCpMessage.setQuoteArea(new QuoteArea());


        wxCpMessageHandler.switchConfig("ww140cb46df62ffbe2", "uG3u51Fl4PZ9CLdwYA2Bpwsd3vBzsquVuEEkbueiRwpGhPx4IzTZ9vuaL4FdQN5B")
                .send(wxCpMessage);
    }
}
