import pytest

from notifications_utils.countries import Country, CountryNotFoundError


def _country_not_found(*test_case):
    return pytest.param(
        *test_case,
        marks=pytest.mark.xfail(raises=CountryNotFoundError),
    )


@pytest.mark.parametrize(
    ("alpha_2", "expected_name"),
    [
        ("AF", "Afghanistan"),
        ("AL", "Albania"),
        ("DZ", "Algeria"),
        ("AS", "American Samoa"),
        ("AD", "Andorra"),
        ("AO", "Angola"),
        ("AI", "Anguilla"),
        ("AQ", "Antarctica"),
        ("AG", "Antigua and Barbuda"),
        ("AR", "Argentina"),
        ("AM", "Armenia"),
        ("AW", "Aruba"),
        ("AU", "Australia"),
        ("AT", "Austria"),
        ("AZ", "Azerbaijan"),
        ("BS", "The Bahamas"),
        ("BH", "Bahrain"),
        ("BD", "Bangladesh"),
        ("BB", "Barbados"),
        ("BY", "Belarus"),
        ("BE", "Belgium"),
        ("BZ", "Belize"),
        ("BJ", "Benin"),
        ("BM", "Bermuda"),
        ("BT", "Bhutan"),
        ("BO", "Bolivia"),
        _country_not_found("BQ", "Bonaire, Sint Eustatius and Saba"),
        ("BA", "Bosnia and Herzegovina"),
        ("BW", "Botswana"),
        ("BV", "Bouvet Island"),
        ("BR", "Brazil"),
        ("IO", "British Indian Ocean Territory"),
        ("BN", "Brunei"),
        ("BG", "Bulgaria"),
        ("BF", "Burkina Faso"),
        ("BI", "Burundi"),
        ("CV", "Cape Verde"),
        ("KH", "Cambodia"),
        ("CM", "Cameroon"),
        ("CA", "Canada"),
        ("KY", "Cayman Islands"),
        ("CF", "Central African Republic"),
        ("TD", "Chad"),
        ("CL", "Chile"),
        ("CN", "China"),
        ("CX", "Christmas Island"),
        ("CC", "Cocos (Keeling) Islands"),
        ("CO", "Colombia"),
        ("KM", "Comoros"),
        ("CD", "Congo (Democratic Republic)"),
        ("CG", "Congo"),
        ("CK", "Cook Islands"),
        ("CR", "Costa Rica"),
        ("HR", "Croatia"),
        ("CU", "Cuba"),
        ("CW", "Curaçao"),
        ("CY", "Cyprus"),
        ("CZ", "Czechia"),
        ("CI", "Ivory Coast"),
        ("DK", "Denmark"),
        ("DJ", "Djibouti"),
        ("DM", "Dominica"),
        ("DO", "Dominican Republic"),
        ("EC", "Ecuador"),
        ("EG", "Egypt"),
        ("SV", "El Salvador"),
        ("GQ", "Equatorial Guinea"),
        ("ER", "Eritrea"),
        ("EE", "Estonia"),
        ("SZ", "Eswatini"),
        ("ET", "Ethiopia"),
        ("FK", "Falkland Islands"),
        ("FO", "Faroe Islands"),
        ("FJ", "Fiji"),
        ("FI", "Finland"),
        ("FR", "France"),
        ("GF", "French Guiana"),
        ("PF", "French Polynesia"),
        ("TF", "French Southern Territories"),
        ("GA", "Gabon"),
        ("GM", "The Gambia"),
        ("GE", "Georgia"),
        ("DE", "Germany"),
        ("GH", "Ghana"),
        ("GI", "Gibraltar"),
        ("GR", "Greece"),
        ("GL", "Greenland"),
        ("GD", "Grenada"),
        ("GP", "Guadeloupe"),
        ("GU", "Guam"),
        ("GT", "Guatemala"),
        ("GG", "United Kingdom"),
        ("GN", "Guinea"),
        ("GW", "Guinea-Bissau"),
        ("GY", "Guyana"),
        ("HT", "Haiti"),
        ("HM", "Heard Island and McDonald Islands"),
        ("VA", "Vatican City"),
        ("HN", "Honduras"),
        ("HK", "Hong Kong"),
        ("HU", "Hungary"),
        ("IS", "Iceland"),
        ("IN", "India"),
        ("ID", "Indonesia"),
        ("IR", "Iran"),
        ("IQ", "Iraq"),
        ("IE", "Ireland"),
        ("IM", "United Kingdom"),
        ("IL", "Israel"),
        ("IT", "Italy"),
        ("JM", "Jamaica"),
        ("JP", "Japan"),
        ("JE", "United Kingdom"),
        ("JO", "Jordan"),
        ("KZ", "Kazakhstan"),
        ("KE", "Kenya"),
        ("KI", "Kiribati"),
        ("KP", "North Korea"),
        ("KR", "South Korea"),
        ("KW", "Kuwait"),
        ("KG", "Kyrgyzstan"),
        ("LA", "Laos"),
        ("LV", "Latvia"),
        ("LB", "Lebanon"),
        ("LS", "Lesotho"),
        ("LR", "Liberia"),
        ("LY", "Libya"),
        ("LI", "Liechtenstein"),
        ("LT", "Lithuania"),
        ("LU", "Luxembourg"),
        ("MO", "Macao"),
        ("MG", "Madagascar"),
        ("MW", "Malawi"),
        ("MY", "Malaysia"),
        ("MV", "Maldives"),
        ("ML", "Mali"),
        ("MT", "Malta"),
        ("MH", "Marshall Islands"),
        ("MQ", "Martinique"),
        ("MR", "Mauritania"),
        ("MU", "Mauritius"),
        ("YT", "Mayotte"),
        ("MX", "Mexico"),
        ("FM", "Micronesia"),
        ("MD", "Moldova"),
        ("MC", "Monaco"),
        ("MN", "Mongolia"),
        ("ME", "Montenegro"),
        ("MS", "Montserrat"),
        ("MA", "Morocco"),
        ("MZ", "Mozambique"),
        ("MM", "Myanmar (Burma)"),
        ("NA", "Namibia"),
        ("NR", "Nauru"),
        ("NP", "Nepal"),
        ("NL", "Netherlands"),
        ("NC", "New Caledonia"),
        ("NZ", "New Zealand"),
        ("NI", "United Kingdom"),  # NI gets interpreted as ‘Northern Ireland’
        ("NE", "Niger"),
        ("NG", "Nigeria"),
        ("NU", "Niue"),
        ("NF", "Norfolk Island"),
        ("MK", "North Macedonia"),
        ("MP", "Northern Mariana Islands"),
        ("NO", "Norway"),
        ("OM", "Oman"),
        ("PK", "Pakistan"),
        ("PW", "Palau"),
        ("PS", "Occupied Palestinian Territories"),
        ("PA", "Panama"),
        ("PG", "Papua New Guinea"),
        ("PY", "Paraguay"),
        ("PE", "Peru"),
        ("PH", "Philippines"),
        ("PN", "Pitcairn, Henderson, Ducie and Oeno Islands"),
        ("PL", "Poland"),
        ("PT", "Portugal"),
        ("PR", "Puerto Rico"),
        ("QA", "Qatar"),
        ("RO", "Romania"),
        ("RU", "Russia"),
        ("RW", "Rwanda"),
        ("RE", "Réunion"),
        ("BL", "Saint Barthélemy"),
        _country_not_found("SH", "Saint Helena, Ascension and Tristan da Cunha"),
        ("KN", "St Kitts and Nevis"),
        ("LC", "St Lucia"),
        ("MF", "Saint-Martin (French part)"),
        ("PM", "Saint Pierre and Miquelon"),
        ("VC", "St Vincent"),
        ("WS", "Samoa"),
        ("SM", "San Marino"),
        ("ST", "Sao Tome and Principe"),
        ("SA", "Saudi Arabia"),
        ("SN", "Senegal"),
        ("RS", "Serbia"),
        ("SC", "Seychelles"),
        ("SL", "Sierra Leone"),
        ("SG", "Singapore"),
        ("SX", "Sint Maarten (Dutch part)"),
        ("SK", "Slovakia"),
        ("SI", "Slovenia"),
        ("SB", "Solomon Islands"),
        ("SO", "Somalia"),
        ("ZA", "South Africa"),
        ("GS", "South Georgia and South Sandwich Islands"),
        ("SS", "South Sudan"),
        ("ES", "Spain"),
        ("LK", "Sri Lanka"),
        ("SD", "Sudan"),
        ("SR", "Suriname"),
        ("SJ", "Svalbard and Jan Mayen"),
        ("SE", "Sweden"),
        ("CH", "Switzerland"),
        ("SY", "Syria"),
        ("TW", "Taiwan"),
        ("TJ", "Tajikistan"),
        ("TZ", "Tanzania"),
        ("TH", "Thailand"),
        ("TL", "East Timor"),
        ("TG", "Togo"),
        ("TK", "Tokelau"),
        ("TO", "Tonga"),
        ("TT", "Trinidad and Tobago"),
        ("TN", "Tunisia"),
        ("TR", "Turkey"),
        ("TM", "Turkmenistan"),
        ("TC", "Turks and Caicos Islands"),
        ("TV", "Tuvalu"),
        ("UG", "Uganda"),
        ("UA", "Ukraine"),
        ("AE", "United Arab Emirates"),
        ("GB", "United Kingdom"),
        _country_not_found("UM", "United States Minor Outlying Islands"),
        ("US", "United States"),
        ("UY", "Uruguay"),
        ("UZ", "Uzbekistan"),
        ("VU", "Vanuatu"),
        ("VE", "Venezuela"),
        ("VN", "Vietnam"),
        ("VG", "British Virgin Islands"),
        ("VI", "United States Virgin Islands"),
        ("WF", "Wallis and Futuna"),
        ("EH", "Western Sahara"),
        ("YE", "Yemen"),
        ("ZM", "Zambia"),
        ("ZW", "Zimbabwe"),
        ("AX", "Åland Islands"),
    ],
)
def test_iso_alpha_2_country_codes(alpha_2, expected_name):
    assert Country(alpha_2).canonical_name == expected_name


