
package com.tmerclub.cloud.group.config;

import com.tmerclub.cloud.common.rocketmq.config.RocketMqAdapter;
import com.tmerclub.cloud.common.rocketmq.config.RocketMqConstant;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;

/**
 * @author tmerclub
 * @date 2021/3/30
 */
@RefreshScope
@Configuration
public class RocketMqConfig {

    @Autowired
    private RocketMqAdapter rocketMqAdapter;

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate groupOrderCreateTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.GROUP_ORDER_CREATE_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate groupOrderSuccessTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.GROUP_ORDER_SUCCESS_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate groupOrderUnSuccessTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.GROUP_ORDER_UN_SUCCESS_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate groupOrderUnSuccessRefundTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.GROUP_ORDER_UN_SUCCESS_REFUND_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate sendGroupNotifyToUserTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SEND_GROUP_NOTIFY_TO_USER_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate sendActivityOfflineNotifyToShopTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SEND_ACTIVITY_OFFLINE_NOTIFY_TO_SHOP_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate sendActivityAuditNotifyToShopTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.SEND_ACTIVITY_AUDIT_NOTIFY_TO_SHOP_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate sendGroupOrderSaveTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.GROUP_ORDER_SAVE_TOPIC);
    }

    @Lazy
    @Bean(destroyMethod = "destroy")
    public RocketMQTemplate sendGroupOrderOpenAndJoinGroupTemplate() {
        return rocketMqAdapter.getTransactionTemplateByTopicName(RocketMqConstant.GROUP_ORDER_OPEN_AND_JOIN_GROUP_TOPIC);
    }

}
