// This file is automatically generated. DO NOT EDIT.

//! Languages and countries

use std::str::FromStr;

use serde::{Deserialize, Serialize};

use crate::error::Error;

/// Available languages
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum Language {
    /// Afrikaans
    Af,
    /// Amharic / አማርኛ
    Am,
    /// Arabic / العربية
    Ar,
    /// Assamese / অসমীয়া
    As,
    /// Azerbaijani / Azərbaycan
    Az,
    /// Belarusian / Беларуская
    Be,
    /// Bulgarian / Български
    Bg,
    /// Bangla / বাংলা
    Bn,
    /// Bosnian / Bosanski
    Bs,
    /// Catalan / Català
    Ca,
    /// Czech / Čeština
    Cs,
    /// Danish / Dansk
    Da,
    /// German / Deutsch
    De,
    /// Greek / Ελληνικά
    El,
    /// English (US)
    En,
    /// English (UK)
    #[serde(rename = "en-GB")]
    EnGb,
    /// English (India)
    #[serde(rename = "en-IN")]
    EnIn,
    /// Spanish / Español (España)
    Es,
    /// Latin American Spanish / Español (Latinoamérica)
    #[serde(rename = "es-419")]
    Es419,
    /// Spanish (United States) / Español (US)
    #[serde(rename = "es-US")]
    EsUs,
    /// Estonian / Eesti
    Et,
    /// Basque / Euskara
    Eu,
    /// Persian / فارسی
    Fa,
    /// Finnish / Suomi
    Fi,
    /// Filipino
    Fil,
    /// French / Français
    Fr,
    /// Canadian French / Français (Canada)
    #[serde(rename = "fr-CA")]
    FrCa,
    /// Galician / Galego
    Gl,
    /// Gujarati / ગુજરાતી
    Gu,
    /// Hindi / हिन्दी
    Hi,
    /// Croatian / Hrvatski
    Hr,
    /// Hungarian / Magyar
    Hu,
    /// Armenian / Հայերեն
    Hy,
    /// Indonesian / Bahasa Indonesia
    Id,
    /// Icelandic / Íslenska
    Is,
    /// Italian / Italiano
    It,
    /// Hebrew / עברית
    Iw,
    /// Japanese / 日本語
    Ja,
    /// Georgian / ქართული
    Ka,
    /// Kazakh / Қазақ Тілі
    Kk,
    /// Khmer / ខ្មែរ
    Km,
    /// Kannada / ಕನ್ನಡ
    Kn,
    /// Korean / 한국어
    Ko,
    /// Kyrgyz / Кыргызча
    Ky,
    /// Lao / ລາວ
    Lo,
    /// Lithuanian / Lietuvių
    Lt,
    /// Latvian / Latviešu valoda
    Lv,
    /// Macedonian / Македонски
    Mk,
    /// Malayalam / മലയാളം
    Ml,
    /// Mongolian / Монгол
    Mn,
    /// Marathi / मराठी
    Mr,
    /// Malay / Bahasa Malaysia
    Ms,
    /// Burmese / ဗမာ
    My,
    /// Nepali / नेपाली
    Ne,
    /// Dutch / Nederlands
    Nl,
    /// Norwegian / Norsk
    No,
    /// Odia / ଓଡ଼ିଆ
    Or,
    /// Punjabi / ਪੰਜਾਬੀ
    Pa,
    /// Polish / Polski
    Pl,
    /// Portuguese / Português (Brasil)
    Pt,
    /// European Portuguese / Português
    #[serde(rename = "pt-PT")]
    PtPt,
    /// Romanian / Română
    Ro,
    /// Russian / Русский
    Ru,
    /// Sinhala / සිංහල
    Si,
    /// Slovak / Slovenčina
    Sk,
    /// Slovenian / Slovenščina
    Sl,
    /// Albanian / Shqip
    Sq,
    /// Serbian / Српски
    Sr,
    /// Serbian (Latin) / Srpski
    #[serde(rename = "sr-Latn")]
    SrLatn,
    /// Swedish / Svenska
    Sv,
    /// Swahili / Kiswahili
    Sw,
    /// Tamil / தமிழ்
    Ta,
    /// Telugu / తెలుగు
    Te,
    /// Thai / ภาษาไทย
    Th,
    /// Turkish / Türkçe
    Tr,
    /// Ukrainian / Українська
    Uk,
    /// Urdu / اردو
    Ur,
    /// Uzbek / O‘zbek
    Uz,
    /// Vietnamese / Tiếng Việt
    Vi,
    /// Chinese (China) / 中文 (简体)
    #[serde(rename = "zh-CN")]
    ZhCn,
    /// Chinese (Hong Kong) / 中文 (香港)
    #[serde(rename = "zh-HK")]
    ZhHk,
    /// Chinese (Taiwan) / 中文 (繁體)
    #[serde(rename = "zh-TW")]
    ZhTw,
    /// Zulu / IsiZulu
    Zu,
}

