use serde::{Deserialize, Serialize};

use super::StringOrNum;

#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, PartialEq, Eq)]
#[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "snake_case")]
pub enum TableGap {
    None,
    #[default]
    Space,
    Line,
}

impl TableGap {
    /// Returns the height in rows that this gap occupies.
    pub const fn height(self) -> u16 {
        match self {
            Self::None => 0,
            Self::Space | Self::Line => 1,
        }
    }
}

// TODO: Break this up.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))]
#[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEq, Eq))]
pub(crate) struct GeneralConfig {
    pub(crate) dot_marker: Option<bool>,
    pub(crate) rate: Option<StringOrNum>,
    pub(crate) basic: Option<bool>,
    pub(crate) default_time_value: Option<StringOrNum>,
    pub(crate) time_delta: Option<StringOrNum>,
    pub(crate) autohide_time: Option<bool>,
    pub(crate) hide_time: Option<bool>,
    pub(crate) default_widget_type: Option<String>,
    pub(crate) default_widget_count: Option<u64>,
    pub(crate) expanded: Option<bool>,
    pub(crate) use_old_network_legend: Option<bool>,
    #[serde(default)]
    pub(crate) table_gap: TableGap,
    pub(crate) battery: Option<bool>,
    pub(crate) disable_click: Option<bool>,
    pub(crate) disable_keys: Option<bool>,
    pub(crate) no_write: Option<bool>,
    pub(crate) show_table_scroll_position: Option<bool>,
    pub(crate) show_table_scroll_bar: Option<bool>,
    pub(crate) read_only: Option<bool>,
    pub(crate) disable_gpu: Option<bool>,
    pub(crate) retention: Option<StringOrNum>,
    pub(crate) temperature_type: Option<String>,

    // FIXME: Deprecate these in the future.
    pub(crate) hide_avg_cpu: Option<bool>,
    pub(crate) cpu_left_legend: Option<bool>,
    pub(crate) average_cpu_row: Option<bool>,
    pub(crate) enable_cache_memory: Option<bool>,
    // #[cfg(feature = "zfs")]
    pub(crate) free_arc: Option<bool>,
    pub(crate) network_use_bytes: Option<bool>,
    pub(crate) network_use_log: Option<bool>,
    pub(crate) network_use_binary_prefix: Option<bool>,
    pub(crate) network_legend: Option<String>,
    pub(crate) memory_legend: Option<String>,
    // #[cfg(target_os = "linux")]
    pub(crate) hide_k_threads: Option<bool>,
    pub(crate) tree_collapse: Option<bool>,
    pub(crate) process_command: Option<bool>,
    // This does nothing on Windows, but we leave it enabled to make the config file consistent
    // across platforms.
    //
    // #[cfg(any(target_os = "linux", target_os = "macos", target_os = "freebsd"))]
    pub(crate) disable_advanced_kill: Option<bool>,
    pub(crate) process_memory_as_value: Option<bool>,
    pub(crate) group_processes: Option<bool>,
    pub(crate) regex: Option<bool>,
    pub(crate) case_sensitive: Option<bool>,
    pub(crate) whole_word: Option<bool>,
    pub(crate) tree: Option<bool>,
    pub(crate) current_usage: Option<bool>,
    pub(crate) unnormalized_cpu: Option<bool>,
}
