package com.seer.teach.mp.config;

import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
import com.seer.teach.mp.factory.MpServiceFactory;
import com.seer.teach.mp.handler.LocationHandler;
import com.seer.teach.mp.handler.MessageReceiveHandler;
import com.seer.teach.mp.handler.SubscribeHandler;
import com.seer.teach.mp.handler.UnsubscribeHandler;
import com.seer.teach.mp.service.IMpAccountService;
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * 微信公众号配置类
 */
@Configuration
public class MpConfiguration {

    @Bean
    public RedisTemplateWxRedisOps redisTemplateWxRedisOps(StringRedisTemplate stringRedisTemplate) {
        return new RedisTemplateWxRedisOps(stringRedisTemplate);
    }

    @Bean(initMethod="init")
    public MpServiceFactory mpServiceFactory(RedisTemplateWxRedisOps redisTemplateWxRedisOps,
                                             WxMpProperties wxMpProperties,
                                             IMpAccountService mpAccountService,
                                             MessageReceiveHandler messageReceiveHandler,
                                             SubscribeHandler subscribeHandler,
                                             UnsubscribeHandler unsubscribeHandler,
                                             LocationHandler locationHandler) {
        return new MpServiceFactory(redisTemplateWxRedisOps, mpAccountService,wxMpProperties,
                messageReceiveHandler, subscribeHandler, unsubscribeHandler, locationHandler);
    }

}