/// Available countries
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "UPPERCASE")]
#[non_exhaustive]
pub enum Country {
    /// United Arab Emirates
    Ae,
    /// Argentina
    Ar,
    /// Austria
    At,
    /// Australia
    Au,
    /// Azerbaijan
    Az,
    /// Bosnia and Herzegovina
    Ba,
    /// Bangladesh
    Bd,
    /// Belgium
    Be,
    /// Bulgaria
    Bg,
    /// Bahrain
    Bh,
    /// Bolivia
    Bo,
    /// Brazil
    Br,
    /// Belarus
    By,
    /// Canada
    Ca,
    /// Switzerland
    Ch,
    /// Chile
    Cl,
    /// Colombia
    Co,
    /// Costa Rica
    Cr,
    /// Cyprus
    Cy,
    /// Czechia
    Cz,
    /// Germany
    De,
    /// Denmark
    Dk,
    /// Dominican Republic
    Do,
    /// Algeria
    Dz,
    /// Ecuador
    Ec,
    /// Estonia
    Ee,
    /// Egypt
    Eg,
    /// Spain
    Es,
    /// Finland
    Fi,
    /// France
    Fr,
    /// United Kingdom
    Gb,
    /// Georgia
    Ge,
    /// Ghana
    Gh,
    /// Greece
    Gr,
    /// Guatemala
    Gt,
    /// Hong Kong
    Hk,
    /// Honduras
    Hn,
    /// Croatia
    Hr,
    /// Hungary
    Hu,
    /// Indonesia
    Id,
    /// Ireland
    Ie,
    /// Israel
    Il,
    /// India
    In,
    /// Iraq
    Iq,
    /// Iceland
    Is,
    /// Italy
    It,
    /// Jamaica
    Jm,
    /// Jordan
    Jo,
    /// Japan
    Jp,
    /// Kenya
    Ke,
    /// Cambodia
    Kh,
    /// South Korea
    Kr,
    /// Kuwait
    Kw,
    /// Kazakhstan
    Kz,
    /// Laos
    La,
    /// Lebanon
    Lb,
    /// Liechtenstein
    Li,
    /// Sri Lanka
    Lk,
    /// Lithuania
    Lt,
    /// Luxembourg
    Lu,
    /// Latvia
    Lv,
    /// Libya
    Ly,
    /// Morocco
    Ma,
    /// Montenegro
    Me,
    /// North Macedonia
    Mk,
    /// Malta
    Mt,
    /// Mexico
    Mx,
    /// Malaysia
    My,
    /// Nigeria
    Ng,
    /// Nicaragua
    Ni,
    /// Netherlands
    Nl,
    /// Norway
    No,
    /// Nepal
    Np,
    /// New Zealand
    Nz,
    /// Oman
    Om,
    /// Panama
    Pa,
    /// Peru
    Pe,
    /// Papua New Guinea
    Pg,
    /// Philippines
    Ph,
    /// Pakistan
    Pk,
    /// Poland
    Pl,
    /// Puerto Rico
    Pr,
    /// Portugal
    Pt,
    /// Paraguay
    Py,
    /// Qatar
    Qa,
    /// Romania
    Ro,
    /// Serbia
    Rs,
    /// Russia
    Ru,
    /// Saudi Arabia
    Sa,
    /// Sweden
    Se,
    /// Singapore
    Sg,
    /// Slovenia
    Si,
    /// Slovakia
    Sk,
    /// Senegal
    Sn,
    /// El Salvador
    Sv,
    /// Thailand
    Th,
    /// Tunisia
    Tn,
    /// Turkey
    Tr,
    /// Taiwan
    Tw,
    /// Tanzania
    Tz,
    /// Ukraine
    Ua,
    /// Uganda
    Ug,
    /// United States
    Us,
    /// Uruguay
    Uy,
    /// Venezuela
    Ve,
    /// Vietnam
    Vn,
    /// Yemen
    Ye,
    /// South Africa
    Za,
    /// Zimbabwe
    Zw,
    /// Global (can only be used for music charts)
    Zz,
}

