//package org.egl_cepgl.pm.controller;
//
//import lombok.extern.slf4j.Slf4j;
//import org.egl_cepgl.pm.dto.MessageText;
//import org.egl_cepgl.pm.model.ChatInbox;
//import org.egl_cepgl.pm.model.ChatMessage;
//import org.egl_cepgl.pm.service.ChatService;
//import org.springframework.messaging.handler.annotation.DestinationVariable;
//import org.springframework.messaging.handler.annotation.MessageMapping;
//import org.springframework.messaging.handler.annotation.Payload;
//import org.springframework.stereotype.Controller;
//import reactor.core.publisher.Flux;
//
//@Slf4j
//@Controller
//public class ChatController
//{
//    private final ChatService chatService;
//
//    private String email;
//
//    public ChatController(ChatService chatService) {
//        this.chatService = chatService;
//    }
//
//    @MessageMapping("recentChats")
//    public Flux<ChatInbox> recentChats(@Payload String data)
//    {
//        return this.chatService.getRecentChats(data. replaceAll("\"",""));
//    }
//
//    @MessageMapping("messages/{inboxId}")
//    public Flux<ChatMessage> getMsgsByInbox(@DestinationVariable String inboxId) {
//        return this.chatService.getMsgsByInbox(inboxId).log();
//    }
//
//    @MessageMapping("send/{inboxId}")
//    public void sendMsg(@DestinationVariable String inboxId, @Payload MessageText msg) {
//        this.chatService.saveMsg(inboxId, msg);
//    }
//
////    @MessageMapping("hello")
////    public Mono<Void> hello(Greeting p) {
////        log.info("received: {} at {}", p, Instant.now());
////        return Mono.empty();
////    }
////
//////    private final Sinks.Many<Object> sink;
//////
//////    public ChatController(Sinks.Many<Object> sink) {
//////        this.sink = sink;
//////    }
////
////    @MessageMapping("chat.sendMessage")  // Maps messages sent to "chat.sendMessage" WebSocket destination
////    @SendTo("/topic/public")  // Specifies that the return message will be sent to "/topic/public"
////    public WSChatMsg sendMessage(@Payload WSChatMsg msg) {
////        // Log the sender and content of the message for debugging
////        System.out.println("Message received from " + msg.getSender() + ": " + msg.getContent());
////        // Broadcast the message to all subscribers on the "/topic/public" topic
////        return msg;
////    }
////
////    @MessageMapping("chat.addUser")  // Maps messages sent to "chat.addUser" WebSocket destination
////    @SendTo("/topic/chat")  // Specifies that the return message will be sent to "/topic/chat"
////    public WSChatMsg addUser(@Payload WSChatMsg msg, SimpMessageHeaderAccessor headerAccessor) {
////        // Store the username in the WebSocket session attributes
////        headerAccessor.getSessionAttributes().put("username", msg.getSender());
////        // Log when a user joins the chat
////        System.out.println("User joined: " + msg.getSender());
////        // Broadcast the user join event to all subscribers on the "/topic/chat" topic
////        return msg;
////    }
//
//}
//
////@Data
////class Greeting {
////    String message;
////}
//
//
