use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Deserialize, Serialize, JsonSchema, Default, Clone)]
#[serde(rename_all = "lowercase")]
pub enum Country {
    #[default]
    UNKNOWN,
    AFG,
    ALA,
    ALB,
    DZA,
    ASM,
    AND,
    AGO,
    AIA,
    ATA,
    ATG,
    ARG,
    ARM,
    ABW,
    AUS,
    AUT,
    AZE,
    BHS,
    BHR,
    BGD,
    BRB,
    BLR,
    BEL,
    BLZ,
    BEN,
    BMU,
    BTN,
    BOL,
    BES,
    BIH,
    BWA,
    BVT,
    BRA,
    IOT,
    BRN,
    BGR,
    BFA,
    BDI,
    CPV,
    KHM,
    CMR,
    CAN,
    CYM,
    CAF,
    TCD,
    CHL,
    CHN,
    CXR,
    CCK,
    COL,
    COM,
    COG,
    COD,
    COK,
    CRI,
    CIV,
    HRV,
    CUB,
    CUW,
    CYP,
    CZE,
    DNK,
    DJI,
    DMA,
    DOM,
    ECU,
    EGY,
    SLV,
    GNQ,
    ERI,
    EST,
    SWZ,
    ETH,
    FLK,
    FRO,
    FJI,
    FIN,
    FRA,
    GUF,
    PYF,
    ATF,
    GAB,
    GMB,
    GEO,
    DEU,
    GHA,
    GIB,
    GRC,
    GRL,
    GRD,
    GLP,
    GUM,
    GTM,
    GGY,
    GIN,
    GNB,
    GUY,
    HTI,
    HMD,
    VAT,
    HND,
    HKG,
    HUN,
    ISL,
    IND,
    IDN,
    IRN,
    IRQ,
    IRL,
    IMN,
    ISR,
    ITA,
    JAM,
    JPN,
    JEY,
    JOR,
    KAZ,
    KEN,
    KIR,
    PRK,
    KOR,
    KWT,
    KGZ,
    LAO,
    LVA,
    LBN,
    LSO,
    LBR,
    LBY,
    LIE,
    LTU,
    LUX,
    MAC,
    MDG,
    MWI,
    MYS,
    MDV,
    MLI,
    MLT,
    MHL,
    MTQ,
    MRT,
    MUS,
    MYT,
    MEX,
    FSM,
    MDA,
    MCO,
    MNG,
    MNE,
    MSR,
    MAR,
    MOZ,
    MMR,
    NAM,
    NRU,
    NPL,
    NLD,
    NCL,
    NZL,
    NIC,
    NER,
    NGA,
    NIU,
    NFK,
    MKD,
    MNP,
    NOR,
    OMN,
    PAK,
    PLW,
    PSE,
    PAN,
    PNG,
    PRY,
    PER,
    PHL,
    PCN,
    POL,
    PRT,
    PRI,
    QAT,
    REU,
    ROU,
    RUS,
    RWA,
    BLM,
    SHN,
    KNA,
    LCA,
    MAF,
    SPM,
    VCT,
    WSM,
    SMR,
    STP,
    SAU,
    SEN,
    SRB,
    SYC,
    SLE,
    SGP,
    SXM,
    SVK,
    SVN,
    SLB,
    SOM,
    ZAF,
    SGS,
    SSD,
    ESP,
    LKA,
    SDN,
    SUR,
    SJM,
    SWE,
    CHE,
    SYR,
    TWN,
    TJK,
    TZA,
    THA,
    TLS,
    TGO,
    TKL,
    TON,
    TTO,
    TUN,
    TUR,
    TKM,
    TCA,
    TUV,
    UGA,
    UKR,
    ARE,
    GBR,
    USA,
    UMI,
    URY,
    UZB,
    VUT,
    VEN,
    VNM,
    VGB,
    VIR,
    WLF,
    ESH,
    YEM,
    ZMB,
    ZWE,
}

impl From<&str> for Country {
    fn from(value: &str) -> Self {
        match value.len() {
            2 => Country::_from_alpha2(value),
            3 => Country::_from_alpha3(value),
            _ => Country::UNKNOWN,
        }
    }
}