/// Array of all available languages
/// The languages are sorted by their native names. This array can be used to display
/// a language selection or to get the language code from a language name using binary search.
pub const LANGUAGES: [Language; 83] = [
    Language::Af,
    Language::Az,
    Language::Id,
    Language::Ms,
    Language::Bs,
    Language::Ca,
    Language::Da,
    Language::De,
    Language::Et,
    Language::EnIn,
    Language::EnGb,
    Language::En,
    Language::Es,
    Language::Es419,
    Language::EsUs,
    Language::Eu,
    Language::Fil,
    Language::Fr,
    Language::FrCa,
    Language::Gl,
    Language::Hr,
    Language::Zu,
    Language::It,
    Language::Sw,
    Language::Lv,
    Language::Lt,
    Language::Hu,
    Language::Nl,
    Language::No,
    Language::Uz,
    Language::Pl,
    Language::PtPt,
    Language::Pt,
    Language::Ro,
    Language::Sq,
    Language::Sk,
    Language::Sl,
    Language::SrLatn,
    Language::Fi,
    Language::Sv,
    Language::Vi,
    Language::Tr,
    Language::Is,
    Language::Cs,
    Language::El,
    Language::Be,
    Language::Bg,
    Language::Ky,
    Language::Mk,
    Language::Mn,
    Language::Ru,
    Language::Sr,
    Language::Uk,
    Language::Kk,
    Language::Hy,
    Language::Iw,
    Language::Ur,
    Language::Ar,
    Language::Fa,
    Language::Ne,
    Language::Mr,
    Language::Hi,
    Language::As,
    Language::Bn,
    Language::Pa,
    Language::Gu,
    Language::Or,
    Language::Ta,
    Language::Te,
    Language::Kn,
    Language::Ml,
    Language::Si,
    Language::Th,
    Language::Lo,
    Language::My,
    Language::Ka,
    Language::Am,
    Language::Km,
    Language::ZhCn,
    Language::ZhTw,
    Language::ZhHk,
    Language::Ja,
    Language::Ko,
];

/// Array of all available countries
///
/// The countries are sorted by their english names. This array can be used to display
/// a country selection or to get the country code from a country name using binary search.
pub const COUNTRIES: [Country; 109] = [
    Country::Dz,
    Country::Ar,
    Country::Au,
    Country::At,
    Country::Az,
    Country::Bh,
    Country::Bd,
    Country::By,
    Country::Be,
    Country::Bo,
    Country::Ba,
    Country::Br,
    Country::Bg,
    Country::Kh,
    Country::Ca,
    Country::Cl,
    Country::Co,
    Country::Cr,
    Country::Hr,
    Country::Cy,
    Country::Cz,
    Country::Dk,
    Country::Do,
    Country::Ec,
    Country::Eg,
    Country::Sv,
    Country::Ee,
    Country::Fi,
    Country::Fr,
    Country::Ge,
    Country::De,
    Country::Gh,
    Country::Gr,
    Country::Gt,
    Country::Hn,
    Country::Hk,
    Country::Hu,
    Country::Is,
    Country::In,
    Country::Id,
    Country::Iq,
    Country::Ie,
    Country::Il,
    Country::It,
    Country::Jm,
    Country::Jp,
    Country::Jo,
    Country::Kz,
    Country::Ke,
    Country::Kw,
    Country::La,
    Country::Lv,
    Country::Lb,
    Country::Ly,
    Country::Li,
    Country::Lt,
    Country::Lu,
    Country::My,
    Country::Mt,
    Country::Mx,
    Country::Me,
    Country::Ma,
    Country::Np,
    Country::Nl,
    Country::Nz,
    Country::Ni,
    Country::Ng,
    Country::Mk,
    Country::No,
    Country::Om,
    Country::Pk,
    Country::Pa,
    Country::Pg,
    Country::Py,
    Country::Pe,
    Country::Ph,
    Country::Pl,
    Country::Pt,
    Country::Pr,
    Country::Qa,
    Country::Ro,
    Country::Ru,
    Country::Sa,
    Country::Sn,
    Country::Rs,
    Country::Sg,
    Country::Sk,
    Country::Si,
    Country::Za,
    Country::Kr,
    Country::Es,
    Country::Lk,
    Country::Se,
    Country::Ch,
    Country::Tw,
    Country::Tz,
    Country::Th,
    Country::Tn,
    Country::Tr,
    Country::Ug,
    Country::Ua,
    Country::Ae,
    Country::Gb,
    Country::Us,
    Country::Uy,
    Country::Ve,
    Country::Vn,
    Country::Ye,
    Country::Zw,
];

