use serde::{Deserialize, Serialize};

use crate::watcher::WatchFolder;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct AppConfig {
    pub first_run_complete: bool,
    pub tutorial_complete: bool,
    pub output_subfolder: String,
    pub output_fixed_path: Option<String>,
    pub overwrite_behavior: OverwriteBehavior,
    pub remember_settings: bool,
    pub skill_level: SkillLevel,
    pub thread_count: ThreadCount,
    pub error_behavior: ErrorBehavior,
    pub notify_on_completion: bool,
    pub play_completion_sound: bool,
    pub auto_open_output: bool,
    pub high_contrast: bool,
    pub large_text: bool,
    pub reduced_motion: bool,
    pub history_max_entries: usize,
    pub history_max_days: u32,
    pub watch_folders: Vec<WatchFolder>,
}

impl Default for AppConfig {
    fn default() -> Self {
        Self {
            first_run_complete: false,
            tutorial_complete: false,
            output_subfolder: "processed".into(),
            output_fixed_path: None,
            overwrite_behavior: OverwriteBehavior::Ask,
            remember_settings: true,
            skill_level: SkillLevel::Simple,
            thread_count: ThreadCount::Auto,
            error_behavior: ErrorBehavior::SkipAndContinue,
            notify_on_completion: true,
            play_completion_sound: false,
            auto_open_output: false,
            high_contrast: false,
            large_text: false,
            reduced_motion: false,
            history_max_entries: 50,
            history_max_days: 30,
            watch_folders: Vec::new(),
        }
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OverwriteBehavior {
    Ask,
    AutoRename,
    Overwrite,
    Skip,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum SkillLevel {
    Simple,
    Detailed,
}

impl SkillLevel {
    pub fn is_advanced(&self) -> bool {
        matches!(self, Self::Detailed)
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ThreadCount {
    Auto,
    Manual(usize),
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ErrorBehavior {
    SkipAndContinue,
    PauseOnError,
}
