// Code generated by go run ./country_generate.go; DO NOT EDIT.

package geoip

import (
	"encoding"
	"fmt"

	"github.com/AdguardTeam/golibs/errors"
)

// Country represents an ISO 3166-1 alpha-2 country code.
type Country string

// Country code constants.  Note that these constants don't include the
// user-assigned ones.
const (
	// CountryNone is an invalid or unknown country code.
	CountryNone Country = ""

	// CountryNotApplicable is the user-assigned ISO 3166-1 alpha-2 code used
	// when a country of origin cannot be determined due to a lack of
	// information, for example a response of the record type that doesn't
	// contain an IP address.
	CountryNotApplicable Country = "QN"

	// CountryXK is the user-assigned ISO 3166-1 alpha-2 code for Republic of
	// Kosovo.  Kosovo does not have a recognized ISO 3166 code, but it is still
	// an entity whose user-assigned code is relatively common.
	CountryXK Country = "XK"

	// CountryAD is the ISO 3166-1 alpha-2 code for
	// Andorra.
	CountryAD Country = "AD"
	// CountryAE is the ISO 3166-1 alpha-2 code for
	// United Arab Emirates.
	CountryAE Country = "AE"
	// CountryAF is the ISO 3166-1 alpha-2 code for
	// Afghanistan.
	CountryAF Country = "AF"
	// CountryAG is the ISO 3166-1 alpha-2 code for
	// Antigua and Barbuda.
	CountryAG Country = "AG"
	// CountryAI is the ISO 3166-1 alpha-2 code for
	// Anguilla.
	CountryAI Country = "AI"
	// CountryAL is the ISO 3166-1 alpha-2 code for
	// Albania.
	CountryAL Country = "AL"
	// CountryAM is the ISO 3166-1 alpha-2 code for
	// Armenia.
	CountryAM Country = "AM"
	// CountryAO is the ISO 3166-1 alpha-2 code for
	// Angola.
	CountryAO Country = "AO"
	// CountryAQ is the ISO 3166-1 alpha-2 code for
	// Antarctica.
	CountryAQ Country = "AQ"
	// CountryAR is the ISO 3166-1 alpha-2 code for
	// Argentina.
	CountryAR Country = "AR"
	// CountryAS is the ISO 3166-1 alpha-2 code for
	// American Samoa.
	CountryAS Country = "AS"
	// CountryAT is the ISO 3166-1 alpha-2 code for
	// Austria.
	CountryAT Country = "AT"
	// CountryAU is the ISO 3166-1 alpha-2 code for
	// Australia.
	CountryAU Country = "AU"
	// CountryAW is the ISO 3166-1 alpha-2 code for
	// Aruba.
	CountryAW Country = "AW"
	// CountryAX is the ISO 3166-1 alpha-2 code for
	// Åland Islands.
	CountryAX Country = "AX"
	// CountryAZ is the ISO 3166-1 alpha-2 code for
	// Azerbaijan.
	CountryAZ Country = "AZ"
	// CountryBA is the ISO 3166-1 alpha-2 code for
	// Bosnia and Herzegovina.
	CountryBA Country = "BA"
	// CountryBB is the ISO 3166-1 alpha-2 code for
	// Barbados.
	CountryBB Country = "BB"
	// CountryBD is the ISO 3166-1 alpha-2 code for
	// Bangladesh.
	CountryBD Country = "BD"
	// CountryBE is the ISO 3166-1 alpha-2 code for
	// Belgium.
	CountryBE Country = "BE"
	// CountryBF is the ISO 3166-1 alpha-2 code for
	// Burkina Faso.
	CountryBF Country = "BF"
	// CountryBG is the ISO 3166-1 alpha-2 code for
	// Bulgaria.
	CountryBG Country = "BG"
	// CountryBH is the ISO 3166-1 alpha-2 code for
	// Bahrain.
	CountryBH Country = "BH"
	// CountryBI is the ISO 3166-1 alpha-2 code for
	// Burundi.
	CountryBI Country = "BI"
	// CountryBJ is the ISO 3166-1 alpha-2 code for
	// Benin.
	CountryBJ Country = "BJ"
	// CountryBL is the ISO 3166-1 alpha-2 code for
	// Saint Barthélemy.
	CountryBL Country = "BL"
	// CountryBM is the ISO 3166-1 alpha-2 code for
	// Bermuda.
	CountryBM Country = "BM"
	// CountryBN is the ISO 3166-1 alpha-2 code for
	// Brunei Darussalam.
	CountryBN Country = "BN"
	// CountryBO is the ISO 3166-1 alpha-2 code for
	// Bolivia, Plurinational State of.
	CountryBO Country = "BO"
	// CountryBQ is the ISO 3166-1 alpha-2 code for
	// Bonaire, Sint Eustatius and Saba.
	CountryBQ Country = "BQ"
	// CountryBR is the ISO 3166-1 alpha-2 code for
	// Brazil.
	CountryBR Country = "BR"
	// CountryBS is the ISO 3166-1 alpha-2 code for
	// Bahamas.
	CountryBS Country = "BS"
	// CountryBT is the ISO 3166-1 alpha-2 code for
	// Bhutan.
	CountryBT Country = "BT"
	// CountryBV is the ISO 3166-1 alpha-2 code for
	// Bouvet Island.
	CountryBV Country = "BV"
	// CountryBW is the ISO 3166-1 alpha-2 code for
	// Botswana.
	CountryBW Country = "BW"
	// CountryBY is the ISO 3166-1 alpha-2 code for
	// Belarus.
	CountryBY Country = "BY"
	// CountryBZ is the ISO 3166-1 alpha-2 code for
	// Belize.
	CountryBZ Country = "BZ"
	// CountryCA is the ISO 3166-1 alpha-2 code for
	// Canada.
	CountryCA Country = "CA"
	// CountryCC is the ISO 3166-1 alpha-2 code for
	// Cocos (Keeling) Islands.
	CountryCC Country = "CC"
	// CountryCD is the ISO 3166-1 alpha-2 code for
	// Congo, Democratic Republic of the.
	CountryCD Country = "CD"
	// CountryCF is the ISO 3166-1 alpha-2 code for
	// Central African Republic.
	CountryCF Country = "CF"
	// CountryCG is the ISO 3166-1 alpha-2 code for
	// Congo.
	CountryCG Country = "CG"
	// CountryCH is the ISO 3166-1 alpha-2 code for
	// Switzerland.
	CountryCH Country = "CH"
	// CountryCI is the ISO 3166-1 alpha-2 code for
	// Côte d'Ivoire.
	CountryCI Country = "CI"
	// CountryCK is the ISO 3166-1 alpha-2 code for
	// Cook Islands.
	CountryCK Country = "CK"
	// CountryCL is the ISO 3166-1 alpha-2 code for
	// Chile.
	CountryCL Country = "CL"
	// CountryCM is the ISO 3166-1 alpha-2 code for
	// Cameroon.
	CountryCM Country = "CM"
	// CountryCN is the ISO 3166-1 alpha-2 code for
	// China.
	CountryCN Country = "CN"
	// CountryCO is the ISO 3166-1 alpha-2 code for
	// Colombia.
	CountryCO Country = "CO"
	// CountryCR is the ISO 3166-1 alpha-2 code for
	// Costa Rica.
	CountryCR Country = "CR"
	// CountryCU is the ISO 3166-1 alpha-2 code for
	// Cuba.
	CountryCU Country = "CU"
	// CountryCV is the ISO 3166-1 alpha-2 code for
	// Cabo Verde.
	CountryCV Country = "CV"
	// CountryCW is the ISO 3166-1 alpha-2 code for
	// Curaçao.
	CountryCW Country = "CW"
	// CountryCX is the ISO 3166-1 alpha-2 code for
	// Christmas Island.
	CountryCX Country = "CX"
	// CountryCY is the ISO 3166-1 alpha-2 code for
	// Cyprus.
	CountryCY Country = "CY"
	// CountryCZ is the ISO 3166-1 alpha-2 code for
	// Czechia.
	CountryCZ Country = "CZ"
	// CountryDE is the ISO 3166-1 alpha-2 code for
	// Germany.
	CountryDE Country = "DE"
	// CountryDJ is the ISO 3166-1 alpha-2 code for
	// Djibouti.
	CountryDJ Country = "DJ"
	// CountryDK is the ISO 3166-1 alpha-2 code for
	// Denmark.
	CountryDK Country = "DK"
	// CountryDM is the ISO 3166-1 alpha-2 code for
	// Dominica.
	CountryDM Country = "DM"
	// CountryDO is the ISO 3166-1 alpha-2 code for
	// Dominican Republic.
	CountryDO Country = "DO"
	// CountryDZ is the ISO 3166-1 alpha-2 code for
	// Algeria.
	CountryDZ Country = "DZ"
	// CountryEC is the ISO 3166-1 alpha-2 code for
	// Ecuador.
	CountryEC Country = "EC"
	// CountryEE is the ISO 3166-1 alpha-2 code for
	// Estonia.
	CountryEE Country = "EE"
	// CountryEG is the ISO 3166-1 alpha-2 code for
	// Egypt.
	CountryEG Country = "EG"
	// CountryEH is the ISO 3166-1 alpha-2 code for
	// Western Sahara.
	CountryEH Country = "EH"
	// CountryER is the ISO 3166-1 alpha-2 code for
	// Eritrea.
	CountryER Country = "ER"
	// CountryES is the ISO 3166-1 alpha-2 code for
	// Spain.
	CountryES Country = "ES"
	// CountryET is the ISO 3166-1 alpha-2 code for
	// Ethiopia.
	CountryET Country = "ET"
	// CountryFI is the ISO 3166-1 alpha-2 code for
	// Finland.
	CountryFI Country = "FI"
	// CountryFJ is the ISO 3166-1 alpha-2 code for
	// Fiji.
	CountryFJ Country = "FJ"
	// CountryFK is the ISO 3166-1 alpha-2 code for
	// Falkland Islands (Malvinas).
	CountryFK Country = "FK"
	// CountryFM is the ISO 3166-1 alpha-2 code for
	// Micronesia, Federated States of.
	CountryFM Country = "FM"
	// CountryFO is the ISO 3166-1 alpha-2 code for
	// Faroe Islands.
	CountryFO Country = "FO"
	// CountryFR is the ISO 3166-1 alpha-2 code for
	// France.
	CountryFR Country = "FR"
	// CountryGA is the ISO 3166-1 alpha-2 code for
	// Gabon.
	CountryGA Country = "GA"
	// CountryGB is the ISO 3166-1 alpha-2 code for
	// United Kingdom of Great Britain and Northern Ireland.
	CountryGB Country = "GB"
	// CountryGD is the ISO 3166-1 alpha-2 code for
	// Grenada.
	CountryGD Country = "GD"
	// CountryGE is the ISO 3166-1 alpha-2 code for
	// Georgia.
	CountryGE Country = "GE"
	// CountryGF is the ISO 3166-1 alpha-2 code for
	// French Guiana.
	CountryGF Country = "GF"
	// CountryGG is the ISO 3166-1 alpha-2 code for
	// Guernsey.
	CountryGG Country = "GG"
	// CountryGH is the ISO 3166-1 alpha-2 code for
	// Ghana.
	CountryGH Country = "GH"
	// CountryGI is the ISO 3166-1 alpha-2 code for
	// Gibraltar.
	CountryGI Country = "GI"
	// CountryGL is the ISO 3166-1 alpha-2 code for
	// Greenland.
	CountryGL Country = "GL"
	// CountryGM is the ISO 3166-1 alpha-2 code for
	// Gambia.
	CountryGM Country = "GM"
	// CountryGN is the ISO 3166-1 alpha-2 code for
	// Guinea.
	CountryGN Country = "GN"
	// CountryGP is the ISO 3166-1 alpha-2 code for
	// Guadeloupe.
	CountryGP Country = "GP"
	// CountryGQ is the ISO 3166-1 alpha-2 code for
	// Equatorial Guinea.
	CountryGQ Country = "GQ"
	// CountryGR is the ISO 3166-1 alpha-2 code for
	// Greece.
	CountryGR Country = "GR"
	// CountryGS is the ISO 3166-1 alpha-2 code for
	// South Georgia and the South Sandwich Islands.
	CountryGS Country = "GS"
	// CountryGT is the ISO 3166-1 alpha-2 code for
	// Guatemala.
	CountryGT Country = "GT"
	// CountryGU is the ISO 3166-1 alpha-2 code for
	// Guam.
	CountryGU Country = "GU"
	// CountryGW is the ISO 3166-1 alpha-2 code for
	// Guinea-Bissau.
	CountryGW Country = "GW"
	// CountryGY is the ISO 3166-1 alpha-2 code for
	// Guyana.
	CountryGY Country = "GY"
	// CountryHK is the ISO 3166-1 alpha-2 code for
	// Hong Kong.
	CountryHK Country = "HK"
	// CountryHM is the ISO 3166-1 alpha-2 code for
	// Heard Island and McDonald Islands.
	CountryHM Country = "HM"
	// CountryHN is the ISO 3166-1 alpha-2 code for
	// Honduras.
	CountryHN Country = "HN"
	// CountryHR is the ISO 3166-1 alpha-2 code for
	// Croatia.
	CountryHR Country = "HR"
	// CountryHT is the ISO 3166-1 alpha-2 code for
	// Haiti.
	CountryHT Country = "HT"
	// CountryHU is the ISO 3166-1 alpha-2 code for
	// Hungary.
	CountryHU Country = "HU"
	// CountryID is the ISO 3166-1 alpha-2 code for
	// Indonesia.
	CountryID Country = "ID"
	// CountryIE is the ISO 3166-1 alpha-2 code for
	// Ireland.
	CountryIE Country = "IE"
	// CountryIL is the ISO 3166-1 alpha-2 code for
	// Israel.
	CountryIL Country = "IL"
	// CountryIM is the ISO 3166-1 alpha-2 code for
	// Isle of Man.
	CountryIM Country = "IM"
	// CountryIN is the ISO 3166-1 alpha-2 code for
	// India.
	CountryIN Country = "IN"
	// CountryIO is the ISO 3166-1 alpha-2 code for
	// British Indian Ocean Territory.
	CountryIO Country = "IO"
	// CountryIQ is the ISO 3166-1 alpha-2 code for
	// Iraq.
	CountryIQ Country = "IQ"
	// CountryIR is the ISO 3166-1 alpha-2 code for
	// Iran, Islamic Republic of.
	CountryIR Country = "IR"
	// CountryIS is the ISO 3166-1 alpha-2 code for
	// Iceland.
	CountryIS Country = "IS"
	// CountryIT is the ISO 3166-1 alpha-2 code for
	// Italy.
	CountryIT Country = "IT"
	// CountryJE is the ISO 3166-1 alpha-2 code for
	// Jersey.
	CountryJE Country = "JE"
	// CountryJM is the ISO 3166-1 alpha-2 code for
	// Jamaica.
	CountryJM Country = "JM"
	// CountryJO is the ISO 3166-1 alpha-2 code for
	// Jordan.
	CountryJO Country = "JO"
	// CountryJP is the ISO 3166-1 alpha-2 code for
	// Japan.
	CountryJP Country = "JP"
	// CountryKE is the ISO 3166-1 alpha-2 code for
	// Kenya.
	CountryKE Country = "KE"
	// CountryKG is the ISO 3166-1 alpha-2 code for
	// Kyrgyzstan.
	CountryKG Country = "KG"
	// CountryKH is the ISO 3166-1 alpha-2 code for
	// Cambodia.
	CountryKH Country = "KH"
	// CountryKI is the ISO 3166-1 alpha-2 code for
	// Kiribati.
	CountryKI Country = "KI"
	// CountryKM is the ISO 3166-1 alpha-2 code for
	// Comoros.
	CountryKM Country = "KM"
	// CountryKN is the ISO 3166-1 alpha-2 code for
	// Saint Kitts and Nevis.
	CountryKN Country = "KN"
	// CountryKP is the ISO 3166-1 alpha-2 code for
	// Korea, Democratic People's Republic of.
	CountryKP Country = "KP"
	// CountryKR is the ISO 3166-1 alpha-2 code for
	// Korea, Republic of.
	CountryKR Country = "KR"
	// CountryKW is the ISO 3166-1 alpha-2 code for
	// Kuwait.
	CountryKW Country = "KW"
	// CountryKY is the ISO 3166-1 alpha-2 code for
	// Cayman Islands.
	CountryKY Country = "KY"
	// CountryKZ is the ISO 3166-1 alpha-2 code for
	// Kazakhstan.
	CountryKZ Country = "KZ"
	// CountryLA is the ISO 3166-1 alpha-2 code for
	// Lao People's Democratic Republic.
	CountryLA Country = "LA"
	// CountryLB is the ISO 3166-1 alpha-2 code for
	// Lebanon.
	CountryLB Country = "LB"
	// CountryLC is the ISO 3166-1 alpha-2 code for
	// Saint Lucia.
	CountryLC Country = "LC"
	// CountryLI is the ISO 3166-1 alpha-2 code for
	// Liechtenstein.
	CountryLI Country = "LI"
	// CountryLK is the ISO 3166-1 alpha-2 code for
	// Sri Lanka.
	CountryLK Country = "LK"
	// CountryLR is the ISO 3166-1 alpha-2 code for
	// Liberia.
	CountryLR Country = "LR"
	// CountryLS is the ISO 3166-1 alpha-2 code for
	// Lesotho.
	CountryLS Country = "LS"
	// CountryLT is the ISO 3166-1 alpha-2 code for
	// Lithuania.
	CountryLT Country = "LT"
	// CountryLU is the ISO 3166-1 alpha-2 code for
	// Luxembourg.
	CountryLU Country = "LU"
	// CountryLV is the ISO 3166-1 alpha-2 code for
	// Latvia.
	CountryLV Country = "LV"
	// CountryLY is the ISO 3166-1 alpha-2 code for
	// Libya.
	CountryLY Country = "LY"
	// CountryMA is the ISO 3166-1 alpha-2 code for
	// Morocco.
	CountryMA Country = "MA"
	// CountryMC is the ISO 3166-1 alpha-2 code for
	// Monaco.
	CountryMC Country = "MC"
	// CountryMD is the ISO 3166-1 alpha-2 code for
	// Moldova, Republic of.
	CountryMD Country = "MD"
	// CountryME is the ISO 3166-1 alpha-2 code for
	// Montenegro.
	CountryME Country = "ME"
	// CountryMF is the ISO 3166-1 alpha-2 code for
	// Saint Martin (French part).
	CountryMF Country = "MF"
	// CountryMG is the ISO 3166-1 alpha-2 code for
	// Madagascar.
	CountryMG Country = "MG"
	// CountryMH is the ISO 3166-1 alpha-2 code for
	// Marshall Islands.
	CountryMH Country = "MH"
	// CountryMK is the ISO 3166-1 alpha-2 code for
	// North Macedonia.
	CountryMK Country = "MK"
	// CountryML is the ISO 3166-1 alpha-2 code for
	// Mali.
	CountryML Country = "ML"
	// CountryMM is the ISO 3166-1 alpha-2 code for
	// Myanmar.
	CountryMM Country = "MM"
	// CountryMN is the ISO 3166-1 alpha-2 code for
	// Mongolia.
	CountryMN Country = "MN"
	// CountryMO is the ISO 3166-1 alpha-2 code for
	// Macao.
	CountryMO Country = "MO"
	// CountryMP is the ISO 3166-1 alpha-2 code for
	// Northern Mariana Islands.
	CountryMP Country = "MP"
	// CountryMQ is the ISO 3166-1 alpha-2 code for
	// Martinique.
	CountryMQ Country = "MQ"
	// CountryMR is the ISO 3166-1 alpha-2 code for
	// Mauritania.
	CountryMR Country = "MR"
	// CountryMS is the ISO 3166-1 alpha-2 code for
	// Montserrat.
	CountryMS Country = "MS"
	// CountryMT is the ISO 3166-1 alpha-2 code for
	// Malta.
	CountryMT Country = "MT"
	// CountryMU is the ISO 3166-1 alpha-2 code for
	// Mauritius.
	CountryMU Country = "MU"
	// CountryMV is the ISO 3166-1 alpha-2 code for
	// Maldives.
	CountryMV Country = "MV"
	// CountryMW is the ISO 3166-1 alpha-2 code for
	// Malawi.
	CountryMW Country = "MW"
	// CountryMX is the ISO 3166-1 alpha-2 code for
	// Mexico.
	CountryMX Country = "MX"
	// CountryMY is the ISO 3166-1 alpha-2 code for
	// Malaysia.
	CountryMY Country = "MY"
	// CountryMZ is the ISO 3166-1 alpha-2 code for
	// Mozambique.
	CountryMZ Country = "MZ"
	// CountryNA is the ISO 3166-1 alpha-2 code for
	// Namibia.
	CountryNA Country = "NA"
	// CountryNC is the ISO 3166-1 alpha-2 code for
	// New Caledonia.
	CountryNC Country = "NC"
	// CountryNE is the ISO 3166-1 alpha-2 code for
	// Niger.
	CountryNE Country = "NE"
	// CountryNF is the ISO 3166-1 alpha-2 code for
	// Norfolk Island.
	CountryNF Country = "NF"
	// CountryNG is the ISO 3166-1 alpha-2 code for
	// Nigeria.
	CountryNG Country = "NG"
	// CountryNI is the ISO 3166-1 alpha-2 code for
	// Nicaragua.
	CountryNI Country = "NI"
	// CountryNL is the ISO 3166-1 alpha-2 code for
	// Netherlands, Kingdom of the.
	CountryNL Country = "NL"
	// CountryNO is the ISO 3166-1 alpha-2 code for
	// Norway.
	CountryNO Country = "NO"
	// CountryNP is the ISO 3166-1 alpha-2 code for
	// Nepal.
	CountryNP Country = "NP"
	// CountryNR is the ISO 3166-1 alpha-2 code for
	// Nauru.
	CountryNR Country = "NR"
	// CountryNU is the ISO 3166-1 alpha-2 code for
	// Niue.
	CountryNU Country = "NU"
	// CountryNZ is the ISO 3166-1 alpha-2 code for
	// New Zealand.
	CountryNZ Country = "NZ"
	// CountryOM is the ISO 3166-1 alpha-2 code for
	// Oman.
	CountryOM Country = "OM"
	// CountryPA is the ISO 3166-1 alpha-2 code for
	// Panama.
	CountryPA Country = "PA"
	// CountryPE is the ISO 3166-1 alpha-2 code for
	// Peru.
	CountryPE Country = "PE"
	// CountryPF is the ISO 3166-1 alpha-2 code for
	// French Polynesia.
	CountryPF Country = "PF"
	// CountryPG is the ISO 3166-1 alpha-2 code for
	// Papua New Guinea.
	CountryPG Country = "PG"
	// CountryPH is the ISO 3166-1 alpha-2 code for
	// Philippines.
	CountryPH Country = "PH"
	// CountryPK is the ISO 3166-1 alpha-2 code for
	// Pakistan.
	CountryPK Country = "PK"
	// CountryPL is the ISO 3166-1 alpha-2 code for
	// Poland.
	CountryPL Country = "PL"
	// CountryPM is the ISO 3166-1 alpha-2 code for
	// Saint Pierre and Miquelon.
	CountryPM Country = "PM"
	// CountryPN is the ISO 3166-1 alpha-2 code for
	// Pitcairn.
	CountryPN Country = "PN"
	// CountryPR is the ISO 3166-1 alpha-2 code for
	// Puerto Rico.
	CountryPR Country = "PR"
	// CountryPS is the ISO 3166-1 alpha-2 code for
	// Palestine, State of.
	CountryPS Country = "PS"
	// CountryPT is the ISO 3166-1 alpha-2 code for
	// Portugal.
	CountryPT Country = "PT"
	// CountryPW is the ISO 3166-1 alpha-2 code for
	// Palau.
	CountryPW Country = "PW"
	// CountryPY is the ISO 3166-1 alpha-2 code for
	// Paraguay.
	CountryPY Country = "PY"
	// CountryQA is the ISO 3166-1 alpha-2 code for
	// Qatar.
	CountryQA Country = "QA"
	// CountryRE is the ISO 3166-1 alpha-2 code for
	// Réunion.
	CountryRE Country = "RE"
	// CountryRO is the ISO 3166-1 alpha-2 code for
	// Romania.
	CountryRO Country = "RO"
	// CountryRS is the ISO 3166-1 alpha-2 code for
	// Serbia.
	CountryRS Country = "RS"
	// CountryRU is the ISO 3166-1 alpha-2 code for
	// Russian Federation.
	CountryRU Country = "RU"
	// CountryRW is the ISO 3166-1 alpha-2 code for
	// Rwanda.
	CountryRW Country = "RW"
	// CountrySA is the ISO 3166-1 alpha-2 code for
	// Saudi Arabia.
	CountrySA Country = "SA"
	// CountrySB is the ISO 3166-1 alpha-2 code for
	// Solomon Islands.
	CountrySB Country = "SB"
	// CountrySC is the ISO 3166-1 alpha-2 code for
	// Seychelles.
	CountrySC Country = "SC"
	// CountrySD is the ISO 3166-1 alpha-2 code for
	// Sudan.
	CountrySD Country = "SD"
	// CountrySE is the ISO 3166-1 alpha-2 code for
	// Sweden.
	CountrySE Country = "SE"
	// CountrySG is the ISO 3166-1 alpha-2 code for
	// Singapore.
	CountrySG Country = "SG"
	// CountrySH is the ISO 3166-1 alpha-2 code for
	// Saint Helena, Ascension and Tristan da Cunha.
	CountrySH Country = "SH"
	// CountrySI is the ISO 3166-1 alpha-2 code for
	// Slovenia.
	CountrySI Country = "SI"
	// CountrySJ is the ISO 3166-1 alpha-2 code for
	// Svalbard and Jan Mayen.
	CountrySJ Country = "SJ"
	// CountrySK is the ISO 3166-1 alpha-2 code for
	// Slovakia.
	CountrySK Country = "SK"
	// CountrySL is the ISO 3166-1 alpha-2 code for
	// Sierra Leone.
	CountrySL Country = "SL"
	// CountrySM is the ISO 3166-1 alpha-2 code for
	// San Marino.
	CountrySM Country = "SM"
	// CountrySN is the ISO 3166-1 alpha-2 code for
	// Senegal.
	CountrySN Country = "SN"
	// CountrySO is the ISO 3166-1 alpha-2 code for
	// Somalia.
	CountrySO Country = "SO"
	// CountrySR is the ISO 3166-1 alpha-2 code for
	// Suriname.
	CountrySR Country = "SR"
	// CountrySS is the ISO 3166-1 alpha-2 code for
	// South Sudan.
	CountrySS Country = "SS"
	// CountryST is the ISO 3166-1 alpha-2 code for
	// Sao Tome and Principe.
	CountryST Country = "ST"
	// CountrySV is the ISO 3166-1 alpha-2 code for
	// El Salvador.
	CountrySV Country = "SV"
	// CountrySX is the ISO 3166-1 alpha-2 code for
	// Sint Maarten (Dutch part).
	CountrySX Country = "SX"
	// CountrySY is the ISO 3166-1 alpha-2 code for
	// Syrian Arab Republic.
	CountrySY Country = "SY"
	// CountrySZ is the ISO 3166-1 alpha-2 code for
	// Eswatini.
	CountrySZ Country = "SZ"
	// CountryTC is the ISO 3166-1 alpha-2 code for
	// Turks and Caicos Islands.
	CountryTC Country = "TC"
	// CountryTD is the ISO 3166-1 alpha-2 code for
	// Chad.
	CountryTD Country = "TD"
	// CountryTF is the ISO 3166-1 alpha-2 code for
	// French Southern Territories.
	CountryTF Country = "TF"
	// CountryTG is the ISO 3166-1 alpha-2 code for
	// Togo.
	CountryTG Country = "TG"
	// CountryTH is the ISO 3166-1 alpha-2 code for
	// Thailand.
	CountryTH Country = "TH"
	// CountryTJ is the ISO 3166-1 alpha-2 code for
	// Tajikistan.
	CountryTJ Country = "TJ"
	// CountryTK is the ISO 3166-1 alpha-2 code for
	// Tokelau.
	CountryTK Country = "TK"
	// CountryTL is the ISO 3166-1 alpha-2 code for
	// Timor-Leste.
	CountryTL Country = "TL"
	// CountryTM is the ISO 3166-1 alpha-2 code for
	// Turkmenistan.
	CountryTM Country = "TM"
	// CountryTN is the ISO 3166-1 alpha-2 code for
	// Tunisia.
	CountryTN Country = "TN"
	// CountryTO is the ISO 3166-1 alpha-2 code for
	// Tonga.
	CountryTO Country = "TO"
	// CountryTR is the ISO 3166-1 alpha-2 code for
	// Türkiye.
	CountryTR Country = "TR"
	// CountryTT is the ISO 3166-1 alpha-2 code for
	// Trinidad and Tobago.
	CountryTT Country = "TT"
	// CountryTV is the ISO 3166-1 alpha-2 code for
	// Tuvalu.
	CountryTV Country = "TV"
	// CountryTW is the ISO 3166-1 alpha-2 code for
	// Taiwan, Province of China.
	CountryTW Country = "TW"
	// CountryTZ is the ISO 3166-1 alpha-2 code for
	// Tanzania, United Republic of.
	CountryTZ Country = "TZ"
	// CountryUA is the ISO 3166-1 alpha-2 code for
	// Ukraine.
	CountryUA Country = "UA"
	// CountryUG is the ISO 3166-1 alpha-2 code for
	// Uganda.
	CountryUG Country = "UG"
	// CountryUM is the ISO 3166-1 alpha-2 code for
	// United States Minor Outlying Islands.
	CountryUM Country = "UM"
	// CountryUS is the ISO 3166-1 alpha-2 code for
	// United States of America.
	CountryUS Country = "US"
	// CountryUY is the ISO 3166-1 alpha-2 code for
	// Uruguay.
	CountryUY Country = "UY"
	// CountryUZ is the ISO 3166-1 alpha-2 code for
	// Uzbekistan.
	CountryUZ Country = "UZ"
	// CountryVA is the ISO 3166-1 alpha-2 code for
	// Holy See.
	CountryVA Country = "VA"
	// CountryVC is the ISO 3166-1 alpha-2 code for
	// Saint Vincent and the Grenadines.
	CountryVC Country = "VC"
	// CountryVE is the ISO 3166-1 alpha-2 code for
	// Venezuela, Bolivarian Republic of.
	CountryVE Country = "VE"
	// CountryVG is the ISO 3166-1 alpha-2 code for
	// Virgin Islands (British).
	CountryVG Country = "VG"
	// CountryVI is the ISO 3166-1 alpha-2 code for
	// Virgin Islands (U.S.).
	CountryVI Country = "VI"
	// CountryVN is the ISO 3166-1 alpha-2 code for
	// Viet Nam.
	CountryVN Country = "VN"
	// CountryVU is the ISO 3166-1 alpha-2 code for
	// Vanuatu.
	CountryVU Country = "VU"
	// CountryWF is the ISO 3166-1 alpha-2 code for
	// Wallis and Futuna.
	CountryWF Country = "WF"
	// CountryWS is the ISO 3166-1 alpha-2 code for
	// Samoa.
	CountryWS Country = "WS"
	// CountryYE is the ISO 3166-1 alpha-2 code for
	// Yemen.
	CountryYE Country = "YE"
	// CountryYT is the ISO 3166-1 alpha-2 code for
	// Mayotte.
	CountryYT Country = "YT"
	// CountryZA is the ISO 3166-1 alpha-2 code for
	// South Africa.
	CountryZA Country = "ZA"
	// CountryZM is the ISO 3166-1 alpha-2 code for
	// Zambia.
	CountryZM Country = "ZM"
	// CountryZW is the ISO 3166-1 alpha-2 code for
	// Zimbabwe.
	CountryZW Country = "ZW"
)

