use falling_tetromino_engine::{DelayParameters, ExtDuration, Stat};

use crate::game_modding::{CheeseConfig, ComboConfig};

#[derive(
    PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, serde::Serialize, serde::Deserialize,
)]
pub struct GameModePreferences {
    pub custom_config: CustomModeConfig,
    pub cheese_config: CheeseConfig,
    pub cheese_fall_and_lock_delays: (ExtDuration, ExtDuration),
    pub combo_config: ComboConfig,
    pub master_mode_unlocked: bool,
    pub experimental_mode_unlocked: bool,
}

impl Default for GameModePreferences {
    fn default() -> Self {
        Self {
            custom_config: CustomModeConfig::default(),
            cheese_config: CheeseConfig::default(),
            cheese_fall_and_lock_delays: (ExtDuration::Infinite, ExtDuration::Infinite),
            combo_config: ComboConfig::default(),
            master_mode_unlocked: false,
            experimental_mode_unlocked: false,
        }
    }
}

#[derive(
    PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Debug, serde::Serialize, serde::Deserialize,
)]
pub struct CustomModeConfig {
    pub seed: Option<u64>,
    pub start_board: Option<String>, // For more compact serialization of NewGameSettings, we store an encoded `Board` (see `StartBoard` mod.)
    pub fall_params: DelayParameters,
    pub lock_params: DelayParameters,
    pub win_condition: Option<Stat>,
}

impl Default for CustomModeConfig {
    fn default() -> Self {
        Self {
            fall_params: DelayParameters::standard_fall(),
            lock_params: DelayParameters::standard_lock(),
            win_condition: None,
            seed: None,
            start_board: None,
        }
    }
}
