package com.apobates.forum.thrones;

import com.apobates.forum.core.impl.event.*;
import com.apobates.forum.member.impl.event.*;
import com.apobates.forum.thrones.event.*;
import com.github.davidmarquis.redisq.RedisMessageQueue;
import com.github.davidmarquis.redisq.consumer.MessageConsumer;
import com.github.davidmarquis.redisq.persistence.RedisOps;
import com.github.davidmarquis.redisq.serialization.PayloadSerializer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ThronesRedisEventConfig {
    //base redis mq
    @Bean
    public PayloadSerializer payloadSerializer(){
        return new com.github.davidmarquis.redisq.serialization.GsonPayloadSerializer();
    }
    @Bean("redisOps")
    public RedisOps buildRedisMQOps(){
        return new com.github.davidmarquis.redisq.persistence.RedisOps();
    }
    // loop Producer
    // loop Member Consumer
    @Bean
    public MessageConsumer<MemberSignUpEvent> registerNoticeConsumer(
            @Qualifier("signUpEventQueue") RedisMessageQueue signUpEventQueue,
            @Qualifier("registerNotice") MemberSignUpNoticeListener registerNotice){
        MessageConsumer<MemberSignUpEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(signUpEventQueue);
        messageConsumer.setConsumerId("SignUpEvent:Notice");
        messageConsumer.setMessageListener(registerNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<MemberSignInEvent> loginNoticeConsumer(
            @Qualifier("signInEventQueue") RedisMessageQueue signInEventQueue,
            @Qualifier("loginNotice") MemberSignInNoticeListener loginNotice){
        MessageConsumer<MemberSignInEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(signInEventQueue);
        messageConsumer.setConsumerId("SignInEvent:Notice");
        messageConsumer.setMessageListener(loginNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<MemberPenalizeEvent> penalizeNoticeConsumer(
            @Qualifier("penalizeEventQueue") RedisMessageQueue penalizeEventQueue,
            @Qualifier("penalizeNotice") MemberPenalizeNoticeListener penalizeNotice){
        MessageConsumer<MemberPenalizeEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(penalizeEventQueue);
        messageConsumer.setConsumerId("PenalizeEvent:Notice");
        messageConsumer.setMessageListener(penalizeNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<MemberVipExchangeEvent> vipExchangeNoticeConsumer(
            @Qualifier("vipExchangeEventQueue") RedisMessageQueue vipExchangeEventQueue,
            @Qualifier("vipExchangeNotice") MemberVipExchangeNoticeListener vipExchangeNotice){
        MessageConsumer<MemberVipExchangeEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(vipExchangeEventQueue);
        messageConsumer.setConsumerId("VipExchangeEvent:Notice");
        messageConsumer.setMessageListener(vipExchangeNotice);
        return messageConsumer;
    }
    // loop CORE Consumer
    @Bean
    public MessageConsumer<PostsPublishEvent> postsReplyNoticeConsumer(
            @Qualifier("postsPublishQueue") RedisMessageQueue postsPublishQueue,
            @Qualifier("postsReplyNotice") PostsReplyNoticeListener postsReplyNotice){
        MessageConsumer<PostsPublishEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(postsPublishQueue);
        messageConsumer.setConsumerId("PostsPublishEvent:replyNotice");
        messageConsumer.setMessageListener(postsReplyNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<PostsPublishEvent> postsQuoteNoticeConsumer(
            @Qualifier("postsPublishQueue") RedisMessageQueue postsPublishQueue,
            @Qualifier("postsQuoteNotice") PostsQuoteNoticeListener postsQuoteNotice){
        MessageConsumer<PostsPublishEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(postsPublishQueue);
        messageConsumer.setConsumerId("PostsPublishEvent:quoteNotice");
        messageConsumer.setMessageListener(postsQuoteNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<PostsMoodEvent> moodActionNoticeConsumer(
            @Qualifier("postsMoodQueue") RedisMessageQueue postsMoodQueue,
            @Qualifier("moodActionNotice") PostsMoodNoticeListener moodActionNotice){
        MessageConsumer<PostsMoodEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(postsMoodQueue);
        messageConsumer.setConsumerId("PostsMoodEvent:actionNotice");
        messageConsumer.setMessageListener(moodActionNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<TopicMoveEvent> topicMoveActionNoticeConsumer(
            @Qualifier("topicMoveQueue") RedisMessageQueue topicMoveQueue,
            @Qualifier("topicMoveActionNotice") TopicMoveNoticeListener topicMoveActionNotice){
        MessageConsumer<TopicMoveEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(topicMoveQueue);
        messageConsumer.setConsumerId("TopicMoveEvent:actionNotice");
        messageConsumer.setMessageListener(topicMoveActionNotice);
        return messageConsumer;
    }

    @Bean
    public MessageConsumer<ModeratorRecallEvent> moderatorRecallNoticeConsumer(
            @Qualifier("moderatorRecallQueue") RedisMessageQueue moderatorRecallQueue,
            @Qualifier("recallNotice") ModeratorRecallNoticeListener recallNotice){
        MessageConsumer<ModeratorRecallEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(moderatorRecallQueue);
        messageConsumer.setConsumerId("ModeratorRecallEvent:recallNotice");
        messageConsumer.setMessageListener(recallNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<ModeratorBornEvent> moderatorBornNoticeConsumer(
            @Qualifier("moderatorBornQueue") RedisMessageQueue moderatorBornQueue,
            @Qualifier("bornNotice") ModeratorBornNoticeListener bornNotice){
        MessageConsumer<ModeratorBornEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(moderatorBornQueue);
        messageConsumer.setConsumerId("ModeratorBornEvent:bornNotice");
        messageConsumer.setMessageListener(bornNotice);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<MemberChangeEvent> changeEventConsumer(
            @Qualifier("changeEventQueue") RedisMessageQueue changeEventQueue,
            @Qualifier("asyncInfoCache") MemberChangeEventListener asyncInfoCache){
        MessageConsumer<MemberChangeEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(changeEventQueue);
        messageConsumer.setConsumerId("MemberChangeEvent:asyncInfo");
        messageConsumer.setMessageListener(asyncInfoCache);
        //messageConsumer.setThreadingStrategy(new com.github.davidmarquis.redisq.consumer.MultiThreadingStrategy(4));
        return messageConsumer;
    }
}
