use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use crate::chat::ChatService;
use crate::config::AppConfig;
use crate::engine::game::Game;
use crate::ws::WsManager;
pub type GameStore = RwLock<HashMap<String, Game>>;
pub struct AppState {
pub games: GameStore,
pub config: AppConfig,
pub start_time: std::time::Instant,
pub chat: Option<Arc<ChatService>>,
pub ws: Arc<WsManager>,
}
pub type SharedState = Arc<AppState>;
impl AppState {
pub fn new(config: AppConfig) -> SharedState {
let chat = if config.llm.enabled {
Some(ChatService::new(config.llm.clone()))
} else {
None
};
Arc::new(AppState {
games: RwLock::new(HashMap::new()),
config,
start_time: std::time::Instant::now(),
chat,
ws: WsManager::new(),
})
}
}