use serde::{Deserialize, Serialize}; use std::collections::HashMap; #[derive(Debug, Clone, Serialize, Deserialize)] pub enum GameError { InvalidAction(String), InsufficientBalance, InvalidBet, GameOver, SessionNotFound, InternalError(String), } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum GamePhase { WaitingToStart, Playing, Finished, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GameState { pub session_id: String, pub game_type: String, pub bet_amount: u64, pub phase: GamePhase, pub data: HashMap, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct GameResult { pub session_id: String, pub game_type: String, pub bet_amount: u64, pub winnings: u64, pub final_balance: u64, pub result_data: HashMap, } pub trait Game: Send + Sync { fn game_type(&self) -> &'static str; fn get_name(&self) -> &'static str; fn get_description(&self) -> &'static str; fn validate_bet(&self, bet_amount: u64, user_balance: u64) -> Result<(), GameError> { if bet_amount == 0 { return Err(GameError::InvalidBet); } if bet_amount > user_balance { return Err(GameError::InsufficientBalance); } Ok(()) } fn prepare_state(&self, username: &str, bet_amount: u64) -> GameState; fn process_action( &self, state: &GameState, action: &str, params: &[&str], ) -> Result; fn calculate_result(&self, state: &GameState) -> Result; }