use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum LanguageKey {
    Multi,
    Arabic,
    Bengali,
    Bulgarian,
    Burmese,
    Catalan,
    ChineseSimp,
    ChineseTrad,
    Czech,
    Danish,
    Dutch,
    English,
    Filipino,
    Finnish,
    French,
    German,
    Greek,
    Hebrew,
    Hindi,
    Hungarian,
    Indonesian,
    Italian,
    Japanese,
    Korean,
    Lithuanian,
    Malay,
    Mongolian,
    Persian,
    Polish,
    PortugueseBr,
    PortuguesePt,
    Romanian,
    Russian,
    SerboCroatian,
    SpanishEs,
    SpanishLatam,
    Swedish,
    Thai,
    Turkish,
    Ukrainian,
    Vietnamese,
}

impl LanguageKey {
    pub fn name(&self) -> &'static str {
        match self {
            LanguageKey::Multi => "Multi",
            LanguageKey::Arabic => "Arabic",
            LanguageKey::Bengali => "Bengali",
            LanguageKey::Bulgarian => "Bulgarian",
            LanguageKey::Burmese => "Burmese",
            LanguageKey::Catalan => "Catalan",
            LanguageKey::ChineseSimp => "Chinese (Simplified)",
            LanguageKey::ChineseTrad => "Chinese (Traditional)",
            LanguageKey::Czech => "Czech",
            LanguageKey::Danish => "Danish",
            LanguageKey::Dutch => "Dutch",
            LanguageKey::English => "English",
            LanguageKey::Filipino => "Filipino",
            LanguageKey::Finnish => "Finnish",
            LanguageKey::French => "French",
            LanguageKey::German => "German",
            LanguageKey::Greek => "Greek",
            LanguageKey::Hebrew => "Hebrew",
            LanguageKey::Hindi => "Hindi",
            LanguageKey::Hungarian => "Hungarian",
            LanguageKey::Indonesian => "Indonesian",
            LanguageKey::Italian => "Italian",
            LanguageKey::Japanese => "Japanese",
            LanguageKey::Korean => "Korean",
            LanguageKey::Lithuanian => "Lithuanian",
            LanguageKey::Malay => "Malay",
            LanguageKey::Mongolian => "Mongolian",
            LanguageKey::Persian => "Persian",
            LanguageKey::Polish => "Polish",
            LanguageKey::PortugueseBr => "Portuguese (Brazil)",
            LanguageKey::PortuguesePt => "Portuguese (Portugal)",
            LanguageKey::Romanian => "Romanian",
            LanguageKey::Russian => "Russian",
            LanguageKey::SerboCroatian => "Serbo-Croatian",
            LanguageKey::SpanishEs => "Spanish (Spain)",
            LanguageKey::SpanishLatam => "Spanish (Latin America)",
            LanguageKey::Swedish => "Swedish",
            LanguageKey::Thai => "Thai",
            LanguageKey::Turkish => "Turkish",
            LanguageKey::Ukrainian => "Ukrainian",
            LanguageKey::Vietnamese => "Vietnamese",
        }
    }

    pub fn flag_code(&self) -> &'static str {
        match self {
            LanguageKey::Multi => "",
            LanguageKey::Arabic => "sa",
            LanguageKey::Bengali => "bd",
            LanguageKey::Bulgarian => "bg",
            LanguageKey::Burmese => "mm",
            LanguageKey::Catalan => "ct",
            LanguageKey::ChineseSimp => "cn",
            LanguageKey::ChineseTrad => "hk",
            LanguageKey::Czech => "cz",
            LanguageKey::Danish => "dk",
            LanguageKey::Dutch => "nl",
            LanguageKey::English => "en",
            LanguageKey::Filipino => "ph",
            LanguageKey::Finnish => "fi",
            LanguageKey::French => "fr",
            LanguageKey::German => "de",
            LanguageKey::Greek => "gr",
            LanguageKey::Hebrew => "il",
            LanguageKey::Hindi => "in",
            LanguageKey::Hungarian => "hu",
            LanguageKey::Indonesian => "id",
            LanguageKey::Italian => "it",
            LanguageKey::Japanese => "jp",
            LanguageKey::Korean => "kr",
            LanguageKey::Lithuanian => "lt",
            LanguageKey::Malay => "my",
            LanguageKey::Mongolian => "mn",
            LanguageKey::Persian => "ir",
            LanguageKey::Polish => "pl",
            LanguageKey::PortugueseBr => "br",
            LanguageKey::PortuguesePt => "pt",
            LanguageKey::Romanian => "ro",
            LanguageKey::Russian => "ru",
            LanguageKey::SerboCroatian => "rs",
            LanguageKey::SpanishEs => "es",
            LanguageKey::SpanishLatam => "mx",
            LanguageKey::Swedish => "se",
            LanguageKey::Thai => "th",
            LanguageKey::Turkish => "tr",
            LanguageKey::Ukrainian => "ua",
            LanguageKey::Vietnamese => "vn",
        }
    }

    pub fn iso639_1(&self) -> &'static str {
        match self {
            LanguageKey::Multi => "",
            LanguageKey::Arabic => "ar",
            LanguageKey::Bengali => "bn",
            LanguageKey::Bulgarian => "bg",
            LanguageKey::Burmese => "my",
            LanguageKey::Catalan => "ca",
            LanguageKey::ChineseSimp => "zh",
            LanguageKey::ChineseTrad => "zh",
            LanguageKey::Czech => "cs",
            LanguageKey::Danish => "da",
            LanguageKey::Dutch => "nl",
            LanguageKey::English => "en",
            LanguageKey::Filipino => "fil",
            LanguageKey::Finnish => "fi",
            LanguageKey::French => "fr",
            LanguageKey::German => "de",
            LanguageKey::Greek => "el",
            LanguageKey::Hebrew => "he",
            LanguageKey::Hindi => "hi",
            LanguageKey::Hungarian => "hu",
            LanguageKey::Indonesian => "id",
            LanguageKey::Italian => "it",
            LanguageKey::Japanese => "jp",
            LanguageKey::Korean => "ko",
            LanguageKey::Lithuanian => "lt",
            LanguageKey::Malay => "ms",
            LanguageKey::Mongolian => "mn",
            LanguageKey::Persian => "fa",
            LanguageKey::Polish => "pl",
            LanguageKey::PortugueseBr => "pt",
            LanguageKey::PortuguesePt => "pt",
            LanguageKey::Romanian => "ro",
            LanguageKey::Russian => "ru",
            LanguageKey::SerboCroatian => "sr",
            LanguageKey::SpanishEs => "es",
            LanguageKey::SpanishLatam => "es",
            LanguageKey::Swedish => "sv",
            LanguageKey::Thai => "th",
            LanguageKey::Turkish => "tr",
            LanguageKey::Ukrainian => "uk",
            LanguageKey::Vietnamese => "vi",
        }
    }
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Language {
    pub key: LanguageKey,
    pub name: String,
    pub flag_code: String,
    pub iso639_1: String,
}

impl Language {
    pub fn new(key: LanguageKey) -> Self {
        Self {
            key,
            name: key.name().to_string(),
            flag_code: key.flag_code().to_string(),
            iso639_1: key.iso639_1().to_string(),
        }
    }
}
