
package com.tmerclub.cloud.user.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 couponGiveTemplate() {
        return rocketMqAdapter.getTemplateByTopicName(RocketMqConstant.COUPON_GIVE_TOPIC);
    }

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

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

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

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

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

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

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

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

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