// Path: rock-paper-scissors-lizard-spock/src/main/java/be/ordina/jworks/rpsls/game/pubsub/ChatEventConsumer.java
// @Slf4j
// public class ChatEventConsumer {
// 
//     private final SimpMessagingTemplate template;
// 
//     public ChatEventConsumer(SimpMessagingTemplate template) {
//         this.template = template;
//     }
// 
//     @SuppressWarnings("unused")
//     public void handleMessage(final String message) {
//         log.debug("[CHAT] " + message);
// 
//         log.info("Sending ChatEvent to Websocket: " + message);
//         template.convertAndSend("/topic/chat", message);
//     }
// }
// 
// Path: rock-paper-scissors-lizard-spock/src/main/java/be/ordina/jworks/rpsls/game/pubsub/GameEventConsumer.java
// @Slf4j
// public class GameEventConsumer {
// 
//     private final SimpMessagingTemplate template;
// 
//     public GameEventConsumer(SimpMessagingTemplate template) {
//         this.template = template;
//     }
// 
//     @SuppressWarnings("unused")
//     public void handleMessage(final String message) {
//         log.info("[GAME] " + message);
// 
//         log.info("Sending GameEvent to Websocket: " + message);
//         template.convertAndSend("/topic/game", message);
//     }
// }


import be.ordina.jworks.rpsls.game.pubsub.ChatEventConsumer;
import be.ordina.jworks.rpsls.game.pubsub.GameEventConsumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import redis.clients.jedis.JedisShardInfo;
        container.setConnectionFactory(redisConnectionFactory());
        container.addMessageListener(gameMessageListener(simpMessagingTemplate), gameTopic());
        container.addMessageListener(chatMessageListener(simpMessagingTemplate), chatTopic());

        return container;
    }

    @Bean
    public RedisTemplate<String, Object> messageRedisTemplate() {
        RedisTemplate<String, Object> template = new RedisTemplate<>();

        template.setConnectionFactory(redisConnectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new JsonRedisSerializer());

        return template;
    }

    @Bean
    public MessageListener gameMessageListener(SimpMessagingTemplate simpMessagingTemplate) {
        return new MessageListenerAdapter(new GameEventConsumer(simpMessagingTemplate));
    }

    @Bean
    public Topic gameTopic() {
        return new ChannelTopic("pubsub:game");
    }

    @Bean
    public MessageListener chatMessageListener(SimpMessagingTemplate simpMessagingTemplate) {
// Path: rock-paper-scissors-lizard-spock/src/main/java/be/ordina/jworks/rpsls/game/pubsub/ChatEventConsumer.java
// @Slf4j
// public class ChatEventConsumer {
// 
//     private final SimpMessagingTemplate template;
// 
//     public ChatEventConsumer(SimpMessagingTemplate template) {
//         this.template = template;
//     }
// 
//     @SuppressWarnings("unused")
//     public void handleMessage(final String message) {
//         log.debug("[CHAT] " + message);
// 
//         log.info("Sending ChatEvent to Websocket: " + message);
//         template.convertAndSend("/topic/chat", message);
//     }
// }
// 
// Path: rock-paper-scissors-lizard-spock/src/main/java/be/ordina/jworks/rpsls/game/pubsub/GameEventConsumer.java
// @Slf4j
// public class GameEventConsumer {
// 
//     private final SimpMessagingTemplate template;
// 
//     public GameEventConsumer(SimpMessagingTemplate template) {
//         this.template = template;
//     }
// 
//     @SuppressWarnings("unused")
//     public void handleMessage(final String message) {
//         log.info("[GAME] " + message);
// 
//         log.info("Sending GameEvent to Websocket: " + message);
//         template.convertAndSend("/topic/game", message);
//     }
// }


// Path: rock-paper-scissors-lizard-spock/src/main/java/be/ordina/jworks/rpsls/configuration/RedisConfiguration.java
import be.ordina.jworks.rpsls.game.pubsub.ChatEventConsumer;
import be.ordina.jworks.rpsls.game.pubsub.GameEventConsumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import redis.clients.jedis.JedisShardInfo;

        container.setConnectionFactory(redisConnectionFactory());
        container.addMessageListener(gameMessageListener(simpMessagingTemplate), gameTopic());
        container.addMessageListener(chatMessageListener(simpMessagingTemplate), chatTopic());

        return container;
    }

    @Bean
    public RedisTemplate<String, Object> messageRedisTemplate() {
        RedisTemplate<String, Object> template = new RedisTemplate<>();

        template.setConnectionFactory(redisConnectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new JsonRedisSerializer());

        return template;
    }

    @Bean
    public MessageListener gameMessageListener(SimpMessagingTemplate simpMessagingTemplate) {
        return new MessageListenerAdapter(new GameEventConsumer(simpMessagingTemplate));
    }

    @Bean
    public Topic gameTopic() {
        return new ChannelTopic("pubsub:game");
    }

    @Bean
    public MessageListener chatMessageListener(SimpMessagingTemplate simpMessagingTemplate) {
        return new MessageListenerAdapter(new ChatEventConsumer(simpMessagingTemplate));