package org.dromara.common.wechat.ma.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.message.WxMaMessageHandler;
import cn.binarywang.wx.miniapp.message.WxMaMessageRouter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.wechat.ma.handler.WechatMaLogHandler;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.context.annotation.Bean;

import static me.chanjar.weixin.common.api.WxConsts.KefuMsgType.MINIPROGRAMPAGE;

/**
 * 微信小程序消息路由
 *
 * @author ym
 * @version 1.0.0
 * @date 2024-11-12 09:52
 */
@Slf4j
@AutoConfiguration
@RequiredArgsConstructor
public class WechatMaConfig {

    private final WechatMaLogHandler wechatMaLogHandler;

    private final WxMaMessageHandler customerHandler;

    @Bean
    public WxMaMessageRouter wxMaMessageRouter(WxMaService wxMaService) {
        final WxMaMessageRouter router = new WxMaMessageRouter(wxMaService);
        router.rule().handler(wechatMaLogHandler).next();

        router.rule().async(false).msgType(MINIPROGRAMPAGE).handler(customerHandler).end();
        return router;
    }

}
