package com.apobates.forum.member.impl;

import com.apobates.forum.member.impl.event.*;
import com.apobates.forum.member.impl.event.listener.MemberPenalizeChangeStatusListener;
import com.apobates.forum.member.impl.event.listener.MemberSignUpInviteCodeListener;
import com.apobates.forum.member.impl.event.listener.MemberSignUpPromoteRoleListener;
import com.apobates.forum.member.impl.event.listener.MemberVipExchangeGroupListener;
import com.github.davidmarquis.redisq.RedisMessageQueue;
import com.github.davidmarquis.redisq.consumer.MessageConsumer;
import com.github.davidmarquis.redisq.producer.DefaultMessageProducer;
import com.github.davidmarquis.redisq.producer.MessageProducer;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedisMemberEventConfig {
    // loop queue
    @Bean("signUpEventQueue")
    public RedisMessageQueue signUpEventQueue(){
        RedisMessageQueue mq =  new com.github.davidmarquis.redisq.RedisMessageQueue();
        mq.setQueueName("member:SignUpEvent");
        return mq;
    }
    @Bean("signInEventQueue")
    public RedisMessageQueue signInEventQueue(){
        RedisMessageQueue mq =  new com.github.davidmarquis.redisq.RedisMessageQueue();
        mq.setQueueName("member:SignInEvent");
        return mq;
    }
    @Bean("signOutEventQueue")
    public RedisMessageQueue signOutEventQueue(){
        RedisMessageQueue mq =  new com.github.davidmarquis.redisq.RedisMessageQueue();
        mq.setQueueName("member:SignOutEvent");
        return mq;
    }
    @Bean("penalizeEventQueue")
    public RedisMessageQueue penalizeEventQueue(){
        RedisMessageQueue mq =  new com.github.davidmarquis.redisq.RedisMessageQueue();
        mq.setQueueName("member:PenalizeEvent");
        return mq;
    }
    @Bean("vipExchangeEventQueue")
    public RedisMessageQueue vipExchangeEventQueue(){
        RedisMessageQueue mq =  new com.github.davidmarquis.redisq.RedisMessageQueue();
        mq.setQueueName("member:VipExchangeEvent");
        return mq;
    }
    @Bean("changeEventQueue")
    public RedisMessageQueue changeEventQueue(){
        RedisMessageQueue mq =  new com.github.davidmarquis.redisq.RedisMessageQueue();
        mq.setQueueName("member:ChangeEvent");
        return mq;
    }
    // loop Producer
    @Bean("signUpEventProducer")
    public MessageProducer<MemberSignUpEvent> signUpEventProducer(@Qualifier("signUpEventQueue") RedisMessageQueue signUpEventQueue){
        DefaultMessageProducer<MemberSignUpEvent> dmq = new com.github.davidmarquis.redisq.producer.DefaultMessageProducer<>();
        dmq.setQueue(signUpEventQueue);
        return dmq;
    }
    @Bean("signInEventProducer")
    public MessageProducer<MemberSignInEvent> signInEventProducer(@Qualifier("signInEventQueue") RedisMessageQueue signInEventQueue){
        DefaultMessageProducer<MemberSignInEvent> dmq = new com.github.davidmarquis.redisq.producer.DefaultMessageProducer<>();
        dmq.setQueue(signInEventQueue);
        return dmq;
    }
    @Bean("signOutEventProducer")
    public MessageProducer<MemberSignOutEvent> signOutEventProducer(@Qualifier("signOutEventQueue") RedisMessageQueue signOutEventQueue){
        DefaultMessageProducer<MemberSignOutEvent> dmq = new com.github.davidmarquis.redisq.producer.DefaultMessageProducer<>();
        dmq.setQueue(signOutEventQueue);
        return dmq;
    }
    @Bean("penalizeEventProducer")
    public MessageProducer<MemberPenalizeEvent> penalizeEventProducer(@Qualifier("penalizeEventQueue") RedisMessageQueue penalizeEventQueue){
        DefaultMessageProducer<MemberPenalizeEvent> dmq = new com.github.davidmarquis.redisq.producer.DefaultMessageProducer<>();
        dmq.setQueue(penalizeEventQueue);
        return dmq;
    }
    @Bean("vipExchangeEventProducer")
    public MessageProducer<MemberVipExchangeEvent> vipExchangeEventProducer(@Qualifier("vipExchangeEventQueue") RedisMessageQueue vipExchangeEventQueue){
        DefaultMessageProducer<MemberVipExchangeEvent> dmq = new com.github.davidmarquis.redisq.producer.DefaultMessageProducer<>();
        dmq.setQueue(vipExchangeEventQueue);
        return dmq;
    }
    @Bean("changeEventProducer")
    public MessageProducer<MemberChangeEvent> changeEventProducer(@Qualifier("changeEventQueue") RedisMessageQueue changeEventQueue){
        DefaultMessageProducer<MemberChangeEvent> dmq = new com.github.davidmarquis.redisq.producer.DefaultMessageProducer<>();
        dmq.setQueue(changeEventQueue);
        return dmq;
    }
    //loop Consumer
    @Bean
    public MessageConsumer<MemberSignUpEvent> promoteRoleConsumer(
            @Qualifier("signUpEventQueue") RedisMessageQueue signUpEventQueue,
            @Qualifier("promoteRole") MemberSignUpPromoteRoleListener promoteRole){
        MessageConsumer<MemberSignUpEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(signUpEventQueue);
        messageConsumer.setConsumerId("SignUpEvent:PromoteRole");
        messageConsumer.setMessageListener(promoteRole);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<MemberSignUpEvent> inviteCodeConsumer(
            @Qualifier("signUpEventQueue") RedisMessageQueue signUpEventQueue,
            @Qualifier("inviteCode") MemberSignUpInviteCodeListener inviteCode){
        MessageConsumer<MemberSignUpEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(signUpEventQueue);
        messageConsumer.setConsumerId("SignUpEvent:InviteCode");
        messageConsumer.setMessageListener(inviteCode);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<MemberPenalizeEvent> changeStatusConsumer(
            @Qualifier("penalizeEventQueue") RedisMessageQueue penalizeEventQueue,
            @Qualifier("changeStatus") MemberPenalizeChangeStatusListener changeStatus){
        MessageConsumer<MemberPenalizeEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(penalizeEventQueue);
        messageConsumer.setConsumerId("PenalizeEvent:ChangeStatus");
        messageConsumer.setMessageListener(changeStatus);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<MemberVipExchangeEvent> changeGroupConsumer(
            @Qualifier("vipExchangeEventQueue") RedisMessageQueue vipExchangeEventQueue,
            @Qualifier("changeGroup") MemberVipExchangeGroupListener changeGroup){
        MessageConsumer<MemberVipExchangeEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(vipExchangeEventQueue);
        messageConsumer.setConsumerId("VipExchangeEvent:ChangeGroup");
        messageConsumer.setMessageListener(changeGroup);
        return messageConsumer;
    }
}