impl Language {
    /// Get the native name of the language
    ///
    /// Examples: "English (US)", "Deutsch", "中文 (简体)"
    pub fn name(&self) -> &str {
        match self {
            Language::Af => "Afrikaans",
            Language::Am => "አማርኛ",
            Language::Ar => "العربية",
            Language::As => "অসমীয়া",
            Language::Az => "Azərbaycan",
            Language::Be => "Беларуская",
            Language::Bg => "Български",
            Language::Bn => "বাংলা",
            Language::Bs => "Bosanski",
            Language::Ca => "Català",
            Language::Cs => "Čeština",
            Language::Da => "Dansk",
            Language::De => "Deutsch",
            Language::El => "Ελληνικά",
            Language::En => "English (US)",
            Language::EnGb => "English (UK)",
            Language::EnIn => "English (India)",
            Language::Es => "Español (España)",
            Language::Es419 => "Español (Latinoamérica)",
            Language::EsUs => "Español (US)",
            Language::Et => "Eesti",
            Language::Eu => "Euskara",
            Language::Fa => "فارسی",
            Language::Fi => "Suomi",
            Language::Fil => "Filipino",
            Language::Fr => "Français",
            Language::FrCa => "Français (Canada)",
            Language::Gl => "Galego",
            Language::Gu => "ગુજરાતી",
            Language::Hi => "हिन्दी",
            Language::Hr => "Hrvatski",
            Language::Hu => "Magyar",
            Language::Hy => "Հայերեն",
            Language::Id => "Bahasa Indonesia",
            Language::Is => "Íslenska",
            Language::It => "Italiano",
            Language::Iw => "עברית",
            Language::Ja => "日本語",
            Language::Ka => "ქართული",
            Language::Kk => "Қазақ Тілі",
            Language::Km => "ខ្មែរ",
            Language::Kn => "ಕನ್ನಡ",
            Language::Ko => "한국어",
            Language::Ky => "Кыргызча",
            Language::Lo => "ລາວ",
            Language::Lt => "Lietuvių",
            Language::Lv => "Latviešu valoda",
            Language::Mk => "Македонски",
            Language::Ml => "മലയാളം",
            Language::Mn => "Монгол",
            Language::Mr => "मराठी",
            Language::Ms => "Bahasa Malaysia",
            Language::My => "ဗမာ",
            Language::Ne => "नेपाली",
            Language::Nl => "Nederlands",
            Language::No => "Norsk",
            Language::Or => "ଓଡ଼ିଆ",
            Language::Pa => "ਪੰਜਾਬੀ",
            Language::Pl => "Polski",
            Language::Pt => "Português (Brasil)",
            Language::PtPt => "Português",
            Language::Ro => "Română",
            Language::Ru => "Русский",
            Language::Si => "සිංහල",
            Language::Sk => "Slovenčina",
            Language::Sl => "Slovenščina",
            Language::Sq => "Shqip",
            Language::Sr => "Српски",
            Language::SrLatn => "Srpski",
            Language::Sv => "Svenska",
            Language::Sw => "Kiswahili",
            Language::Ta => "தமிழ்",
            Language::Te => "తెలుగు",
            Language::Th => "ภาษาไทย",
            Language::Tr => "Türkçe",
            Language::Uk => "Українська",
            Language::Ur => "اردو",
            Language::Uz => "O‘zbek",
            Language::Vi => "Tiếng Việt",
            Language::ZhCn => "中文 (简体)",
            Language::ZhHk => "中文 (香港)",
            Language::ZhTw => "中文 (繁體)",
            Language::Zu => "IsiZulu",
        }
    }
}

