use std::collections::HashMap;
#[derive(Debug, Clone)]
pub struct RoomEvent {
pub user_id: String,
pub event_type: EventType,
pub payload: String,
}
#[derive(Debug, Clone)]
pub enum EventType {
Join,
Leave,
Message,
Typing,
}
pub struct ChatRoomManager {
rooms: HashMap<String, usize>, }
impl ChatRoomManager {
pub fn new() -> Self {
Self {
rooms: HashMap::new(),
}
}
pub fn get_or_create_room(&mut self, room_id: &str) -> usize {
let count = self.rooms.entry(room_id.to_string()).or_insert(0);
*count += 1;
*count
}
pub fn remove_room(&mut self, room_id: &str) {
if let Some(count) = self.rooms.get_mut(room_id) {
*count = count.saturating_sub(1);
if *count == 0 {
self.rooms.remove(room_id);
}
}
}
pub fn room_count(&self) -> usize {
self.rooms.len()
}
}
impl Default for ChatRoomManager {
fn default() -> Self {
Self::new()
}
}