@pytest.mark.parametrize(
    ("alpha_3", "expected_name"),
    [
        _country_not_found("AFG", "Afghanistan"),
        _country_not_found("ALB", "Albania"),
        _country_not_found("DZA", "Algeria"),
        _country_not_found("ASM", "American Samoa"),
        _country_not_found("AND", "Andorra"),
        _country_not_found("AGO", "Angola"),
        _country_not_found("AIA", "Anguilla"),
        _country_not_found("ATA", "Antarctica"),
        _country_not_found("ATG", "Antigua and Barbuda"),
        _country_not_found("ARG", "Argentina"),
        _country_not_found("ARM", "Armenia"),
        _country_not_found("ABW", "Aruba"),
        _country_not_found("AUS", "Australia"),
        _country_not_found("AUT", "Austria"),
        _country_not_found("AZE", "Azerbaijan"),
        _country_not_found("BHS", "The Bahamas"),
        _country_not_found("BHR", "Bahrain"),
        _country_not_found("BGD", "Bangladesh"),
        _country_not_found("BRB", "Barbados"),
        _country_not_found("BLR", "Belarus"),
        _country_not_found("BEL", "Belgium"),
        _country_not_found("BLZ", "Belize"),
        _country_not_found("BEN", "Benin"),
        _country_not_found("BMU", "Bermuda"),
        _country_not_found("BTN", "Bhutan"),
        _country_not_found("BOL", "Bolivia"),
        _country_not_found("BES", "Bonaire, Sint Eustatius and Saba"),
        ("BIH", "Bosnia and Herzegovina"),
        _country_not_found("BWA", "Botswana"),
        _country_not_found("BVT", "Bouvet Island"),
        _country_not_found("BRA", "Brazil"),
        ("IOT", "British Indian Ocean Territory"),
        _country_not_found("BRN", "Brunei"),
        _country_not_found("BGR", "Bulgaria"),
        _country_not_found("BFA", "Burkina Faso"),
        _country_not_found("BDI", "Burundi"),
        _country_not_found("CPV", "Cape Verde"),
        _country_not_found("KHM", "Cambodia"),
        _country_not_found("CMR", "Cameroon"),
        _country_not_found("CAN", "Canada"),
        _country_not_found("CYM", "Cayman Islands"),
        _country_not_found("CAF", "Central African Republic"),
        _country_not_found("TCD", "Chad"),
        _country_not_found("CHL", "Chile"),
        _country_not_found("CHN", "China"),
        _country_not_found("CXR", "Christmas Island"),
        _country_not_found("CCK", "Cocos (Keeling) Islands"),
        _country_not_found("COL", "Colombia"),
        _country_not_found("COM", "Comoros"),
        _country_not_found("COD", "Congo (Democratic Republic)"),
        _country_not_found("COG", "Congo"),
        _country_not_found("COK", "Cook Islands"),
        _country_not_found("CRI", "Costa Rica"),
        _country_not_found("HRV", "Croatia"),
        _country_not_found("CUB", "Cuba"),
        _country_not_found("CUW", "Curaçao"),
        _country_not_found("CYP", "Cyprus"),
        _country_not_found("CZE", "Czechia"),
        _country_not_found("CIV", "Ivory Coast"),
        _country_not_found("DNK", "Denmark"),
        _country_not_found("DJI", "Djibouti"),
        _country_not_found("DMA", "Dominica"),
        _country_not_found("DOM", "Dominican Republic"),
        _country_not_found("ECU", "Ecuador"),
        _country_not_found("EGY", "Egypt"),
        _country_not_found("SLV", "El Salvador"),
        _country_not_found("GNQ", "Equatorial Guinea"),
        _country_not_found("ERI", "Eritrea"),
        _country_not_found("EST", "Estonia"),
        _country_not_found("SWZ", "Eswatini"),
        _country_not_found("ETH", "Ethiopia"),
        _country_not_found("FLK", "Falkland Islands"),
        _country_not_found("FRO", "Faroe Islands"),
        _country_not_found("FJI", "Fiji"),
        _country_not_found("FIN", "Finland"),
        _country_not_found("FRA", "France"),
        _country_not_found("GUF", "French Guiana"),
        _country_not_found("PYF", "French Polynesia"),
        _country_not_found("ATF", "French Southern Territories"),
        _country_not_found("GAB", "Gabon"),
        _country_not_found("GMB", "The Gambia"),
        _country_not_found("GEO", "Georgia"),
        _country_not_found("DEU", "Germany"),
        _country_not_found("GHA", "Ghana"),
        _country_not_found("GIB", "Gibraltar"),
        _country_not_found("GRC", "Greece"),
        _country_not_found("GRL", "Greenland"),
        _country_not_found("GRD", "Grenada"),
        _country_not_found("GLP", "Guadeloupe"),
        _country_not_found("GUM", "Guam"),
        _country_not_found("GTM", "Guatemala"),
        _country_not_found("GGY", "United Kingdom"),
        _country_not_found("GIN", "Guinea"),
        _country_not_found("GNB", "Guinea-Bissau"),
        _country_not_found("GUY", "Guyana"),
        _country_not_found("HTI", "Haiti"),
        _country_not_found("HMD", "Heard Island and McDonald Islands"),
        _country_not_found("VAT", "Vatican City"),
        _country_not_found("HND", "Honduras"),
        _country_not_found("HKG", "Hong Kong"),
        _country_not_found("HUN", "Hungary"),
        _country_not_found("ISL", "Iceland"),
        _country_not_found("IND", "India"),
        _country_not_found("IDN", "Indonesia"),
        _country_not_found("IRN", "Iran"),
        _country_not_found("IRQ", "Iraq"),
        _country_not_found("IRL", "Ireland"),
        _country_not_found("IMN", "United Kingdom"),
        _country_not_found("ISR", "Israel"),
        _country_not_found("ITA", "Italy"),
        _country_not_found("JAM", "Jamaica"),
        _country_not_found("JPN", "Japan"),
        _country_not_found("JEY", "United Kingdom"),
        _country_not_found("JOR", "Jordan"),
        _country_not_found("KAZ", "Kazakhstan"),
        _country_not_found("KEN", "Kenya"),
        _country_not_found("KIR", "Kiribati"),
        ("PRK", "North Korea"),
        _country_not_found("KOR", "Korea"),
        _country_not_found("KWT", "Kuwait"),
        _country_not_found("KGZ", "Kyrgyzstan"),
        ("LAO", "Laos"),
        _country_not_found("LVA", "Latvia"),
        _country_not_found("LBN", "Lebanon"),
        _country_not_found("LSO", "Lesotho"),
        _country_not_found("LBR", "Liberia"),
        _country_not_found("LBY", "Libya"),
        _country_not_found("LIE", "Liechtenstein"),
        _country_not_found("LTU", "Lithuania"),
        _country_not_found("LUX", "Luxembourg"),
        _country_not_found("MAC", "Macao"),
        _country_not_found("MDG", "Madagascar"),
        _country_not_found("MWI", "Malawi"),
        _country_not_found("MYS", "Malaysia"),
        _country_not_found("MDV", "Maldives"),
        _country_not_found("MLI", "Mali"),
        _country_not_found("MLT", "Malta"),
        _country_not_found("MHL", "Marshall Islands"),
        _country_not_found("MTQ", "Martinique"),
        _country_not_found("MRT", "Mauritania"),
        _country_not_found("MUS", "Mauritius"),
        _country_not_found("MYT", "Mayotte"),
        _country_not_found("MEX", "Mexico"),
        _country_not_found("FSM", "Micronesia"),
        _country_not_found("MDA", "Moldova"),
        _country_not_found("MCO", "Monaco"),
        _country_not_found("MNG", "Mongolia"),
        _country_not_found("MNE", "Montenegro"),
        _country_not_found("MSR", "Montserrat"),
        _country_not_found("MAR", "Morocco"),
        _country_not_found("MOZ", "Mozambique"),
        _country_not_found("MMR", "Myanmar (Burma)"),
        _country_not_found("NAM", "Namibia"),
        _country_not_found("NRU", "Nauru"),
        _country_not_found("NPL", "Nepal"),
        _country_not_found("NLD", "Netherlands"),
        _country_not_found("NCL", "New Caledonia"),
        _country_not_found("NZL", "New Zealand"),
        _country_not_found("NIC", "Nicaragua"),
        _country_not_found("NER", "Niger"),
        _country_not_found("NGA", "Nigeria"),
        _country_not_found("NIU", "Niue"),
        _country_not_found("NFK", "Norfolk Island"),
        _country_not_found("MKD", "North Macedonia"),
        _country_not_found("MNP", "Northern Mariana Islands"),
        _country_not_found("NOR", "Norway"),
        _country_not_found("OMN", "Oman"),
        _country_not_found("PAK", "Pakistan"),
        _country_not_found("PLW", "Palau"),
        _country_not_found("PSE", "Occupied Palestinian Territories"),
        _country_not_found("PAN", "Panama"),
        ("PNG", "Papua New Guinea"),
        _country_not_found("PRY", "Paraguay"),
        _country_not_found("PER", "Peru"),
        _country_not_found("PHL", "Philippines"),
        _country_not_found("PCN", "Pitcairn, Henderson, Ducie and Oeno Islands"),
        _country_not_found("POL", "Poland"),
        _country_not_found("PRT", "Portugal"),
        _country_not_found("PRI", "Puerto Rico"),
        _country_not_found("QAT", "Qatar"),
        _country_not_found("ROU", "Romania"),
        _country_not_found("RUS", "Russian Federation"),
        _country_not_found("RWA", "Rwanda"),
        _country_not_found("REU", "Réunion"),
        _country_not_found("BLM", "Saint Barthélemy"),
        _country_not_found("SHN", "Saint Helena, Ascension and Tristan da Cunha"),
        _country_not_found("KNA", "St Kitts and Nevis"),
        _country_not_found("LCA", "St Lucia"),
        _country_not_found("MAF", "Saint-Martin (French part)"),
        _country_not_found("SPM", "Saint Pierre and Miquelon"),
        _country_not_found("VCT", "Saint Vincent"),
        _country_not_found("WSM", "Samoa"),
        _country_not_found("SMR", "San Marino"),
        _country_not_found("STP", "Sao Tome and Principe"),
        _country_not_found("SAU", "Saudi Arabia"),
        _country_not_found("SEN", "Senegal"),
        _country_not_found("SRB", "Serbia"),
        _country_not_found("SYC", "Seychelles"),
        _country_not_found("SLE", "Sierra Leone"),
        _country_not_found("SGP", "Singapore"),
        _country_not_found("SXM", "Sint Maarten (Dutch part)"),
        _country_not_found("SVK", "Slovakia"),
        _country_not_found("SVN", "Slovenia"),
        _country_not_found("SLB", "Solomon Islands"),
        _country_not_found("SOM", "Somalia"),
        _country_not_found("ZAF", "South Africa"),
        _country_not_found("SGS", "South Georgia and South Sandwich Islands"),
        _country_not_found("SSD", "South Sudan"),
        _country_not_found("ESP", "Spain"),
        _country_not_found("LKA", "Sri Lanka"),
        _country_not_found("SDN", "Sudan"),
        _country_not_found("SUR", "Suriname"),
        _country_not_found("SJM", "Svalbard and Jan Mayen"),
        _country_not_found("SWE", "Sweden"),
        _country_not_found("CHE", "Switzerland"),
        _country_not_found("SYR", "Syrian Arab Republic"),
        _country_not_found("TWN", "Taiwan"),
        _country_not_found("TJK", "Tajikistan"),
        _country_not_found("TZA", "Tanzania"),
        _country_not_found("THA", "Thailand"),
        _country_not_found("TLS", "East Timor"),
        _country_not_found("TGO", "Togo"),
        _country_not_found("TKL", "Tokelau"),
        _country_not_found("TON", "Tonga"),
        _country_not_found("TTO", "Trinidad and Tobago"),
        _country_not_found("TUN", "Tunisia"),
        _country_not_found("TUR", "Turkey"),
        _country_not_found("TKM", "Turkmenistan"),
        _country_not_found("TCA", "Turks and Caicos Islands"),
        _country_not_found("TUV", "Tuvalu"),
        _country_not_found("UGA", "Uganda"),
        _country_not_found("UKR", "Ukraine"),
        _country_not_found("ARE", "United Arab Emirates"),
        ("GBR", "United Kingdom"),
        _country_not_found("UMI", "United States Minor Outlying Islands"),
        ("USA", "United States"),
        _country_not_found("URY", "Uruguay"),
        _country_not_found("UZB", "Uzbekistan"),
        _country_not_found("VUT", "Vanuatu"),
        _country_not_found("VEN", "Venezuela"),
        _country_not_found("VNM", "Vietnam"),
        _country_not_found("VGB", "British Virgin Islands"),
        _country_not_found("VIR", "United States Virgin Islands"),
        _country_not_found("WLF", "Wallis and Futuna"),
        _country_not_found("ESH", "Western Sahara"),
        _country_not_found("YEM", "Yemen"),
        _country_not_found("ZMB", "Zambia"),
        _country_not_found("ZWE", "Zimbabwe"),
        _country_not_found("ALA", "Åland Islands"),
    ],
)
def test_iso_alpha_3_country_codes(alpha_3, expected_name):
    assert Country(alpha_3).canonical_name == expected_name