impl Country {
    /// Get the English name of the country
    ///
    /// Examples: "United States", "Germany"
    pub fn name(&self) -> &str {
        match self {
            Country::Ae => "United Arab Emirates",
            Country::Ar => "Argentina",
            Country::At => "Austria",
            Country::Au => "Australia",
            Country::Az => "Azerbaijan",
            Country::Ba => "Bosnia and Herzegovina",
            Country::Bd => "Bangladesh",
            Country::Be => "Belgium",
            Country::Bg => "Bulgaria",
            Country::Bh => "Bahrain",
            Country::Bo => "Bolivia",
            Country::Br => "Brazil",
            Country::By => "Belarus",
            Country::Ca => "Canada",
            Country::Ch => "Switzerland",
            Country::Cl => "Chile",
            Country::Co => "Colombia",
            Country::Cr => "Costa Rica",
            Country::Cy => "Cyprus",
            Country::Cz => "Czechia",
            Country::De => "Germany",
            Country::Dk => "Denmark",
            Country::Do => "Dominican Republic",
            Country::Dz => "Algeria",
            Country::Ec => "Ecuador",
            Country::Ee => "Estonia",
            Country::Eg => "Egypt",
            Country::Es => "Spain",
            Country::Fi => "Finland",
            Country::Fr => "France",
            Country::Gb => "United Kingdom",
            Country::Ge => "Georgia",
            Country::Gh => "Ghana",
            Country::Gr => "Greece",
            Country::Gt => "Guatemala",
            Country::Hk => "Hong Kong",
            Country::Hn => "Honduras",
            Country::Hr => "Croatia",
            Country::Hu => "Hungary",
            Country::Id => "Indonesia",
            Country::Ie => "Ireland",
            Country::Il => "Israel",
            Country::In => "India",
            Country::Iq => "Iraq",
            Country::Is => "Iceland",
            Country::It => "Italy",
            Country::Jm => "Jamaica",
            Country::Jo => "Jordan",
            Country::Jp => "Japan",
            Country::Ke => "Kenya",
            Country::Kh => "Cambodia",
            Country::Kr => "South Korea",
            Country::Kw => "Kuwait",
            Country::Kz => "Kazakhstan",
            Country::La => "Laos",
            Country::Lb => "Lebanon",
            Country::Li => "Liechtenstein",
            Country::Lk => "Sri Lanka",
            Country::Lt => "Lithuania",
            Country::Lu => "Luxembourg",
            Country::Lv => "Latvia",
            Country::Ly => "Libya",
            Country::Ma => "Morocco",
            Country::Me => "Montenegro",
            Country::Mk => "North Macedonia",
            Country::Mt => "Malta",
            Country::Mx => "Mexico",
            Country::My => "Malaysia",
            Country::Ng => "Nigeria",
            Country::Ni => "Nicaragua",
            Country::Nl => "Netherlands",
            Country::No => "Norway",
            Country::Np => "Nepal",
            Country::Nz => "New Zealand",
            Country::Om => "Oman",
            Country::Pa => "Panama",
            Country::Pe => "Peru",
            Country::Pg => "Papua New Guinea",
            Country::Ph => "Philippines",
            Country::Pk => "Pakistan",
            Country::Pl => "Poland",
            Country::Pr => "Puerto Rico",
            Country::Pt => "Portugal",
            Country::Py => "Paraguay",
            Country::Qa => "Qatar",
            Country::Ro => "Romania",
            Country::Rs => "Serbia",
            Country::Ru => "Russia",
            Country::Sa => "Saudi Arabia",
            Country::Se => "Sweden",
            Country::Sg => "Singapore",
            Country::Si => "Slovenia",
            Country::Sk => "Slovakia",
            Country::Sn => "Senegal",
            Country::Sv => "El Salvador",
            Country::Th => "Thailand",
            Country::Tn => "Tunisia",
            Country::Tr => "Turkey",
            Country::Tw => "Taiwan",
            Country::Tz => "Tanzania",
            Country::Ua => "Ukraine",
            Country::Ug => "Uganda",
            Country::Us => "United States",
            Country::Uy => "Uruguay",
            Country::Ve => "Venezuela",
            Country::Vn => "Vietnam",
            Country::Ye => "Yemen",
            Country::Za => "South Africa",
            Country::Zw => "Zimbabwe",
            Country::Zz => "Global",
        }
    }
}

impl FromStr for Language {
    type Err = Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let mut sub = s;
        loop {
            if let Ok(v) = serde_plain::from_str(sub) {
                return Ok(v);
            }
            match sub.rfind('-') {
                Some(pos) => {
                    sub = &sub[..pos];
                }
                None => return Err(Error::Other("could not parse language `{s}`".into())),
            }
        }
    }
}

serde_plain::derive_display_from_serialize!(Language);

serde_plain::derive_fromstr_from_deserialize!(Country, Error);
serde_plain::derive_display_from_serialize!(Country);
