use crate::domain::theme::{Theme, ThemeRepository};

const DEFAULT_CSS: &str = include_str!("../../resources/themes/default.css");
const DARK_CSS: &str = include_str!("../../resources/themes/dark.css");
const SEPIA_CSS: &str = include_str!("../../resources/themes/sepia.css");
const LARGE_TEXT_CSS: &str = include_str!("../../resources/themes/large-text.css");
const EMERALD_CSS: &str = include_str!("../../resources/themes/emerald.css");
const SHELL_INDIGO_CSS: &str = include_str!("../../resources/themes/shell-indigo.css");

pub struct StaticThemeRepository;

impl ThemeRepository for StaticThemeRepository {
    fn list(&self) -> Vec<Theme> {
        vec![
            Theme { id: "default".into(), label: "Défaut".into() },
            Theme { id: "dark".into(), label: "Mode sombre".into() },
            Theme { id: "sepia".into(), label: "Sépia".into() },
            Theme { id: "large-text".into(), label: "Grand texte".into() },
            Theme { id: "emerald".into(), label: "Accent émeraude".into() },
            Theme { id: "shell-indigo".into(), label: "Shell Indigo".into() },
        ]
    }

    fn get_css(&self, id: &str) -> Option<String> {
        match id {
            "default" => Some(DEFAULT_CSS.to_string()),
            "dark" => Some(DARK_CSS.to_string()),
            "sepia" => Some(SEPIA_CSS.to_string()),
            "large-text" => Some(LARGE_TEXT_CSS.to_string()),
            "emerald" => Some(EMERALD_CSS.to_string()),
            "shell-indigo" => Some(SHELL_INDIGO_CSS.to_string()),
            _ => None,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::domain::theme::ThemeRepository;

    #[test]
    fn list_returns_all_themes() {
        let repo = StaticThemeRepository;
        let themes = repo.list();
        assert_eq!(themes.len(), 6);
        let ids: Vec<&str> = themes.iter().map(|t| t.id.as_str()).collect();
        assert!(ids.contains(&"default"));
        assert!(ids.contains(&"dark"));
        assert!(ids.contains(&"shell-indigo"));
    }

    #[test]
    fn get_css_known_themes() {
        let repo = StaticThemeRepository;
        for id in ["default", "dark", "sepia", "large-text", "emerald", "shell-indigo"] {
            let css = repo.get_css(id);
            assert!(css.is_some(), "CSS manquant pour le thème {id}");
            assert!(!css.unwrap().is_empty());
        }
    }

    #[test]
    fn get_css_unknown_returns_none() {
        let repo = StaticThemeRepository;
        assert!(repo.get_css("nonexistent").is_none());
    }
}
