package com.apobates.forum.thrones.admin;

import com.apobates.forum.core.impl.event.ModeratorBornEvent;
import com.apobates.forum.core.impl.event.ModeratorRecallEvent;
import com.apobates.forum.thrones.admin.event.ModeratorBornChangeRoleListener;
import com.apobates.forum.thrones.admin.event.ModeratorRecallChangeRoleListener;
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 ThronesAdminRedisEventConfig {
    //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<ModeratorRecallEvent> moderatorRecallChangeRoleConsumer(
            @Qualifier("moderatorRecallQueue") RedisMessageQueue moderatorRecallQueue,
            @Qualifier("recallChangeRole") ModeratorRecallChangeRoleListener recallChangeRole){
        MessageConsumer<ModeratorRecallEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(moderatorRecallQueue);
        messageConsumer.setConsumerId("ModeratorRecallEvent:recallChangeRole");
        messageConsumer.setMessageListener(recallChangeRole);
        return messageConsumer;
    }
    @Bean
    public MessageConsumer<ModeratorBornEvent> moderatorBornChangeRoleConsumer(
            @Qualifier("moderatorBornQueue") RedisMessageQueue moderatorBornQueue,
            @Qualifier("bornChangeRole") ModeratorBornChangeRoleListener bornChangeRole){
        MessageConsumer<ModeratorBornEvent> messageConsumer = new com.github.davidmarquis.redisq.consumer.MessageConsumer<>();
        messageConsumer.setQueue(moderatorBornQueue);
        messageConsumer.setConsumerId("ModeratorBornEvent:bornChangeRole");
        messageConsumer.setMessageListener(bornChangeRole);
        return messageConsumer;
    }
}
