package com.ematou.wxservice.mp.handler;

import com.ematou.wxservice.common.constant.WeChatConstant;
import com.ematou.wxservice.mp.message.WeChatMessage;
import com.ematou.wxservice.mp.message.WeChatMpXmlOutMessage;
import com.ematou.wxservice.mp.message.WeChatMpXmlOutNewsMessage;
import com.ematou.wxservice.mp.message.WeChatMpXmlOutTextMessage;
import org.springframework.stereotype.Component;

/**
 * CLICK事件处理器
 * @author lhm
 * @version 1.0
 * 2021-05-11 19:28
 */
@Component
public class WeChatClickEventMessageHandler implements WeChatMessageHandler {

    /**
     * 处理消息，并封装返回消息
     *
     * @param weChatMessage 接收到的消息
     * @return 响应消息
     */
    @Override
    public WeChatMpXmlOutMessage handlerMessage(WeChatMessage weChatMessage) {
        WeChatMpXmlOutMessage response = null;
        // TODO 处理菜单点击事件
        switch (weChatMessage.getEventKey()) {
            case WeChatConstant.CustomEventKey.POLICY_SUPPORT:
                response = handlerPolicySupportEvent(weChatMessage);
                break;
            case WeChatConstant.CustomEventKey.CALL_COMPANY:
                response = handlerCallCompanyEvent(weChatMessage);
                break;
            case WeChatConstant.CustomEventKey.MY_TAKE_PARCEL_CODE:
                // TODO 我的取件码
                break;
            case WeChatConstant.CustomEventKey.MY_HISTORY_RECORD:
                // TODO 取件记录
                break;
            case WeChatConstant.CustomEventKey.SCANCODE_PUSH_BUTTON:
                // TODO 扫码取件
//                WeChatMessageHandler handler = new WeChatScannHandler();
//                WeChatMpXmlOutMessage outMessage = handler.handlerMessage(weChatMessage);

                break;
            default:
                break;
        }

        return response;
    }

    /**
     * 处理联系我们按钮点击事件
     * @param weChatMessage 事件
     * @return 响应
     */
    private WeChatMpXmlOutTextMessage handlerCallCompanyEvent(WeChatMessage weChatMessage){

        String content = "【前海电商（深圳）供应链集团有限公司】\n" +
                "\n" +
                "我们在这里！↓↓↓[嘿哈]\n" +
                "地址：深圳市前海深港合作区南山街道桂湾片区二单元前海卓越金融中心（一期）7号楼1705\n" +
                "\n" +
                "或者直接拨打电话 0755-21628282,18124754870[握手]\n" +
                "我们热情的等着您~";
        return WeChatMpXmlOutMessage.TEXT().content(content).toUser(weChatMessage.getFromUser()).fromUser(weChatMessage.getToUser()).build();
    }

    /**
     * 处理政策支持按钮点击事件
     * @param weChatMessage 事件
     * @return 响应
     */
    private WeChatMpXmlOutNewsMessage handlerPolicySupportEvent(WeChatMessage weChatMessage){

        WeChatMpXmlOutNewsMessage.Item item = new WeChatMpXmlOutNewsMessage.Item();
        item.setDescription("【11月8日上午，深圳前海国检领导和业务科长一行莅临e码头进行企业调研。】e码头董事长沈琦雅向来访领导介绍了");
        item.setTitle("前海国检领导和业务科长莅临e码头 ——就企业创新需求及模式进行调研");
        item.setPicUrl("http://mmbiz.qpic.cn/mmbiz_png/Vsr05SEyic67Jj1G2pnbuJSfc0I3qoZ6mV3KXKtrhjicK1jZvicHH431laAMWskiamd4KibLkTvk1I5YT8aEt6RPmfg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1");
        item.setUrl("https://mp.weixin.qq.com/s?__biz=MzIwMTI2MTg1MA==&tempkey=MTExM185eTh5aE1DSkRjRWFqa1FGRElaWmNGa1pZLWpTbG5va0tNTnJxaXE0SE04WWVLMmYzc1hteU82THN3Rm5QamtSQUtXS0N2Zm4ybTBBZnhaOUZOZnl2eTVNVjZ5MzRvSXFPZ3lEcFNnUVdpUzV5aVRHZHJocXNLTV9RNUJYSUhTeTBVdFcxM2pxZU9INWJHSDVOUmRDWTdHcmlQSVR4TGNSQ2I3bHpnfn4%3D&chksm=0ef9ac39398e252f2791f410f2c92def335d61bfb8d7bc8563ae4dc4d91eb6b9d1b5c72ed4f4#rd");
        return WeChatMpXmlOutMessage.NEWS().addArticle(item).toUser(weChatMessage.getFromUser()).fromUser(weChatMessage.getToUser()).build();
    }

}
