package org.jeecg.modules.adweb.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author wfansh
 */
@Getter
@AllArgsConstructor
public enum CountryCode {
    AD("AD", "Andorra", "安道尔"),
    AE("AE", "United Arab Emirates", "阿拉伯联合酋长国"),
    AF("AF", "Afghanistan", "阿富汗"),
    AG("AG", "Antigua and Barbuda", "安提瓜和巴布达"),
    AI("AI", "Anguilla", "安圭拉"),
    AL("AL", "Albania", "阿尔巴尼亚"),
    AM("AM", "Armenia", "亚美尼亚"),
    AO("AO", "Angola", "安哥拉"),
    AQ("AQ", "Antarctica", "南极洲"),
    AR("AR", "Argentina", "阿根廷"),
    AS("AS", "American Samoa", "美属萨摩亚"),
    AT("AT", "Austria", "奥地利"),
    AU("AU", "Australia", "澳大利亚"),
    AW("AW", "Aruba", "阿鲁巴"),
    AX("AX", "Åland Islands", "奥兰群岛"),
    AZ("AZ", "Azerbaijan", "阿塞拜疆"),
    BA("BA", "Bosnia & Herzegovina", "波斯尼亚和黑山共和国"),
    BB("BB", "Barbados", "巴巴多斯"),
    BD("BD", "Bangladesh", "孟加拉"),
    BE("BE", "Belgium", "比利时"),
    BF("BF", "Burkina Faso", "布基纳法索"),
    BG("BG", "Bulgaria", "保加利亚"),
    BH("BH", "Bahrain", "巴林"),
    BI("BI", "Burundi", "布隆迪"),
    BJ("BJ", "Benin", "贝宁"),
    BL("BL", "Saint Barthélemy", "圣巴泰勒米"),
    BM("BM", "Bermuda", "百慕大"),
    BN("BN", "Brunei darussalam", "文莱"),
    BO("BO", "Bolivia", "玻利维亚"),
    BQ("BQ", "Bonaire, Sint Eustatius and Saba", "博奈尔岛、圣尤斯达蒂斯和萨巴"),
    BR("BR", "Brazil", "巴西"),
    BS("BS", "Bahamas", "巴哈马"),
    BT("BT", "Bhutan", "不丹"),
    BV("BV", "Bouvet Island", "布维特岛"),
    BW("BW", "Botswana", "博茨瓦纳"),
    BY("BY", "Belarus", "白俄罗斯"),
    BZ("BZ", "Belize", "伯利兹"),
    CA("CA", "Canada", "加拿大"),
    CC("CC", "Cocos (Keeling) Islands", "科科斯群岛"),
    CD("CD", "Congo Democratic Rep.", "刚果（金）"),
    CF("CF", "Central African Republic", "中非共和国"),
    CG("CG", "Congo - Brazzaville", "刚果（布）"),
    CH("CH", "Switzerland", "瑞士"),
    CI("CI", "Côte d’Ivoire", "科特迪瓦"),
    CK("CK", "Cook Islands", "库克群岛"),
    CL("CL", "Chile", "智利"),
    CM("CM", "Cameroon", "喀麦隆"),
    CN("CN", "China", "中国"),
    CO("CO", "Colombia", "哥伦比亚"),
    CR("CR", "Costa Rica", "哥斯达黎加"),
    CU("CU", "Cuba", "古巴"),
    CV("CV", "Cape Verde", "佛得角"),
    CW("CW", "Curaçao", "库拉索"),
    CX("CX", "Christmas Island", "圣诞岛"),
    CY("CY", "Cyprus", "塞浦路斯"),
    CZ("CZ", "Czechia", "捷克"),
    DE("DE", "Germany", "德国"),
    DJ("DJ", "Djibouti", "吉布提"),
    DK("DK", "Denmark", "丹麦"),
    DM("DM", "Dominica", "多米尼加"),
    DO("DO", "Dominican Republic", "多米尼加共和国"),
    DZ("DZ", "Algeria", "阿尔及利亚"),
    EC("EC", "Ecuador", "厄瓜多尔"),
    EE("EE", "Estonia", "爱沙尼亚"),
    EG("EG", "Egypt", "埃及"),
    EH("EH", "Western Sahara", "西撒哈拉"),
    ER("ER", "Eritrea", "厄立特里亚"),
    ES("ES", "Spain", "西班牙"),
    ET("ET", "Ethiopia", "埃塞俄比亚"),
    FI("FI", "Finland", "芬兰"),
    FJ("FJ", "Fiji", "斐济"),
    FK("FK", "Falkland Islands (Malvinas)", "福克兰群岛"),
    FM("FM", "Micronesia", "密克罗尼西亚"),
    FO("FO", "Faroe Islands", "法罗群岛"),
    FR("FR", "France", "法国"),
    GA("GA", "Gabon", "加蓬"),
    GB("GB", "United Kingdom", "英国"),
    GD("GD", "Grenada", "格林纳达"),
    GE("GE", "Georgia", "格鲁吉亚"),
    GF("GF", "French Guiana", "法属圭亚那"),
    GG("GG", "Guernsey", "格恩西岛"),
    GH("GH", "Ghana", "加纳"),
    GI("GI", "Gibraltar", "直布罗陀"),
    GL("GL", "Greenland", "格陵兰"),
    GM("GM", "Gambia", "冈比亚"),
    GN("GN", "Guinea", "几内亚"),
    GP("GP", "Guadeloupe", "瓜德罗普岛"),
    GQ("GQ", "Equatorial Guinea", "赤道几内亚"),
    GR("GR", "Greece", "希腊"),
    GS("GS", "South Georgia and the South Sandwich Islands", "南乔治亚岛和南桑威齐群岛"),
    GT("GT", "Guatemala", "危地马拉"),
    GU("GU", "Guam", "关岛"),
    GW("GW", "Guinea-Bissau", "几内亚比绍"),
    GY("GY", "Guyana", "圭亚那"),
    HK("HK", "Hong Kong", "中国香港"),
    HM("HM", "Heard Island and McDonald Islands", "赫德与麦克唐纳群岛"),
    HN("HN", "Honduras", "洪都拉斯"),
    HR("HR", "Croatia", "克罗地亚"),
    HT("HT", "Haiti", "海地"),
    HU("HU", "Hungary", "匈牙利"),
    ID("ID", "Indonesia", "印度尼西亚"),
    IE("IE", "Ireland", "爱尔兰"),
    IL("IL", "Israel", "以色列"),
    IM("IM", "Isle of Man", "曼岛"),
    IN("IN", "India", "印度"),
    IO("IO", "British Indian Ocean Territory", "英属印度洋领地"),
    IQ("IQ", "Iraq", "伊拉克"),
    IR("IR", "Iran", "伊朗伊斯兰共和国"),
    IS("IS", "Iceland", "冰岛"),
    IT("IT", "Italy", "意大利"),
    JE("JE", "Jersey", "泽西岛"),
    JM("JM", "Jamaica", "牙买加"),
    JO("JO", "Jordan", "约旦"),
    JP("JP", "Japan", "日本"),
    KE("KE", "Kenya", "肯尼亚"),
    KG("KG", "Kyrgyzstan", "吉尔吉克斯坦"),
    KH("KH", "Cambodia", "柬埔寨"),
    KI("KI", "Kiribati", "基里巴斯"),
    KM("KM", "Comoros", "科摩罗"),
    KN("KN", "St Kitts and Nevis", "圣基茨和尼维斯"),
    KP("KP", "Korea Democratic Rep.", "朝鲜民主共和国"),
    KR("KR", "South Korea", "大韩民国"),
    KW("KW", "Kuwait", "科威特"),
    KY("KY", "Cayman Islands", "开曼群岛"),
    KZ("KZ", "Kazakhstan", "哈萨克斯坦"),
    LA("LA", "Laos", "老挝"),
    LB("LB", "Lebanon", "黎巴嫩"),
    LC("LC", "Saint Lucia", "圣卢西亚"),
    LI("LI", "Liechtenstein", "列支敦士登"),
    LK("LK", "Sri Lanka", "斯里兰卡"),
    LR("LR", "Liberia", "利比里亚"),
    LS("LS", "Lesotho", "莱索托"),
    LT("LT", "Lithuania", "立陶宛"),
    LU("LU", "Luxembourg", "卢森堡"),
    LV("LV", "Latvia", "拉脱维亚"),
    LY("LY", "Libya", "阿拉伯利比亚民众国"),
    MA("MA", "Morocco", "摩洛哥"),
    MC("MC", "Monaco", "摩纳哥"),
    MD("MD", "Moldova", "摩尔多瓦共和国"),
    ME("ME", "Montenegro", "黑山共和国"),
    MF("MF", "Saint Martin (French part)", "圣马丁"),
    MG("MG", "Madagascar", "马达加斯加"),
    MH("MH", "Marshall Islands", "马绍尔群岛"),
    MK("MK", "North Macedonia", "北马其顿"),
    ML("ML", "Mali", "马里"),
    MM("MM", "Myanmar (Burma)", "缅甸"),
    MN("MN", "Mongolia", "蒙古"),
    MO("MO", "Macau", "中国澳门"),
    MP("MP", "Northern Mariana Islands", "北马里亚纳群岛"),
    MQ("MQ", "Martinique", "马提尼克群岛"),
    MR("MR", "Mauritania", "毛里塔尼亚"),
    MS("MS", "Montserrat", "蒙塞拉特群岛"),
    MT("MT", "Malta", "马耳他"),
    MU("MU", "Mauritius", "毛里求斯"),
    MV("MV", "Maldives", "马尔代夫"),
    MW("MW", "Malawi", "马拉维"),
    MX("MX", "Mexico", "墨西哥"),
    MY("MY", "Malaysia", "马来西亚"),
    MZ("MZ", "Mozambique", "莫桑比克"),
    NA("NA", "Namibia", "纳米比亚"),
    NC("NC", "New Caledonia", "新喀里多尼亚"),
    NE("NE", "Niger", "尼日尔"),
    NF("NF", "Norfolk Island", "诺福克岛"),
    NG("NG", "Nigeria", "尼日利亚"),
    NI("NI", "Nicaragua", "尼加拉瓜"),
    NL("NL", "Netherlands", "荷兰"),
    NO("NO", "Norway", "挪威"),
    NP("NP", "Nepal", "尼泊尔"),
    NR("NR", "Nauru", "瑙鲁"),
    NU("NU", "Niue", "纽埃"),
    NZ("NZ", "New Zealand", "新西兰"),
    OM("OM", "Oman", "阿曼"),
    PA("PA", "Panama", "巴拿马"),
    PE("PE", "Peru", "秘鲁"),
    PF("PF", "French Polynesia", "法属波利尼西亚"),
    PG("PG", "Papua New Guinea", "巴布亚新几内亚"),
    PH("PH", "Philippines", "菲律宾"),
    PK("PK", "Pakistan", "巴基斯坦"),
    PL("PL", "Poland", "波兰"),
    PM("PM", "Saint Pierre and Miquelon", "圣皮埃尔和密克隆"),
    PN("PN", "Pitcairn", "皮特凯恩群岛"),
    PR("PR", "Puerto Rico", "波多黎各"),
    PSE("PSE", "Palestine", "巴勒斯坦"),
    PT("PT", "Portugal", "葡萄牙"),
    PW("PW", "Palau", "帕劳"),
    PY("PY", "Paraguay", "巴拉圭"),
    QA("QA", "Qatar", "卡塔尔"),
    RE("RE", "Reunion", "留尼汪"),
    RO("RO", "Romania", "罗马尼亚"),
    RS("RS", "Serbia", "塞尔维亚"),
    RU("RU", "Russia", "俄罗斯"),
    RW("RW", "Rwanda", "卢旺达"),
    SA("SA", "Saudi Arabia", "沙特阿拉伯"),
    SB("SB", "Solomon Islands", "所罗门群岛"),
    SC("SC", "Seychelles", "塞舌尔群岛"),
    SD("SD", "Sudan", "苏丹"),
    SE("SE", "Sweden", "瑞典"),
    SG("SG", "Singapore", "新加坡"),
    SH("SH", "Saint Helena, Ascension and Tristan da Cunha", "圣赫勒拿"),
    SI("SI", "Slovenia", "斯洛文尼亚"),
    SJ("SJ", "Svalbard and Jan Mayen", "斯瓦尔巴特和扬马延"),
    SK("SK", "Slovakia", "斯洛伐克共和国"),
    SL("SL", "Sierra Leone", "塞拉利昂"),
    SM("SM", "San Marino", "圣马力诺"),
    SN("SN", "Senegal", "塞内加尔"),
    SO("SO", "Somalia", "索马里"),
    SR("SR", "Suriname", "苏里南"),
    SS("SS", "South Sudan", "南苏丹"),
    ST("ST", "Sao-Tome and Principe", "圣多美和普林西比"),
    SV("SV", "El Salvador", "萨尔瓦多"),
    SX("SX", "Sint Maarten (Dutch part)", "圣马丁岛"),
    SY("SY", "Syria", "叙利亚"),
    SZ("SZ", "Eswatini", "斯威士兰"),
    TC("TC", "Turks and Caicos Islands", "特克斯和凯科斯群岛"),
    TD("TD", "Chad", "乍得"),
    TF("TF", "French Southern Territories", "法属南部领土"),
    TG("TG", "Togo", "多哥"),
    TH("TH", "Thailand", "泰国"),
    TJ("TJ", "Tajikistan", "塔吉克斯坦"),
    TK("TK", "Tokelau", "托克劳"),
    TL("TL", "Timor Leste", "东帝汶"),
    TM("TM", "Turkmenistan", "土库曼斯坦"),
    TN("TN", "Tunisia", "突尼斯"),
    TO("TO", "Tonga", "汤加"),
    TR("TR", "Turkey", "土耳其"),
    TT("TT", "Trinidad & Tobago", "特立尼达和多巴哥"),
    TV("TV", "Tuvalu", "图瓦卢"),
    TW("TW", "Taiwan", "中国台湾"),
    TZ("TZ", "Tanzania", "坦桑尼亚"),
    UA("UA", "Ukraine", "乌克兰"),
    UG("UG", "Uganda", "乌干达"),
    UM("UM", "United States Minor Outlying Islands", "美国边远小岛"),
    US("US", "United States", "美国"),
    UY("UY", "Uruguay", "乌拉圭"),
    UZ("UZ", "Uzbekistan", "乌兹别克斯坦"),
    VA("VA", "Vatican City State", "圣座（梵蒂冈）"),
    VC("VC", "St Vincent", "圣文森特和格林纳丁斯"),
    VE("VE", "Venezuela", "委内瑞拉"),
    VG("VG", "Virgin islands British", "英属维京群岛"),
    VI("VI", "Virgin Island U.S.", "美属维京群岛"),
    VN("VN", "Vietnam", "越南"),
    VU("VU", "Vanuatu", "瓦努阿图"),
    WF("WF", "Wallis and Futuna", "瓦利斯和富图纳"),
    WS("WS", "Samoa", "萨摩亚"),
    XK("XK", "Kosovo", "科索沃"),
    YE("YE", "Yemen", "也门"),
    YT("YT", "Mayotte", "马约特"),
    ZA("ZA", "South Africa", "南非"),
    ZM("ZM", "Zambia", "赞比亚"),
    ZW("ZW", "Zimbabwe", "津巴布韦"),

    // Unknown
    UNK("UNK", "UNKNOWN", "未知");

    private static final Map<String, CountryCode> CODE_MAP =
            Stream.of(CountryCode.values())
                    .collect(Collectors.toMap(CountryCode::getCode, Function.identity()));

    private static final Map<String, CountryCode> NAME_MAP =
            Stream.of(CountryCode.values())
                    .collect(Collectors.toMap(CountryCode::getName, Function.identity()));

    public static CountryCode valueOfCode(String code) {
        return CODE_MAP.getOrDefault(code, UNK);
    }

    public static CountryCode valueOfName(String name) {
        return NAME_MAP.getOrDefault(name, UNK);
    }

    private final String code;
    private final String name;
    private final String cnName;
}