impl Country {
    fn _from_alpha2(value: &str) -> Self {
        match value.to_uppercase().as_str() {
            "AF" => Country::AFG,
            "AX" => Country::ALA,
            "AL" => Country::ALB,
            "DZ" => Country::DZA,
            "AS" => Country::ASM,
            "AD" => Country::AND,
            "AO" => Country::AGO,
            "AI" => Country::AIA,
            "AQ" => Country::ATA,
            "AG" => Country::ATG,
            "AR" => Country::ARG,
            "AM" => Country::ARM,
            "AW" => Country::ABW,
            "AU" => Country::AUS,
            "AT" => Country::AUT,
            "AZ" => Country::AZE,
            "BS" => Country::BHS,
            "BH" => Country::BHR,
            "BD" => Country::BGD,
            "BB" => Country::BRB,
            "BY" => Country::BLR,
            "BE" => Country::BEL,
            "BZ" => Country::BLZ,
            "BJ" => Country::BEN,
            "BM" => Country::BMU,
            "BT" => Country::BTN,
            "BO" => Country::BOL,
            "BQ" => Country::BES,
            "BA" => Country::BIH,
            "BW" => Country::BWA,
            "BV" => Country::BVT,
            "BR" => Country::BRA,
            "IO" => Country::IOT,
            "BN" => Country::BRN,
            "BG" => Country::BGR,
            "BF" => Country::BFA,
            "BI" => Country::BDI,
            "CV" => Country::CPV,
            "KH" => Country::KHM,
            "CM" => Country::CMR,
            "CA" => Country::CAN,
            "KY" => Country::CYM,
            "CF" => Country::CAF,
            "TD" => Country::TCD,
            "CL" => Country::CHL,
            "CN" => Country::CHN,
            "CX" => Country::CXR,
            "CC" => Country::CCK,
            "CO" => Country::COL,
            "KM" => Country::COM,
            "CG" => Country::COG,
            "CD" => Country::COD,
            "CK" => Country::COK,
            "CR" => Country::CRI,
            "CI" => Country::CIV,
            "HR" => Country::HRV,
            "CU" => Country::CUB,
            "CW" => Country::CUW,
            "CY" => Country::CYP,
            "CZ" => Country::CZE,
            "DK" => Country::DNK,
            "DJ" => Country::DJI,
            "DM" => Country::DMA,
            "DO" => Country::DOM,
            "EC" => Country::ECU,
            "EG" => Country::EGY,
            "SV" => Country::SLV,
            "GQ" => Country::GNQ,
            "ER" => Country::ERI,
            "EE" => Country::EST,
            "SZ" => Country::SWZ,
            "ET" => Country::ETH,
            "FK" => Country::FLK,
            "FO" => Country::FRO,
            "FJ" => Country::FJI,
            "FI" => Country::FIN,
            "FR" => Country::FRA,
            "GF" => Country::GUF,
            "PF" => Country::PYF,
            "TF" => Country::ATF,
            "GA" => Country::GAB,
            "GM" => Country::GMB,
            "GE" => Country::GEO,
            "DE" => Country::DEU,
            "GH" => Country::GHA,
            "GI" => Country::GIB,
            "GR" => Country::GRC,
            "GL" => Country::GRL,
            "GD" => Country::GRD,
            "GP" => Country::GLP,
            "GU" => Country::GUM,
            "GT" => Country::GTM,
            "GG" => Country::GGY,
            "GN" => Country::GIN,
            "GW" => Country::GNB,
            "GY" => Country::GUY,
            "HT" => Country::HTI,
            "HM" => Country::HMD,
            "VA" => Country::VAT,
            "HN" => Country::HND,
            "HK" => Country::HKG,
            "HU" => Country::HUN,
            "IS" => Country::ISL,
            "IN" => Country::IND,
            "ID" => Country::IDN,
            "IR" => Country::IRN,
            "IQ" => Country::IRQ,
            "IE" => Country::IRL,
            "IM" => Country::IMN,
            "IL" => Country::ISR,
            "IT" => Country::ITA,
            "JM" => Country::JAM,
            "JP" => Country::JPN,
            "JE" => Country::JEY,
            "JO" => Country::JOR,
            "KZ" => Country::KAZ,
            "KE" => Country::KEN,
            "KI" => Country::KIR,
            "KP" => Country::PRK,
            "KR" => Country::KOR,
            "KW" => Country::KWT,
            "KG" => Country::KGZ,
            "LA" => Country::LAO,
            "LV" => Country::LVA,
            "LB" => Country::LBN,
            "LS" => Country::LSO,
            "LR" => Country::LBR,
            "LY" => Country::LBY,
            "LI" => Country::LIE,
            "LT" => Country::LTU,
            "LU" => Country::LUX,
            "MO" => Country::MAC,
            "MG" => Country::MDG,
            "MW" => Country::MWI,
            "MY" => Country::MYS,
            "MV" => Country::MDV,
            "ML" => Country::MLI,
            "MT" => Country::MLT,
            "MH" => Country::MHL,
            "MQ" => Country::MTQ,
            "MR" => Country::MRT,
            "MU" => Country::MUS,
            "YT" => Country::MYT,
            "MX" => Country::MEX,
            "FM" => Country::FSM,
            "MD" => Country::MDA,
            "MC" => Country::MCO,
            "MN" => Country::MNG,
            "ME" => Country::MNE,
            "MS" => Country::MSR,
            "MA" => Country::MAR,
            "MZ" => Country::MOZ,
            "MM" => Country::MMR,
            "NA" => Country::NAM,
            "NR" => Country::NRU,
            "NP" => Country::NPL,
            "NL" => Country::NLD,
            "NC" => Country::NCL,
            "NZ" => Country::NZL,
            "NI" => Country::NIC,
            "NE" => Country::NER,
            "NG" => Country::NGA,
            "NU" => Country::NIU,
            "NF" => Country::NFK,
            "MK" => Country::MKD,
            "MP" => Country::MNP,
            "NO" => Country::NOR,
            "OM" => Country::OMN,
            "PK" => Country::PAK,
            "PW" => Country::PLW,
            "PS" => Country::PSE,
            "PA" => Country::PAN,
            "PG" => Country::PNG,
            "PY" => Country::PRY,
            "PE" => Country::PER,
            "PH" => Country::PHL,
            "PN" => Country::PCN,
            "PL" => Country::POL,
            "PT" => Country::PRT,
            "PR" => Country::PRI,
            "QT" => Country::QAT,
            "RE" => Country::REU,
            "RO" => Country::ROU,
            "RU" => Country::RUS,
            "RW" => Country::RWA,
            "BL" => Country::BLM,
            "SH" => Country::SHN,
            "KN" => Country::KNA,
            "LC" => Country::LCA,
            "MF" => Country::MAF,
            "PM" => Country::SPM,
            "VT" => Country::VCT,
            "WS" => Country::WSM,
            "SM" => Country::SMR,
            "ST" => Country::STP,
            "SA" => Country::SAU,
            "SN" => Country::SEN,
            "RS" => Country::SRB,
            "SC" => Country::SYC,
            "SL" => Country::SLE,
            "SG" => Country::SGP,
            "SX" => Country::SXM,
            "SK" => Country::SVK,
            "SI" => Country::SVN,
            "SB" => Country::SLB,
            "SO" => Country::SOM,
            "ZA" => Country::ZAF,
            "GS" => Country::SGS,
            "SS" => Country::SSD,
            "ES" => Country::ESP,
            "LK" => Country::LKA,
            "SD" => Country::SDN,
            "SR" => Country::SUR,
            "SJ" => Country::SJM,
            "SE" => Country::SWE,
            "CH" => Country::CHE,
            "SY" => Country::SYR,
            "TW" => Country::TWN,
            "TJ" => Country::TJK,
            "TZ" => Country::TZA,
            "TH" => Country::THA,
            "TL" => Country::TLS,
            "TG" => Country::TGO,
            "TK" => Country::TKL,
            "TO" => Country::TON,
            "TT" => Country::TTO,
            "TN" => Country::TUN,
            "TR" => Country::TUR,
            "TM" => Country::TKM,
            "TC" => Country::TCA,
            "TV" => Country::TUV,
            "UG" => Country::UGA,
            "UA" => Country::UKR,
            "AE" => Country::ARE,
            "GB" => Country::GBR,
            "US" => Country::USA,
            "UM" => Country::UMI,
            "UY" => Country::URY,
            "UZ" => Country::UZB,
            "VU" => Country::VUT,
            "VE" => Country::VEN,
            "VN" => Country::VNM,
            "VB" => Country::VGB,
            "VI" => Country::VIR,
            "WF" => Country::WLF,
            "EH" => Country::ESH,
            "YE" => Country::YEM,
            "ZM" => Country::ZMB,
            "ZW" => Country::ZWE,
            _ => Country::UNKNOWN,
        }
    }
    fn _from_alpha3(value: &str) -> Self {
        match value.to_uppercase().as_str() {
            "AFG" => Country::AFG,
            "ALA" => Country::ALA,
            "ALB" => Country::ALB,
            "DZA" => Country::DZA,
            "ASM" => Country::ASM,
            "AND" => Country::AND,
            "AGO" => Country::AGO,
            "AIA" => Country::AIA,
            "ATA" => Country::ATA,
            "ATG" => Country::ATG,
            "ARG" => Country::ARG,
            "ARM" => Country::ARM,
            "ABW" => Country::ABW,
            "AUS" => Country::AUS,
            "AUT" => Country::AUT,
            "AZE" => Country::AZE,
            "BHS" => Country::BHS,
            "BHR" => Country::BHR,
            "BGD" => Country::BGD,
            "BRB" => Country::BRB,
            "BLR" => Country::BLR,
            "BEL" => Country::BEL,
            "BLZ" => Country::BLZ,
            "BEN" => Country::BEN,
            "BMU" => Country::BMU,
            "BTN" => Country::BTN,
            "BOL" => Country::BOL,
            "BES" => Country::BES,
            "BIH" => Country::BIH,
            "BWA" => Country::BWA,
            "BVT" => Country::BVT,
            "BRA" => Country::BRA,
            "IOT" => Country::IOT,
            "BRN" => Country::BRN,
            "BGR" => Country::BGR,
            "BFA" => Country::BFA,
            "BDI" => Country::BDI,
            "CPV" => Country::CPV,
            "KHM" => Country::KHM,
            "CMR" => Country::CMR,
            "CAN" => Country::CAN,
            "CYM" => Country::CYM,
            "CAF" => Country::CAF,
            "TCD" => Country::TCD,
            "CHL" => Country::CHL,
            "CHN" => Country::CHN,
            "CXR" => Country::CXR,
            "CCK" => Country::CCK,
            "COL" => Country::COL,
            "COM" => Country::COM,
            "COG" => Country::COG,
            "COD" => Country::COD,
            "COK" => Country::COK,
            "CRI" => Country::CRI,
            "CIV" => Country::CIV,
            "HRV" => Country::HRV,
            "CUB" => Country::CUB,
            "CUW" => Country::CUW,
            "CYP" => Country::CYP,
            "CZE" => Country::CZE,
            "DNK" => Country::DNK,
            "DJI" => Country::DJI,
            "DMA" => Country::DMA,
            "DOM" => Country::DOM,
            "ECU" => Country::ECU,
            "EGY" => Country::EGY,
            "SLV" => Country::SLV,
            "GNQ" => Country::GNQ,
            "ERI" => Country::ERI,
            "EST" => Country::EST,
            "SWZ" => Country::SWZ,
            "ETH" => Country::ETH,
            "FLK" => Country::FLK,
            "FRO" => Country::FRO,
            "FJI" => Country::FJI,
            "FIN" => Country::FIN,
            "FRA" => Country::FRA,
            "GUF" => Country::GUF,
            "PYF" => Country::PYF,
            "ATF" => Country::ATF,
            "GAB" => Country::GAB,
            "GMB" => Country::GMB,
            "GEO" => Country::GEO,
            "DEU" => Country::DEU,
            "GHA" => Country::GHA,
            "GIB" => Country::GIB,
            "GRC" => Country::GRC,
            "GRL" => Country::GRL,
            "GRD" => Country::GRD,
            "GLP" => Country::GLP,
            "GUM" => Country::GUM,
            "GTM" => Country::GTM,
            "GGY" => Country::GGY,
            "GIN" => Country::GIN,
            "GNB" => Country::GNB,
            "GUY" => Country::GUY,
            "HTI" => Country::HTI,
            "HMD" => Country::HMD,
            "VAT" => Country::VAT,
            "HND" => Country::HND,
            "HKG" => Country::HKG,
            "HUN" => Country::HUN,
            "ISL" => Country::ISL,
            "IND" => Country::IND,
            "IDN" => Country::IDN,
            "IRN" => Country::IRN,
            "IRQ" => Country::IRQ,
            "IRL" => Country::IRL,
            "IMN" => Country::IMN,
            "ISR" => Country::ISR,
            "ITA" => Country::ITA,
            "JAM" => Country::JAM,
            "JPN" => Country::JPN,
            "JEY" => Country::JEY,
            "JOR" => Country::JOR,
            "KAZ" => Country::KAZ,
            "KEN" => Country::KEN,
            "KIR" => Country::KIR,
            "PRK" => Country::PRK,
            "KOR" => Country::KOR,
            "KWT" => Country::KWT,
            "KGZ" => Country::KGZ,
            "LAO" => Country::LAO,
            "LVA" => Country::LVA,
            "LBN" => Country::LBN,
            "LSO" => Country::LSO,
            "LBR" => Country::LBR,
            "LBY" => Country::LBY,
            "LIE" => Country::LIE,
            "LTU" => Country::LTU,
            "LUX" => Country::LUX,
            "MAC" => Country::MAC,
            "MDG" => Country::MDG,
            "MWI" => Country::MWI,
            "MYS" => Country::MYS,
            "MDV" => Country::MDV,
            "MLI" => Country::MLI,
            "MLT" => Country::MLT,
            "MHL" => Country::MHL,
            "MTQ" => Country::MTQ,
            "MRT" => Country::MRT,
            "MUS" => Country::MUS,
            "MYT" => Country::MYT,
            "MEX" => Country::MEX,
            "FSM" => Country::FSM,
            "MDA" => Country::MDA,
            "MCO" => Country::MCO,
            "MNG" => Country::MNG,
            "MNE" => Country::MNE,
            "MSR" => Country::MSR,
            "MAR" => Country::MAR,
            "MOZ" => Country::MOZ,
            "MMR" => Country::MMR,
            "NAM" => Country::NAM,
            "NRU" => Country::NRU,
            "NPL" => Country::NPL,
            "NLD" => Country::NLD,
            "NCL" => Country::NCL,
            "NZL" => Country::NZL,
            "NIC" => Country::NIC,
            "NER" => Country::NER,
            "NGA" => Country::NGA,
            "NIU" => Country::NIU,
            "NFK" => Country::NFK,
            "MKD" => Country::MKD,
            "MNP" => Country::MNP,
            "NOR" => Country::NOR,
            "OMN" => Country::OMN,
            "PAK" => Country::PAK,
            "PLW" => Country::PLW,
            "PSE" => Country::PSE,
            "PAN" => Country::PAN,
            "PNG" => Country::PNG,
            "PRY" => Country::PRY,
            "PER" => Country::PER,
            "PHL" => Country::PHL,
            "PCN" => Country::PCN,
            "POL" => Country::POL,
            "PRT" => Country::PRT,
            "PRI" => Country::PRI,
            "QAT" => Country::QAT,
            "REU" => Country::REU,
            "ROU" => Country::ROU,
            "RUS" => Country::RUS,
            "RWA" => Country::RWA,
            "BLM" => Country::BLM,
            "SHN" => Country::SHN,
            "KNA" => Country::KNA,
            "LCA" => Country::LCA,
            "MAF" => Country::MAF,
            "SPM" => Country::SPM,
            "VCT" => Country::VCT,
            "WSM" => Country::WSM,
            "SMR" => Country::SMR,
            "STP" => Country::STP,
            "SAU" => Country::SAU,
            "SEN" => Country::SEN,
            "SRB" => Country::SRB,
            "SYC" => Country::SYC,
            "SLE" => Country::SLE,
            "SGP" => Country::SGP,
            "SXM" => Country::SXM,
            "SVK" => Country::SVK,
            "SVN" => Country::SVN,
            "SLB" => Country::SLB,
            "SOM" => Country::SOM,
            "ZAF" => Country::ZAF,
            "SGS" => Country::SGS,
            "SSD" => Country::SSD,
            "ESP" => Country::ESP,
            "LKA" => Country::LKA,
            "SDN" => Country::SDN,
            "SUR" => Country::SUR,
            "SJM" => Country::SJM,
            "SWE" => Country::SWE,
            "CHE" => Country::CHE,
            "SYR" => Country::SYR,
            "TWN" => Country::TWN,
            "TJK" => Country::TJK,
            "TZA" => Country::TZA,
            "THA" => Country::THA,
            "TLS" => Country::TLS,
            "TGO" => Country::TGO,
            "TKL" => Country::TKL,
            "TON" => Country::TON,
            "TTO" => Country::TTO,
            "TUN" => Country::TUN,
            "TUR" => Country::TUR,
            "TKM" => Country::TKM,
            "TCA" => Country::TCA,
            "TUV" => Country::TUV,
            "UGA" => Country::UGA,
            "UKR" => Country::UKR,
            "ARE" => Country::ARE,
            "GBR" => Country::GBR,
            "USA" => Country::USA,
            "UMI" => Country::UMI,
            "URY" => Country::URY,
            "UZB" => Country::UZB,
            "VUT" => Country::VUT,
            "VEN" => Country::VEN,
            "VNM" => Country::VNM,
            "VGB" => Country::VGB,
            "VIR" => Country::VIR,
            "WLF" => Country::WLF,
            "ESH" => Country::ESH,
            "YEM" => Country::YEM,
            "ZMB" => Country::ZMB,
            "ZWE" => Country::ZWE,
            _ => Country::UNKNOWN,
        }
    }
}