// NewCountry converts s into a Country while also validating it.  Prefer to use
// this instead of a plain conversion.
func NewCountry(s string) (c Country, err error) {
	c = Country(s)
	if isUserAssigned(s) {
		return c, nil
	}

	switch c {
	case
		CountryAD,
		CountryAE,
		CountryAF,
		CountryAG,
		CountryAI,
		CountryAL,
		CountryAM,
		CountryAO,
		CountryAQ,
		CountryAR,
		CountryAS,
		CountryAT,
		CountryAU,
		CountryAW,
		CountryAX,
		CountryAZ,
		CountryBA,
		CountryBB,
		CountryBD,
		CountryBE,
		CountryBF,
		CountryBG,
		CountryBH,
		CountryBI,
		CountryBJ,
		CountryBL,
		CountryBM,
		CountryBN,
		CountryBO,
		CountryBQ,
		CountryBR,
		CountryBS,
		CountryBT,
		CountryBV,
		CountryBW,
		CountryBY,
		CountryBZ,
		CountryCA,
		CountryCC,
		CountryCD,
		CountryCF,
		CountryCG,
		CountryCH,
		CountryCI,
		CountryCK,
		CountryCL,
		CountryCM,
		CountryCN,
		CountryCO,
		CountryCR,
		CountryCU,
		CountryCV,
		CountryCW,
		CountryCX,
		CountryCY,
		CountryCZ,
		CountryDE,
		CountryDJ,
		CountryDK,
		CountryDM,
		CountryDO,
		CountryDZ,
		CountryEC,
		CountryEE,
		CountryEG,
		CountryEH,
		CountryER,
		CountryES,
		CountryET,
		CountryFI,
		CountryFJ,
		CountryFK,
		CountryFM,
		CountryFO,
		CountryFR,
		CountryGA,
		CountryGB,
		CountryGD,
		CountryGE,
		CountryGF,
		CountryGG,
		CountryGH,
		CountryGI,
		CountryGL,
		CountryGM,
		CountryGN,
		CountryGP,
		CountryGQ,
		CountryGR,
		CountryGS,
		CountryGT,
		CountryGU,
		CountryGW,
		CountryGY,
		CountryHK,
		CountryHM,
		CountryHN,
		CountryHR,
		CountryHT,
		CountryHU,
		CountryID,
		CountryIE,
		CountryIL,
		CountryIM,
		CountryIN,
		CountryIO,
		CountryIQ,
		CountryIR,
		CountryIS,
		CountryIT,
		CountryJE,
		CountryJM,
		CountryJO,
		CountryJP,
		CountryKE,
		CountryKG,
		CountryKH,
		CountryKI,
		CountryKM,
		CountryKN,
		CountryKP,
		CountryKR,
		CountryKW,
		CountryKY,
		CountryKZ,
		CountryLA,
		CountryLB,
		CountryLC,
		CountryLI,
		CountryLK,
		CountryLR,
		CountryLS,
		CountryLT,
		CountryLU,
		CountryLV,
		CountryLY,
		CountryMA,
		CountryMC,
		CountryMD,
		CountryME,
		CountryMF,
		CountryMG,
		CountryMH,
		CountryMK,
		CountryML,
		CountryMM,
		CountryMN,
		CountryMO,
		CountryMP,
		CountryMQ,
		CountryMR,
		CountryMS,
		CountryMT,
		CountryMU,
		CountryMV,
		CountryMW,
		CountryMX,
		CountryMY,
		CountryMZ,
		CountryNA,
		CountryNC,
		CountryNE,
		CountryNF,
		CountryNG,
		CountryNI,
		CountryNL,
		CountryNO,
		CountryNP,
		CountryNR,
		CountryNU,
		CountryNZ,
		CountryOM,
		CountryPA,
		CountryPE,
		CountryPF,
		CountryPG,
		CountryPH,
		CountryPK,
		CountryPL,
		CountryPM,
		CountryPN,
		CountryPR,
		CountryPS,
		CountryPT,
		CountryPW,
		CountryPY,
		CountryQA,
		CountryRE,
		CountryRO,
		CountryRS,
		CountryRU,
		CountryRW,
		CountrySA,
		CountrySB,
		CountrySC,
		CountrySD,
		CountrySE,
		CountrySG,
		CountrySH,
		CountrySI,
		CountrySJ,
		CountrySK,
		CountrySL,
		CountrySM,
		CountrySN,
		CountrySO,
		CountrySR,
		CountrySS,
		CountryST,
		CountrySV,
		CountrySX,
		CountrySY,
		CountrySZ,
		CountryTC,
		CountryTD,
		CountryTF,
		CountryTG,
		CountryTH,
		CountryTJ,
		CountryTK,
		CountryTL,
		CountryTM,
		CountryTN,
		CountryTO,
		CountryTR,
		CountryTT,
		CountryTV,
		CountryTW,
		CountryTZ,
		CountryUA,
		CountryUG,
		CountryUM,
		CountryUS,
		CountryUY,
		CountryUZ,
		CountryVA,
		CountryVC,
		CountryVE,
		CountryVG,
		CountryVI,
		CountryVN,
		CountryVU,
		CountryWF,
		CountryWS,
		CountryYE,
		CountryYT,
		CountryZA,
		CountryZM,
		CountryZW,
		CountryNone:
		return c, nil
	default:
		return CountryNone, &NotACountryError{Code: s}
	}
}

// type check
var _ encoding.TextUnmarshaler = (*Country)(nil)

// UnmarshalText implements the encoding.TextUnmarshaler interface for *Country.
func (c *Country) UnmarshalText(b []byte) (err error) {
	if c == nil {
		return errors.Error("nil country")
	}

	ctry, err := NewCountry(string(b))
	if err != nil {
		return fmt.Errorf("decoding country: %w", err)
	}

	*c = ctry

	return nil
}

// isUserAssigned returns true if s is a user-assigned ISO 3166-1 alpha-2
// country code.
func isUserAssigned(s string) (ok bool) {
	if len(s) != 2 {
		return false
	}

	if s[0] == 'X' || (s[0] == 'Q' && s[1] >= 'M') {
		return true
	}

	switch s {
	case "AA", "OO", "ZZ":
		return true
	default:
		return false
	}
}
