<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Each entry: id => ISO 3166-1 alpha-2 country code.
     * '??' means the country could not be determined with confidence.
     *
     * Logic used:
     *  - Known airline name → country from public record
     *  - ICAO callsign prefix (where visible in data)
     *  - Organisation/government name (e.g. "Belgian Air Force" → BE)
     *  - "Blocked" placeholder rows → left as ?? (no real airline)
     */
    private array $map = [
        // ── A ──────────────────────────────────────────────────────────────
        1014 => '??', // Eastwest Airlines — multiple airlines use this name (AU/PH)
        1359 => '??', // ADV — no name, no data
        1383 => 'FR', // HOP!-AIRLINAIR — French regional carrier
        1388 => 'IT', // Air One Aviation — Italy
        1403 => 'VE', // Rutas Aereas de Venezuela RAV S.A — Venezuela
        1416 => 'BT', // Tashi Air — Bhutan
        1451 => 'CA', // Hawkair Aviation — Canada (BC)
        1473 => '??', // Air Inter Transport Co. Ltd. — unclear
        1507 => 'AR', // Tectimes Sudamericana S.A. — Argentina
        1510 => 'HR', // Trade Air Ltd. — Croatia
        1518 => 'US', // Conquest Air, Inc. — USA
        1524 => 'GB', // CHEP Aerospace Solutions Ltd. — UK
        1529 => 'LK', // Saffron Aviation (Pvt) Ltd dba Cinn Air — Sri Lanka
        1569 => 'CY', // Cobaltair Ltd — Cyprus
        1578 => 'TZ', // Coastal Travels Ltd. — Tanzania
        1581 => 'GB', // UBM Aviation - OAG — UK
        1632 => 'NO', // Norwegian Air Norway AS — Norway
        1654 => 'NG', // Dornier Aviation Nigeria AIEP Limit — Nigeria
        1658 => 'GB', // Air Direct Connect Ltd. — UK
        1676 => 'DO', // Dominican Wings. S.A. — Dominican Republic
        1691 => 'AT', // Eurowings Europe GmbH — Austria
        1696 => 'LA', // Sabaidee Airways dba New Gen — Laos
        1704 => 'CG', // Equaflight Service — Republic of Congo
        1749 => 'NL', // European Cargo Services BV — Netherlands
        1852 => 'NL', // Airshop B.V. — Netherlands
        1871 => '??', // S.A.C. — insufficient info
        1911 => 'GN', // Guinea Lineas Aereas — Guinea
        1935 => 'US', // Global Feeder Services, LLC — USA
        1951 => 'US', // Sky Lease I, Inc. — USA
        2023 => 'CA', // Harbour Air — Canada
        2029 => 'RU', // iFly Airlines — Russia
        2031 => 'HT', // Haiti Aviation — Haiti
        2035 => 'AM', // Taron Avia LLC — Armenia
        2041 => 'CL', // Chilejet S.A. — Chile
        2096 => 'SE', // Amapola Flyg AB — Sweden
        2137 => 'CI', // Ivoirienne de Transport Aerien — Côte d'Ivoire
        2159 => '??', // Airmax Airlines — unclear
        2171 => 'RU', // Sapsan Air / Irtysh Air — Russia
        2192 => 'US', // Intercontinental Airways (USA) — USA
        2200 => 'FR', // Michelin Air Services — France
        2219 => 'KH', // Apsara International — Cambodia
        2283 => 'JP', // Japan Air Commuter Co., Ltd. — Japan
        2327 => 'DK', // Jet Time A/S — Denmark
        2351 => 'KE', // DAC Aviation (EC) Ltd. — Kenya
        2353 => '??', // Skybus (KAL Aviation) — unclear
        2361 => 'ID', // Jatayu Air — Indonesia
        2491 => 'US', // American Capital Aviation — USA
        2494 => 'US', // Aviation Services & Support — USA
        2497 => 'VE', // Linea Aerea SAPSA — Venezuela
        2510 => 'US', // Bristow U.S. LLC — USA
        2525 => 'TZ', // Lion Air Cargo Tanzania Limited — Tanzania
        2527 => 'GY', // Laparkan Airways — Guyana
        2574 => 'US', // Pacific Wings — USA (Hawaii)
        2579 => 'CH', // Swiss Global Air Lines AG — Switzerland
        2583 => 'DE', // MHS Aviation GmbH — Germany
        2598 => 'PH', // Magnum Air dba Skyjet — Philippines
        2638 => 'US', // Mohawk Airlines — USA (historical)
        2648 => '??', // Mey-Air — insufficient info
        2680 => 'LB', // TMA Cargo — Lebanon (Trans Mediterranean Airways)
        2691 => 'ZA', // Nomad Aviation (PTY) Ltd. — South Africa
        2692 => 'FI', // Nordic Regional Airlines Oy — Finland
        2704 => 'NG', // Skypower Express Airways Ltd. — Nigeria
        2856 => 'AU', // FlyPelican — Australia
        2896 => 'PL', // Small Planet Airline Sp. Z.o.o — Poland
        2898 => 'PL', // Sprintair SA — Poland
        2929 => 'IN', // Vayudoot — India (historical)
        2947 => 'BS', // Southern Air Charter — Bahamas
        2965 => 'PH', // AirAsia Inc. — Philippines
        2989 => 'AI', // Anguilla Air Services, Ltd — Anguilla
        3019 => 'RU', // Dobrolet — Russia
        3033 => 'US', // Jet Airways Inc. — USA
        3038 => 'VE', // Linea Aerea De Servicio Ejecutivo Regional Laser — Venezuela
        3051 => '??', // Starlight Airline — insufficient info
        3055 => 'US', // North Eastern International — USA
        3057 => 'CZ', // SmartWings — Czech Republic
        3062 => 'CO', // Tampa Cargo S.A.S — Colombia
        3084 => '??', // Reliable Unique Services Aviation — insufficient info
        3094 => 'VE', // Sundance Air Venezuela S.A. — Venezuela
        3127 => '??', // Skyview Airways Company Limited — insufficient info
        3167 => 'CA', // 8165343 Canada Inc. dba Air Canada — Canada
        3187 => 'CR', // SANSA Regional — Costa Rica
        3191 => 'CR', // Servicios Aereos Nacionales S.A. SANSA — Costa Rica
        3198 => 'US', // Metro Air Northeast — USA
        3199 => 'US', // Brockway Air — USA
        3251 => 'TH', // Thai Lion Mentari Co., Ltd. — Thailand
        3257 => '??', // Sunshine Airlines — insufficient info
        3261 => 'TH', // Apex Airline Public Company Limited — Thailand
        3289 => 'GB', // AirTanker Services Limited — UK
        3291 => '??', // Fly Art — insufficient info
        3292 => 'CA', // Nakina Air Service — Canada (Ontario)
        3307 => 'MX', // MCS Aerocarga de Mexico — Mexico
        3317 => '??', // Master Aviation — insufficient info
        3358 => '??', // Jet 24 — insufficient info
        3458 => 'US', // Empire Airlines (1975) — USA
        3486 => 'VE', // Vensecar Internacional C.A. — Venezuela
        3499 => '??', // Clairmont Holdings dba VI Air — insufficient info
        3514 => '??', // Flylink Express — insufficient info
        3533 => 'IT', // CAI Second — Italy
        3564 => 'FR', // Air Vendee — France
        3576 => 'US', // Vintage Props & Jets — USA
        3638 => 'US', // Centurion Air Cargo, Inc. — USA
        3687 => 'US', // Midwest Airlines — USA
        3690 => 'PT', // Aero VIP Companhia Transportes Servicos Aere — Portugal
        3691 => 'US', // Midwest Airlines (duplicate) — USA
        3705 => 'RU', // Closed Joint Stock Company Red Wing — Russia
        3713 => 'US', // Air Excursion, LLC — USA
        3722 => 'US', // Exec Air, Inc. of Naples — USA (Florida)
        3726 => 'CL', // Airmax S.A. — Chile
        3732 => 'CA', // IATA - Montreal — Canada
        3737 => 'US', // Universal Air Travel Plan (UATP-Marketing) — USA
        3743 => 'US', // Delux Public Charter LLC — USA
        3763 => 'ID', // Xpressair — Indonesia
        3769 => 'US', // TEM Enterprises — USA
        3775 => 'ID', // Indonesia AirAsia Extra, PT — Indonesia
        3797 => 'CH', // Travel Technology Interactive SA — Switzerland
        3831 => 'CA', // Department of National Defence — Canada
        3832 => 'CN', // YTO Cargo Airlines Co. Ltd. — China
        3837 => 'CN', // Yunnan Ying'An Airlines — China
        3843 => 'CN', // Yunnan Yingan Airline Co., Ltd. — China
        3857 => 'MX', // Link Conexion Aerea S.A. de C.V — Mexico
        3878 => 'US', // PM Air LLC — USA
        3914 => 'US', // Air Routing International L.P. — USA
        3952 => 'RU', // Bashkortavia — Russia
        3953 => '??', // Sun Air — insufficient info (multiple carriers)

        // ── ICAO-only rows (no IATA code) ──────────────────────────────────
        4197 => 'BE', // Abelag Aviation — Belgium
        4206 => 'UA', // Alpha Air (Ukraine) — Ukraine
        4208 => 'US', // Air Aurora — USA
        4235 => '??', // Aeolus Air — insufficient info
        4270 => 'CA', // Exploits Valley Air Services — Canada (Newfoundland)
        4295 => 'US', // Nantucket Airlines — USA
        4303 => 'MX', // Aero Comondu — Mexico
        4309 => '??', // ASSL — insufficient info
        4313 => 'US', // Flight Line — USA
        4322 => '??', // Blocked
        4327 => 'UA', // Antonov Airlines — Ukraine
        4344 => 'DE', // Aero Dienst — Germany
        4368 => 'EE', // Airest — Estonia
        4377 => '??', // AEROTEC — insufficient info
        4413 => '??', // Blocked
        4443 => 'AO', // Angola Air Charter — Angola
        4460 => 'AZ', // AZAL Avia Cargo — Azerbaijan
        4488 => 'FR', // Airbus Industrie — France (Toulouse HQ)
        4504 => 'RU', // AIS Airlines (Russia) — Russia
        4569 => '??', // International Association Of Latin American Air Carriers — regional body
        4572 => 'US', // American Linehaul Corporation — USA
        4627 => '??', // Aerom — insufficient info
        4639 => 'BR', // ASTA Linhas Aereas — Brazil
        4646 => '??', // Amiyi Airlines — insufficient info
        4663 => 'DE', // Antares Airtransport — Germany
        4678 => 'GB', // OAG Computer — UK
        4681 => '??', // Aerolion International — insufficient info
        4705 => 'US', // Aeros Flight Training — USA
        4780 => 'ZA', // Aeronexus — South Africa
        4846 => 'AU', // Royal Australian Air Force — Australia
        4862 => 'AU', // Par Avion Airlines — Australia (Tasmania)
        4880 => 'DE', // Avanti Air GmbH — Germany
        4966 => 'NZ', // Airwork (NZ) — New Zealand
        4970 => 'NE', // Air Niamey S.A. — Niger
        4976 => 'JO', // Arab Wings — Jordan
        5040 => 'RU', // Azov-Avia — Russia
        5054 => 'GB', // BAe Systems — UK
        5057 => 'BE', // Belgian Air Force — Belgium
        5082 => 'UA', // Bravo Airways — Ukraine
        5095 => 'KZ', // Beibars — Kazakhstan
        5123 => 'DK', // BenAir — Denmark
        5127 => 'GB', // QinetiQ — UK
        5148 => '??', // Airnow — insufficient info
        5161 => 'IN', // Kingfisher Air Service — India
        5178 => '??', // BFS International — insufficient info
        5197 => '??', // Air Inter Transport — insufficient info
        5203 => 'NO', // Bergen Air Transport — Norway
        5214 => 'GB', // Bristow Helicopters — UK
        5227 => 'DE', // BinAir — Germany
        5339 => '??', // Sundance Air — insufficient info
        5347 => 'CA', // Alberni Airways — Canada (BC)
        5377 => 'ID', // Merpati Intan — Indonesia
        5389 => 'HU', // Base Kft — Hungary
        5401 => 'AU', // Star Air Cargo Pty — Australia
        5418 => 'RU', // AeroBratsk JSC — Russia
        5485 => '??', // Blocked
        5534 => '??', // Blocked
        5552 => '??', // Blocked
        5569 => '??', // Blocked
        5629 => 'CN', // Air China Cargo — China
        5648 => '??', // Blocked
        5683 => 'US', // Chipola Aviation — USA (Florida)
        5694 => 'CN', // China Flying Dragon Aviation — China
        5716 => 'MX', // Aereo Calafia — Mexico
        5718 => 'CN', // Zhongfei Airlines — China
        5723 => 'US', // Charlotte NC Air National Guard — USA
        5751 => 'CA', // Cougar Helicopters — Canada
        5758 => 'US', // Channel Islands Aviation — USA (California)
        5813 => 'NG', // Caverton Helicopters Ltd. — Nigeria
        5821 => 'US', // Aviation Charter Services — USA
        5839 => 'US', // Colemill Air Charter — USA
        5844 => 'GB', // Cello Aviation — UK
        5859 => '??', // Challenge Air — insufficient info
        5916 => 'CA', // Sunwest Aviation — Canada
        5956 => 'US', // ConocoPhillips — USA
        5959 => '??', // Blocked
        5983 => 'US', // Corpjet — USA
        5996 => 'US', // Corporate Air — USA
        6043 => '??', // Avia Carriers — insufficient info
        6075 => 'US', // Aero Charter and Transport — USA
        6084 => '??', // CTI - Container Transport International — insufficient info
        6093 => 'UZ', // Tashkent Aircraft Production — Uzbekistan
        6102 => 'BR', // PanAir Cargo — Brazil
        6106 => 'AR', // CATA Linea Aerea — Argentina
        6113 => 'MX', // Aero Cuahonte — Mexico
        6116 => 'ZA', // Court Helicopters — South Africa
        6132 => 'US', // ChevronTexaco Aircraft Operations — USA
        6146 => 'MH', // Air Marshall Islands — Marshall Islands
        6179 => '??', // Blocked
        6180 => '??', // Blocked
        6181 => '??', // Blocked
        6182 => '??', // Blocked
        6183 => '??', // Blocked
        6184 => '??', // Blocked
        6185 => '??', // Blocked
        6186 => '??', // Blocked
        6187 => '??', // Blocked
        6188 => '??', // Blocked
        6189 => '??', // Blocked
        6190 => '??', // Blocked
        6191 => '??', // Blocked
        6192 => '??', // Blocked
        6193 => '??', // Blocked
        6194 => '??', // Blocked
        6195 => '??', // Blocked
        6196 => '??', // Blocked
        6197 => '??', // Blocked
        6198 => '??', // Blocked
        6199 => '??', // Blocked
        6200 => '??', // Blocked
        6201 => '??', // Blocked
        6202 => '??', // Blocked
        6203 => '??', // Blocked
        6204 => '??', // Blocked
        6222 => 'NG', // Dornier Aviation Nigeria — Nigeria
        6250 => 'DE', // DC Aviation — Germany
        6253 => 'GB', // Directflight Limited — UK
        6257 => 'US', // Pentastar Aviation — USA
        6259 => '??', // Blocked
        6294 => '??', // Dasnair — insufficient info
        6320 => 'US', // Encore Air Cargo — USA
        6355 => '??', // Blocked
        6377 => '??', // Blocked
        6429 => 'AE', // Dubai Air Wing — UAE
        6431 => '??', // Aerotecnica — insufficient info
        6442 => 'AW', // Divi Divi Air N.V. — Aruba
        6455 => '??', // Blocked
        6463 => 'NZ', // Eagle Airways — New Zealand
        6475 => 'AU', // Eastern Australia Airlines — Australia
        6522 => '??', // Blocked
        6539 => '??', // Blocked
        6549 => 'AT', // Avanti Airlines — Austria
        6570 => '??', // Excellent Glide — insufficient info
        6601 => 'US', // Executive Jet Management — USA
        6665 => '??', // Blocked
        6691 => 'SI', // Express Airways d.o.o — Slovenia
        6694 => 'US', // Epps Air Service — USA
        6702 => 'MX', // Aerotaxis Tucan — Mexico
        6787 => 'DE', // EFS European Flight Service — Germany
        6790 => 'IT', // Evin-Evoluzionhndustriali — Italy
        6791 => 'BR', // Everjets Aviacao Executiva S.A. — Brazil
        6804 => 'AT', // Eurowings Europe — Austria
        6827 => '??', // Blocked
        6833 => 'DE', // Nightexpress — Germany
        6839 => '??', // Elytra Charter — insufficient info
        6847 => '??', // Blocked
        6859 => 'HU', // ASL Airlines Hungary — Hungary
        6865 => 'SE', // Falcon Air — Sweden
        6913 => 'FR', // SEFA — France
        6920 => 'AU', // Nav Air Charter — Australia
        6923 => '??', // Blocked
        6985 => 'RU', // Test Flight Aerographical Center — Russia
        7013 => 'US', // CitationAir — USA
        7024 => 'ZW', // Fastjet Zimbabwe — Zimbabwe
        7042 => 'ES', // Prestige Jet Spain — Spain
        7064 => 'US', // Flight Express — USA
        7065 => 'RU', // I-Fly — Russia
        7078 => 'IS', // Norlandair — Iceland
        7092 => '??', // Blocked
        7133 => 'US', // Freight Runners Express — USA
        7142 => 'NG', // FirstNation Airways — Nigeria
        7150 => 'US', // Farwest Airlines — USA
        7233 => '??', // Foxair — insufficient info
        7244 => 'BE', // Flying Service — Belgium
        7248 => '??', // Comfort Air — insufficient info
        7253 => 'BR', // Flyways Linhas Aereas — Brazil
        7255 => '??', // Blocked
        7268 => 'DE', // Luftwaffe — Germany
        7271 => 'RU', // Gromov Air — Russia
        7274 => 'VE', // Alianza Glancelot C.A. — Venezuela
        7329 => '??', // Blocked
        7421 => 'LY', // Ghadames Air — Libya
        7425 => 'DE', // German Sky Airlines — Germany
        7460 => '??', // Grivco International — insufficient info
        7479 => '??', // Tranzglobal — insufficient info
        7492 => '??', // Gloria — insufficient info
        7496 => '??', // General Corporation For Light Air Transport — insufficient info
        7502 => 'GB', // Gama Aviation — UK
        7514 => 'MX', // Magnicharters — Mexico
        7525 => '??', // Blocked
        7531 => '??', // Genex — insufficient info
        7551 => '??', // Waltair Europe — insufficient info
        7552 => '??', // Blocked
        7572 => 'BR', // Agroar Carga Aerea — Brazil
        7627 => '??', // An-2 — insufficient info
        7654 => '??', // Blocked
        7655 => 'RU', // V. Grizodubova Air Company — Russia
        7717 => '??', // Blocked
        7722 => '??', // Blocked
        7749 => 'GB', // Highland European — UK (Scotland)
        7802 => 'US', // Superior Aviation — USA
        7809 => 'US', // Hawkaire — USA
        7813 => 'NO', // CHC Helikopter Service — Norway
        7824 => 'FR', // Heli Securite — France
        7863 => '??', // Blocked
        7903 => '??', // Helistar — insufficient info
        7944 => 'US', // Grossman Air Service — USA
        7993 => 'RU', // Private Sky — Russia
        7995 => '??', // Blocked
        8036 => 'ES', // Ibertrans Aerea — Spain
        8050 => 'CA', // Kalair — Canada
        8053 => 'CA', // ICAO — Canada (Montreal HQ)
        8066 => '??', // Blocked
        8091 => 'US', // IFL Group — USA
        8096 => 'DE', // Interflight — Germany
        8125 => 'US', // InterJet West — USA
        8148 => 'RU', // Ilavia — Russia
        8180 => 'GR', // InterJet Hellenic — Greece
        8223 => '??', // Blocked
        8226 => 'US', // CSA Air — USA
        8240 => 'IR', // Eram Air — Iran
        8294 => '??', // Chavia — insufficient info
        8295 => '??', // Blocked
        8296 => 'IR', // Zagros Airlines — Iran
        8302 => 'AT', // Jetalliance Flugbetriebs — Austria
        8320 => 'CN', // Sino Jet (Beijing) — China
        8326 => 'US', // Jetcraft Aviation — USA
        8339 => '??', // Blocked
        8353 => 'FI', // Jetflite — Finland
        8363 => '??', // JS Aviation — insufficient info
        8368 => 'JP', // JAL Express — Japan
        8440 => '??', // Blocked
        8445 => 'US', // Journey Aviation — USA
        8451 => 'SE', // Jonair Affarsflyg AB — Sweden
        8503 => 'FI', // Jet Time Finland — Finland
        8544 => '??', // Blocked
        8570 => 'GM', // Gamair — Gambia
        8584 => '??', // Blocked
        8586 => 'US', // Makani Kai Air — USA (Hawaii)
        8614 => 'EG', // Alexandria Airlines — Egypt
        8617 => 'UA', // Aircompany KHORS — Ukraine
        8673 => '??', // Blocked
        8707 => 'NZ', // Kiwi Regional Airlines — New Zealand
        8725 => 'RU', // Kosmos Airlines — Russia
        8732 => '??', // UN Humanitarian Relief Flights (Kosovo) — international
        8737 => 'LT', // TransAviaBaltika — Lithuania
        8744 => 'RU', // Kotlas Air — Russia
        8784 => '??', // Blocked
        8788 => 'KZ', // Zhezair — Kazakhstan
        8810 => 'CO', // Lineas Aereas Suramericanas — Colombia
        8826 => 'US', // Quest Diagnostics — USA
        8846 => 'MX', // TAR Aerolineas — Mexico
        8850 => '??', // Blocked
        8883 => 'MX', // Aerolineas Ejecutivas — Mexico
        8933 => 'SI', // Limitless Airways d.o.o — Slovenia
        8948 => 'RU', // Luk Aero — Russia
        8988 => 'DE', // Small Planet Airlines Germany — Germany
        8990 => '??', // Let's Fly — insufficient info
        9018 => '??', // Blocked
        9020 => '??', // Links Air — insufficient info
        9027 => 'GB', // London Executive Aviation — UK
        9068 => 'RU', // Alrosa-Avia — Russia
        9080 => '??', // Airailes — insufficient info
        9146 => 'LU', // Luxaviation S.A. — Luxembourg
        9151 => 'US', // Flexjet — USA
        9158 => 'GB', // LyddAir — UK
        9168 => '??', // Blocked
        9186 => 'CA', // Morningstar Air Express — Canada
        9199 => 'GR', // Minoan Air S.A. — Greece
        9202 => '??', // Max Aviation — insufficient info
        9251 => '??', // Blocked
        9268 => '??', // Shervbery — insufficient info
        9290 => 'GB', // Merlin Airways — UK
        9301 => 'RO', // ICAR — Romania
        9365 => '??', // Blocked
        9386 => '??', // Air Majoro — insufficient info
        9403 => 'TW', // Makung Airlines — Taiwan
        9428 => 'MT', // Maleth Aero — Malta
        9472 => 'IT', // MiniLiner s.r.l. — Italy
        9474 => '??', // Blocked
        9553 => 'CN', // Minsheng International Jet — China
        9561 => '??', // Aeromas — insufficient info
        9589 => 'LV', // RAF-Avia — Latvia
        9614 => 'GB', // Harrods Aviation — UK
        9658 => 'EE', // SmartLynx Airlines Estonia — Estonia
        9660 => '??', // Blocked
        9664 => '??', // Mahfooz Aviation — insufficient info
        9672 => 'SI', // North Adria Aviation — Slovenia
        9685 => 'US', // NASA — USA
        9704 => 'CA', // North Cariboo Air — Canada
        9709 => 'NG', // Chanchangi Airlines — Nigeria
        9724 => '??', // Blocked
        9742 => 'NO', // Barents AirLink — Norway
        9775 => 'US', // Angel Flight America — USA
        9809 => '??', // Blocked
        9823 => 'PT', // NetJets Europe — Portugal (EASA cert)
        9862 => '??', // Blocked
        9863 => '??', // Blocked
        9864 => '??', // Blocked
        9865 => '??', // Blocked
        9866 => '??', // Blocked
        9867 => '??', // Blocked
        9868 => '??', // Blocked
        9869 => '??', // Blocked
        9870 => '??', // Blocked
        9871 => '??', // Blocked
        9872 => '??', // Blocked
        9873 => '??', // Blocked
        9874 => '??', // Blocked
        9875 => '??', // Blocked
        9876 => '??', // Blocked
        9877 => '??', // Blocked
        9878 => '??', // Blocked
        9879 => '??', // Blocked
        9880 => '??', // Blocked
        9881 => '??', // Blocked
        9882 => '??', // Blocked
        9883 => '??', // Blocked
        9884 => '??', // Blocked
        9885 => '??', // Blocked
        9886 => '??', // Blocked
        9887 => '??', // Blocked
        9916 => 'GB', // Atlantic Airlines — UK
        9923 => 'NL', // North Sea Airways — Netherlands
        9948 => 'CN', // Nanshan Jet — China
        9961 => 'ES', // Canarias Airlines — Spain (Canary Islands)
        9972 => 'JP', // Hokkaido Air System — Japan
        10020 => 'NO', // AirWing — Norway
        10022 => 'AU', // Network Aviation — Australia
        10040 => 'MW', // Ulendo Airlink — Malawi
        10041 => 'NZ', // Vincent Aviation Ltd. — New Zealand
        10043 => '??', // Blocked
        10045 => 'RU', // Alliance Avia — Russia
        10087 => '??', // Blocked
        10146 => 'PE', // CM Airlines — Peru
        10149 => '??', // Blocked
        10168 => 'US', // Flight Options — USA
        10184 => 'CA', // Orca Airways — Canada
        10239 => 'ES', // Aeronova — Spain
        10259 => '??', // Blocked
        10274 => 'CA', // Perimeter Aviation — Canada
        10280 => 'BR', // MAP Linhas Aereas — Brazil
        10282 => '??', // Blocked
        10294 => 'US', // Presidential Airways — USA
        10308 => 'WS', // Virgin Samoa — Samoa
        10310 => 'NZ', // Virgin Australia (NZ) — New Zealand
        10335 => 'US', // West Air (USA) — USA
        10347 => '??', // Blocked
        10352 => '??', // Blocked
        10357 => 'FR', // Pan Europeenne Air Service — France
        10372 => 'EG', // Petroleum Air Services — Egypt
        10429 => 'AM', // Phoenix Avia — Armenia
        10525 => '??', // Blocked
        10589 => 'US', // PARS Systems — USA
        10620 => '??', // S.A.P. — insufficient info
        10622 => 'RU', // Pskovavia — Russia
        10635 => 'DE', // PrivatAir Germany — Germany
        10647 => 'JO', // Air Arabia Jordan — Jordan
        10675 => 'US', // Privaira / Sky One Holdings — USA
        10678 => '??', // Blocked
        10680 => 'US', // Priester Aviation — USA
        10703 => '??', // Blocked
        10708 => '??', // Blocked
        10709 => '??', // Blocked
        10712 => 'QA', // Qatar Amiri Flight — Qatar
        10724 => '??', // Blocked
        10730 => 'UA', // Windrose Air — Ukraine
        10739 => '??', // Blocked
        10742 => 'NZ', // Jetconnect — New Zealand
        10744 => '??', // Blocked
        10746 => '??', // Blocked
        10747 => '??', // Blocked
        10752 => 'CA', // Gouvernement Du Quebec — Canada
        10759 => '??', // Blocked
        10765 => 'JP', // Ryukyu Air Commuter — Japan
        10798 => 'US', // Rosenbalm Aviation — USA
        10799 => '??', // Royal Air Charter — insufficient info
        10862 => 'US', // Package Express, Inc. — USA
        10863 => '??', // Blocked
        10870 => 'RU', // Adygheya Avia — Russia
        10882 => '??', // Blocked
        10911 => '??', // Blocked
        10949 => 'ES', // Cygnus Air — Spain
        10968 => 'AR', // Ariella Airlines S.A. — Argentina
        10972 => 'LV', // Riga Airlines — Latvia
        10980 => 'BR', // Rio Linhas Aereas — Brazil
        11009 => 'NZ', // Air Nelson — New Zealand
        11017 => '??', // AirNow — insufficient info
        11019 => '??', // S-Air — insufficient info
        11056 => '??', // Blocked
        11090 => 'US', // Republic Airlines — USA
        11102 => '??', // Blocked
        11107 => '??', // Blocked
        11131 => 'ES', // Canarias Airlines — Spain
        11136 => 'AE', // SNAS Aviation — UAE
        11154 => '??', // Blocked
        11155 => '??', // Blocked
        11168 => '??', // Blocked
        11175 => '??', // Blocked
        11223 => 'AU', // Rex Regional Express — Australia
        11227 => 'MA', // RAM Express — Morocco
        11242 => 'ZW', // Royal Zimbabwe Airlines — Zimbabwe
        11243 => '??', // Blocked
        11250 => 'US', // Crossroads Aviation — USA
        11316 => 'FI', // Snowbird Airlines Oy — Finland
        11351 => '??', // Blocked
        11463 => 'TR', // Saga Airlines — Turkey
        11466 => 'GB', // Shell Aircraft — UK
        11481 => 'GB', // British Airways Shuttle — UK
        11491 => 'BR', // Sideral Linhas Aereas — Brazil
        11509 => 'IT', // Sirio — Italy
        11512 => 'RU', // Salair — Russia
        11530 => 'US', // Sun Jet International Airlines — USA
        11535 => 'CN', // Sino Jet — China
        11557 => 'CA', // Skycharter — Canada
        11563 => 'US', // LabCorp — USA
        11580 => 'CZ', // Silver Air — Czech Republic
        11590 => 'CA', // Skylink Aviation — Canada
        11610 => 'BR', // SETE Linhas Aereas — Brazil
        11648 => 'DE', // Senator Aviation Charter — Germany
        11664 => 'IT', // Servizi Aerei — Italy
        11666 => '??', // Blocked
        11700 => 'SI', // Solinair — Slovenia
        11701 => '??', // Blocked
        11739 => 'GB', // Speedwings — UK
        11748 => 'SG', // Singapore Airlines Cargo — Singapore
        11778 => 'PL', // Sprint Air — Poland
        11792 => '??', // Star Of Asia — insufficient info
        11801 => 'SK', // Slovak Government Flying Service — Slovakia
        11813 => 'AU', // Sunstate Airlines — Australia
        11839 => '??', // Starwings International — insufficient info
        11875 => 'PL', // Silesia Air — Poland
        11877 => 'US', // Suburban Air Freight — USA
        11909 => '??', // Blocked
        11914 => 'SE', // Swedish Air Force — Sweden
        11935 => 'LU', // Global Jet Luxembourg — Luxembourg
        11958 => 'CH', // Swiss Global Air Lines — Switzerland
        12010 => 'ZA', // South African Historic Flight — South Africa
        12016 => '??', // Blocked
        12032 => 'US', // TAG Aviation USA — USA
        12034 => 'PF', // Air Moorea — French Polynesia
        12054 => 'ES', // Air Iberia — Spain
        12072 => 'IR', // ATA Airlines — Iran
        12096 => '??', // Blocked
        12100 => '??', // Tadair — insufficient info
        12146 => 'KG', // Tez Jet — Kyrgyzstan
        12150 => '??', // Blocked
        12176 => 'CA', // Transport Canada — Canada
        12198 => 'CA', // Thunder Airlines — Canada
        12225 => 'AT', // Tyrolean Jet Service — Austria
        12234 => 'RU', // Tretyakovo Air Transport — Russia
        12259 => 'ES', // Top Fly — Spain
        12302 => '??', // Blocked
        12352 => 'MX', // TAPSA Aviacion — Mexico
        12419 => 'RU', // Trast — Russia
        12445 => 'BR', // Total Linhas Aereas — Brazil
        12456 => '??', // Blocked
        12463 => 'US', // Yute Air Alaska — USA
        12476 => 'RU', // Tupolev-Aerotrans — Russia
        12507 => 'FR', // Twinjet Aviation — France
        12536 => 'US', // Texstar Air Freight — USA
        12547 => 'AT', // Tyrol Air Ambulance — Austria
        12550 => '??', // Blocked
        12572 => 'UA', // Aviant — Ukraine
        12578 => 'UA', // Antonov Airtrack — Ukraine
        12601 => '??', // Blocked
        12621 => 'RU', // Shar Ink — Russia
        12637 => 'UA', // Ukraine Air Alliance — Ukraine
        12673 => '??', // Blocked
        12674 => '??', // United Nations — international body
        12689 => 'UA', // Ukrainian Pilot School — Ukraine
        12701 => 'AM', // Avia-Urartu — Armenia
        12710 => 'US', // AirNet — USA
        12740 => '??', // Blocked
        12751 => 'CA', // Voyageur Airways — Canada
        12755 => 'TH', // Phuket Air — Thailand
        12792 => '??', // Blocked
        12803 => 'VE', // Aeroejecutivos — Venezuela
        12831 => 'GB', // Virgin Atlantic International — UK
        12839 => 'RU', // Vologda Air Company — Russia
        12848 => 'DE', // Vibro Air Flugservice — Germany
        12911 => '??', // Blocked
        12926 => 'UA', // Veteran Airlines — Ukraine
        12929 => 'UA', // Veteran Air — Ukraine
        12949 => '??', // Vertir Airlines — insufficient info
        12970 => 'SI', // Aviostart — Slovenia
        12979 => 'RU', // Vostok Airlines — Russia
        12981 => 'MX', // Aeronaves TSM — Mexico
        13020 => '??', // Blocked
        13025 => 'GN', // Guinea Airlines — Guinea
        13041 => 'US', // World Atlantic Airlines — USA
        13069 => '??', // Blocked
        13074 => 'DE', // WDL Aviation — Germany
        13088 => '??', // Pronto Airways — insufficient info
        13098 => 'US', // Vacation Express Public Charter — USA
        13121 => 'US', // Wiggins Airways — USA
        13122 => 'NZ', // Waikato Aero Club — New Zealand
        744  => 'CA', // Hydro-Quebec — Canada
        749  => 'GB', // British Airways Cargo — UK
        750  => 'SG', // Sabre Asia Pacific Pte. Ltd. — Singapore
        759  => 'GB', // Travelport International Operations — UK
        760  => 'TW', // Eva Airways Cargo — Taiwan
        761  => 'KR', // Asiana Airways Cargo — South Korea
        762  => 'RU', // JSC Sirena-Travel — Russia
        772  => 'HK', // Dragonair Cargo — Hong Kong
        798  => '??', // GETS Marketing Company — insufficient info
        806  => 'AL', // Albawings — Albania
        808  => 'FR', // SNCF — France
        816  => 'US', // Smokey Bay Air — USA (Alaska)
        825  => 'BE', // Thalys International — Belgium
        832  => '??', // Karlog Air — insufficient info
        839  => '??', // Redemption Inc. — insufficient info
        840  => '??', // Redemption Inc. — insufficient info
        865  => 'US', // Amtrak — USA
        878  => 'US', // Kenosha Aero dba Alliance Air — USA
        879  => 'HK', // Chu Kong Passenger Transport — Hong Kong
        893  => 'DE', // Dokasch GmbH — Germany
        906  => 'MY', // Gading Sari Aviation Sdn Bhd — Malaysia
        928  => 'DE', // Conatact Air — Germany
        932  => 'MW', // Malawian Airlines — Malawi
        934  => '??', // Premier Trans Aire — insufficient info
        944  => 'US', // Aerodynamics, Inc. — USA
        967  => 'GE', // Georgian International Airlines — Georgia
        970  => '??', // Air Besit — insufficient info
        975  => 'US', // Island Air — USA (Hawaii)
        1005 => 'US', // Mercury Air Cargo, Inc. — USA
        1006 => 'US', // Mercury World Cargo — USA
        1025 => 'KE', // Five Fourty Aviation Limited — Kenya
        1027 => 'ES', // Alsa Grupo SLU — Spain
        1035 => '??', // ACM Air Charter — insufficient info
        1049 => 'VE', // Rutas Aereas, C.A. — Venezuela
        1066 => 'AT', // WESTbahn Management GmbH — Austria
        1080 => 'ID', // PT. Pelita Air — Indonesia
        1081 => 'SK', // Travel Service Slovensko s.r.o. — Slovakia
        1103 => '??', // Zacarias Moreno — insufficient info
        1111 => '??', // Gryphon Airlines — insufficient info
        1120 => 'RU', // Alrosa Air — Russia
        1122 => 'RU', // Open Joint Stock Company ALROSA — Russia
        1130 => 'TC', // Turks Air — Turks and Caicos
        1137 => 'ES', // Auto Res S.L.U. dba Avanza Group — Spain
        1156 => '??', // MGC Aviation — insufficient info
        1165 => 'US', // CSafe Global — USA
        1175 => 'HU', // Travel Service Legiforgalmi — Hungary
        1187 => 'EC', // Aero Express del Ecuador — Ecuador
        1190 => 'US', // Alpha Air Transport — USA
        1204 => 'US', // Ameristar Air Cargo, Inc. — USA
        1205 => '??', // Skylanes — insufficient info
        1208 => 'PA', // Panama Airways — Panama
        1237 => '??', // Regional Air Services — insufficient info
        1241 => 'CA', // West Coast Air — Canada (BC)
        1250 => 'CA', // Air Tindi — Canada (NWT)
        1254 => 'SR', // Fly All Ways — Suriname
        1258 => 'SR', // Fly Always N.V. — Suriname
        1269 => 'CA', // AccesRail and Partner Railways — Canada
        1281 => 'GB', // Eurostar International Limited — UK
        1284 => 'GB', // 9G Rail Limited — UK
        1299 => '??', // West Link Airlines — insufficient info
        1301 => '??', // West Link Airways — insufficient info
        1310 => '??', // The Cargo Flights Co. — insufficient info
        1323 => 'TR', // ACT Havayollari A.S. — Turkey
        1338 => '??', // National Airways — insufficient info (multiple carriers)
        1340 => 'AR', // Macair Jet S.A. — Argentina
    ];

    public function up(): void
    {
        DB::table('countries')->insert([
            'code'         => '??',
            'name'         => '??',
            'continent_id' => 1,
        ]);

        DB::table('airlines')->where('country_code', 'AN')->update(['country_code' => 'CW']);
        DB::table('airlines')->where('country_code', 'AX')->update(['country_code' => 'FI']);
        DB::table('airlines')->where('country_code', 'CS')->update(['country_code' => 'RS']);
        DB::table('airlines')->where('country_code', 'UK')->update(['country_code' => 'GB']);
        DB::table('airlines')->where('country_code', 'YU')->update(['country_code' => 'RS']);
        DB::table('airlines')->where('country_code', 'ZR')->update(['country_code' => 'CD']);

        foreach ($this->map as $id => $code) {

            DB::table('airlines')
                ->where('id', $id)
                ->whereNull('country_id')
                ->update(['country_code' => $code]);

        }

        DB::statement("
            UPDATE airlines a
            SET    country_id = c.id
            FROM   countries c
            WHERE  c.code = a.country_code
              AND  a.country_id IS NULL
              AND  a.country_code != ''
        ");

        Schema::table('airlines', function (Blueprint $table) {
            $table->dropColumn(['country_code', 'country_name']);
            $table->foreignId('country_id')->nullable(false)->change();
        });
    }

    public function down(): void
    {
        $ids = array_keys(array_filter($this->map, fn($code) => $code !== '??'));

        DB::table('airlines')
            ->whereIn('id', $ids)
            ->update(['country_code' => '']);
    }
};
