export type Country3LetterCode = (typeof countries)[keyof typeof countries];

export function alpha2ToAlpha3(key: string): Country3LetterCode | undefined {
  return ALPHA2_TO_ALPHA3[key.toUpperCase()];
}

export function alpha3ToAlpha2(key: string) {
  return ALPHA3_TO_ALPHA2[key.toUpperCase()];
}

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

export const countries = {
  AFGHANISTAN: 'AFG',
  ALAND_ISLANDS: 'ALA',
  ALBANIA: 'ALB',
  ALGERIA: 'DZA',
  AMERICAN_SAMOA: 'ASM',
  ANDORRA: 'AND',
  ANGOLA: 'AGO',
  ANGUILLA: 'AIA',
  ANTARCTICA: 'ATA',
  ANTIGUA_AND_BARBUDA: 'ATG',
  ARGENTINA: 'ARG',
  ARMENIA: 'ARM',
  ARUBA: 'ABW',
  AUSTRALIA: 'AUS',
  AUSTRIA: 'AUT',
  AZERBAIJAN: 'AZE',
  BAHAMAS: 'BHS',
  BAHRAIN: 'BHR',
  BANGLADESH: 'BGD',
  BARBADOS: 'BRB',
  BELARUS: 'BLR',
  BELGIUM: 'BEL',
  BELIZE: 'BLZ',
  BENIN: 'BEN',
  BERMUDA: 'BMU',
  BHUTAN: 'BTN',
  BOLIVIA: 'BOL',
  BONAIRE_SINT_EUSTATIUS_AND_SABA: 'BES',
  BOSNIA_AND_HERZEGOVINA: 'BIH',
  BOTSWANA: 'BWA',
  BOUVET_ISLAND: 'BVT',
  BRAZIL: 'BRA',
  BRITISH_INDIAN_OCEAN_TERRITORY: 'IOT',
  BRUNEI: 'BRN',
  BULGARIA: 'BGR',
  BURKINA_FASO: 'BFA',
  BURUNDI: 'BDI',
  CAPE_VERDE: 'CPV',
  CAMBODIA: 'KHM',
  CAMEROON: 'CMR',
  CANADA: 'CAN',
  CAYMAN_ISLANDS: 'CYM',
  CENTRAL_AFRICAN_REPUBLIC: 'CAF',
  CHAD: 'TCD',
  CHILE: 'CHL',
  CHINA: 'CHN',
  CHRISTMAS_ISLAND: 'CXR',
  COCOS_ISLANDS: 'CCK',
  COLOMBIA: 'COL',
  COMOROS: 'COM',
  CONGO: 'COG',
  DR_CONGO: 'COD',
  COOK_ISLANDS: 'COK',
  COSTA_RICA: 'CRI',
  IVORY_COAST: 'CIV',
  CROATIA: 'HRV',
  CUBA: 'CUB',
  CURACAO: 'CUW',
  CYPRUS: 'CYP',
  CZECH_REPUBLIC: 'CZE',
  DENMARK: 'DNK',
  DJIBOUTI: 'DJI',
  DOMINICA: 'DMA',
  DOMINICAN_REPUBLIC: 'DOM',
  ECUADOR: 'ECU',
  EGYPT: 'EGY',
  EL_SALVADOR: 'SLV',
  EQUATORIAL_GUINEA: 'GNQ',
  ERITREA: 'ERI',
  ESTONIA: 'EST',
  ESWATINI: 'SWZ',
  ETHIOPIA: 'ETH',
  FALKLAND_ISLANDS: 'FLK',
  FAROE_ISLANDS: 'FRO',
  FIJI: 'FJI',
  FINLAND: 'FIN',
  FRANCE: 'FRA',
  FRENCH_GUIANA: 'GUF',
  FRENCH_POLYNESIA: 'PYF',
  FRENCH_SOUTHERN_TERRITORIES: 'ATF',
  GABON: 'GAB',
  GAMBIA: 'GMB',
  GEORGIA: 'GEO',
  GERMANY: 'D<<',
  GHANA: 'GHA',
  GIBRALTAR: 'GIB',
  GREECE: 'GRC',
  GREENLAND: 'GRL',
  GRENADA: 'GRD',
  GUADELOUPE: 'GLP',
  GUAM: 'GUM',
  GUATEMALA: 'GTM',
  GUERNSEY: 'GGY',
  GUINEA: 'GIN',
  GUINEA_BISSAU: 'GNB',
  GUYANA: 'GUY',
  HAITI: 'HTI',
  HEARD_ISLAND_AND_MCDONALD_ISLANDS: 'HMD',
  VATICAN_CITY: 'VAT',
  HONDURAS: 'HND',
  HONG_KONG: 'HKG',
  HUNGARY: 'HUN',
  ICELAND: 'ISL',
  INDIA: 'IND',
  INDONESIA: 'IDN',
  IRAN: 'IRN',
  IRAQ: 'IRQ',
  IRELAND: 'IRL',
  ISLE_OF_MAN: 'IMN',
  ISRAEL: 'ISR',
  ITALY: 'ITA',
  JAMAICA: 'JAM',
  JAPAN: 'JPN',
  JERSEY: 'JEY',
  JORDAN: 'JOR',
  KAZAKHSTAN: 'KAZ',
  KENYA: 'KEN',
  KIRIBATI: 'KIR',
  NORTH_KOREA: 'PRK',
  SOUTH_KOREA: 'KOR',
  KUWAIT: 'KWT',
  KYRGYZSTAN: 'KGZ',
  LAOS: 'LAO',
  LATVIA: 'LVA',
  LEBANON: 'LBN',
  LESOTHO: 'LSO',
  LIBERIA: 'LBR',
  LIBYA: 'LBY',
  LIECHTENSTEIN: 'LIE',
  LITHUANIA: 'LTU',
  LUXEMBOURG: 'LUX',
  MACAO: 'MAC',
  MADAGASCAR: 'MDG',
  MALAWI: 'MWI',
  MALAYSIA: 'MYS',
  MALDIVES: 'MDV',
  MALI: 'MLI',
  MALTA: 'MLT',
  MARSHALL_ISLANDS: 'MHL',
  MARTINIQUE: 'MTQ',
  MAURITANIA: 'MRT',
  MAURITIUS: 'MUS',
  MAYOTTE: 'MYT',
  MEXICO: 'MEX',
  MICRONESIA: 'FSM',
  MOLDOVA: 'MDA',
  MONACO: 'MCO',
  MONGOLIA: 'MNG',
  MONTENEGRO: 'MNE',
  MONTSERRAT: 'MSR',
  MOROCCO: 'MAR',
  MOZAMBIQUE: 'MOZ',
  MYANMAR: 'MMR',
  NAMIBIA: 'NAM',
  NAURU: 'NRU',
  NEPAL: 'NPL',
  NETHERLANDS: 'NLD',
  NEW_CALEDONIA: 'NCL',
  NEW_ZEALAND: 'NZL',
  NICARAGUA: 'NIC',
  NIGER: 'NER',
  NIGERIA: 'NGA',
  NIUE: 'NIU',
  NORFOLK_ISLAND: 'NFK',
  NORTH_MACEDONIA: 'MKD',
  NORTHERN_MARIANA_ISLANDS: 'MNP',
  NORWAY: 'NOR',
  OMAN: 'OMN',
  PAKISTAN: 'PAK',
  PALAU: 'PLW',
  PALESTINE: 'PSE',
  PANAMA: 'PAN',
  PAPUA_NEW_GUINEA: 'PNG',
  PARAGUAY: 'PRY',
  PERU: 'PER',
  PHILIPPINES: 'PHL',
  PITCAIRN: 'PCN',
  POLAND: 'POL',
  PORTUGAL: 'PRT',
  PUERTO_RICO: 'PRI',
  QATAR: 'QAT',
  REUNION: 'REU',
  ROMANIA: 'ROU',
  RUSSIA: 'RUS',
  RWANDA: 'RWA',
  SAINT_BARTHELEMY: 'BLM',
  SAINT_HELENA_ASCENSION_AND_TRISTAN_DA_CUNHA: 'SHN',
  SAINT_KITTS_AND_NEVIS: 'KNA',
  SAINT_LUCIA: 'LCA',
  SAINT_MARTIN: 'MAF',
  SAINT_PIERRE_AND_MIQUELON: 'SPM',
  SAINT_VINCENT_AND_THE_GRENADINES: 'VCT',
  SAMOA: 'WSM',
  SAN_MARINO: 'SMR',
  SAO_TOME_AND_PRINCIPE: 'STP',
  SAUDI_ARABIA: 'SAU',
  SENEGAL: 'SEN',
  SERBIA: 'SRB',
  SEYCHELLES: 'SYC',
  SIERRA_LEONE: 'SLE',
  SINGAPORE: 'SGP',
  SINT_MAARTEN: 'SXM',
  SLOVAKIA: 'SVK',
  SLOVENIA: 'SVN',
  SOLOMON_ISLANDS: 'SLB',
  SOMALIA: 'SOM',
  SOUTH_AFRICA: 'ZAF',
  SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS: 'SGS',
  SOUTH_SUDAN: 'SSD',
  SPAIN: 'ESP',
  SRI_LANKA: 'LKA',
  SUDAN: 'SDN',
  SURINAME: 'SUR',
  SVALBARD_AND_JAN_MAYEN: 'SJM',
  SWEDEN: 'SWE',
  SWITZERLAND: 'CHE',
  SYRIAN_ARAB_REPUBLIC: 'SYR',
  TAIWAN: 'TWN',
  TAJIKISTAN: 'TJK',
  TANZANIA: 'TZA',
  THAILAND: 'THA',
  TIMOR_LESTE: 'TLS',
  TOGO: 'TGO',
  TOKELAU: 'TKL',
  TONGA: 'TON',
  TRINIDAD_AND_TOBAGO: 'TTO',
  TUNISIA: 'TUN',
  TURKEY: 'TUR',
  TURKMENISTAN: 'TKM',
  TURKS_AND_CAICOS_ISLANDS: 'TCA',
  TUVALU: 'TUV',
  UGANDA: 'UGA',
  UKRAINE: 'UKR',
  UNITED_ARAB_EMIRATES: 'ARE',
  UNITED_KINGDOM: 'GBR',
  UNITED_STATES: 'USA',
  UNITED_STATES_MINOR_OUTLYING_ISLANDS: 'UMI',
  URUGUAY: 'URY',
  UZBEKISTAN: 'UZB',
  VANUATU: 'VUT',
  VENEZUELA: 'VEN',
  VIET_NAM: 'VNM',
  VIRGIN_ISLANDS_BRITISH: 'VGB',
  VIRGIN_ISLANDS_US: 'VIR',
  WALLIS_AND_FUTUNA: 'WLF',
  WESTERN_SAHARA: 'ESH',
  YEMEN: 'YEM',
  ZAMBIA: 'ZMB',
  ZIMBABWE: 'ZWE',
  EUROPEAN_UNION: 'EUE',
  UNITED_NATIONS: 'UNO',
  COUNCIL_OF_EUROPE: 'XCE',
  INTERPOL: 'XPO',
  SMOM: 'XOM',
} as const;

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

const ALPHA3_TO_ALPHA2 = Object.fromEntries(
  Object.entries(ALPHA2_TO_ALPHA3).map(([k, v]) => [v, k])
) as Record<
  (typeof ALPHA2_TO_ALPHA3)[keyof typeof ALPHA2_TO_ALPHA3],
  keyof typeof ALPHA2_TO_ALPHA3
>;

export function getCountryISO2(key: string) {
  return alpha3ToAlpha2(key);
}
