<?php
namespace Core;

/**
 * ISO-3166-1 alpha-2 country code → ISO-4217 currency code (each country's
 * single most common/official currency). Used to turn an IP-resolved country
 * into a currency for subscription pricing lookups (see Pricing::resolveForOrg).
 *
 * Deliberately not exhaustive of every dependency/territory — unmapped codes
 * simply fall through to the platform's default currency.
 */
class CountryCurrency {
    private const MAP = [
        'US' => 'USD', 'CA' => 'CAD', 'MX' => 'MXN', 'BR' => 'BRL', 'AR' => 'ARS',
        'CL' => 'CLP', 'CO' => 'COP', 'PE' => 'PEN', 'VE' => 'VES', 'EC' => 'USD',
        'UY' => 'UYU', 'PY' => 'PYG', 'BO' => 'BOB', 'CR' => 'CRC', 'PA' => 'PAB',
        'GT' => 'GTQ', 'HN' => 'HNL', 'SV' => 'USD', 'NI' => 'NIO', 'DO' => 'DOP',
        'JM' => 'JMD', 'TT' => 'TTD', 'BS' => 'BSD', 'BB' => 'BBD', 'BZ' => 'BZD',
        'GY' => 'GYD', 'SR' => 'SRD', 'HT' => 'HTG', 'CU' => 'CUP',

        'GB' => 'GBP', 'IE' => 'EUR', 'FR' => 'EUR', 'DE' => 'EUR', 'ES' => 'EUR',
        'PT' => 'EUR', 'IT' => 'EUR', 'NL' => 'EUR', 'BE' => 'EUR', 'LU' => 'EUR',
        'AT' => 'EUR', 'FI' => 'EUR', 'GR' => 'EUR', 'CY' => 'EUR', 'MT' => 'EUR',
        'SK' => 'EUR', 'SI' => 'EUR', 'EE' => 'EUR', 'LV' => 'EUR', 'LT' => 'EUR',
        'HR' => 'EUR', 'CH' => 'CHF', 'NO' => 'NOK', 'SE' => 'SEK', 'DK' => 'DKK',
        'IS' => 'ISK', 'PL' => 'PLN', 'CZ' => 'CZK', 'HU' => 'HUF', 'RO' => 'RON',
        'BG' => 'BGN', 'RS' => 'RSD', 'BA' => 'BAM', 'MK' => 'MKD', 'AL' => 'ALL',
        'ME' => 'EUR', 'MD' => 'MDL', 'UA' => 'UAH', 'BY' => 'BYN', 'RU' => 'RUB',
        'TR' => 'TRY', 'GE' => 'GEL', 'AM' => 'AMD', 'AZ' => 'AZN',

        'NG' => 'NGN', 'GH' => 'GHS', 'KE' => 'KES', 'ZA' => 'ZAR', 'EG' => 'EGP',
        'TZ' => 'TZS', 'UG' => 'UGX', 'RW' => 'RWF', 'ET' => 'ETB', 'SN' => 'XOF',
        'CI' => 'XOF', 'ML' => 'XOF', 'BF' => 'XOF', 'BJ' => 'XOF', 'NE' => 'XOF',
        'TG' => 'XOF', 'GW' => 'XOF', 'CM' => 'XAF', 'GA' => 'XAF', 'CG' => 'XAF',
        'TD' => 'XAF', 'CF' => 'XAF', 'GQ' => 'XAF', 'MA' => 'MAD', 'DZ' => 'DZD',
        'TN' => 'TND', 'LY' => 'LYD', 'SD' => 'SDG', 'ZM' => 'ZMW', 'ZW' => 'ZWL',
        'MW' => 'MWK', 'MZ' => 'MZN', 'BW' => 'BWP', 'NA' => 'NAD', 'AO' => 'AOA',
        'CD' => 'CDF', 'SO' => 'SOS', 'DJ' => 'DJF', 'ER' => 'ERN', 'SS' => 'SSP',
        'BI' => 'BIF', 'MG' => 'MGA', 'MU' => 'MUR', 'SC' => 'SCR', 'LS' => 'LSL',
        'SZ' => 'SZL', 'GM' => 'GMD', 'GN' => 'GNF', 'SL' => 'SLL', 'LR' => 'LRD',
        'MR' => 'MRU', 'CV' => 'CVE', 'ST' => 'STN', 'KM' => 'KMF',

        'CN' => 'CNY', 'JP' => 'JPY', 'KR' => 'KRW', 'IN' => 'INR', 'PK' => 'PKR',
        'BD' => 'BDT', 'LK' => 'LKR', 'NP' => 'NPR', 'BT' => 'BTN', 'MM' => 'MMK',
        'TH' => 'THB', 'VN' => 'VND', 'PH' => 'PHP', 'MY' => 'MYR', 'SG' => 'SGD',
        'ID' => 'IDR', 'KH' => 'KHR', 'LA' => 'LAK', 'BN' => 'BND', 'TL' => 'USD',
        'MN' => 'MNT', 'KZ' => 'KZT', 'UZ' => 'UZS', 'TM' => 'TMT', 'TJ' => 'TJS',
        'KG' => 'KGS', 'AF' => 'AFN', 'HK' => 'HKD', 'TW' => 'TWD', 'MO' => 'MOP',
        'MV' => 'MVR',

        'AE' => 'AED', 'SA' => 'SAR', 'QA' => 'QAR', 'KW' => 'KWD', 'BH' => 'BHD',
        'OM' => 'OMR', 'JO' => 'JOD', 'LB' => 'LBP', 'IL' => 'ILS', 'PS' => 'ILS',
        'IQ' => 'IQD', 'IR' => 'IRR', 'YE' => 'YER', 'SY' => 'SYP',

        'AU' => 'AUD', 'NZ' => 'NZD', 'FJ' => 'FJD', 'PG' => 'PGK', 'WS' => 'WST',
        'TO' => 'TOP', 'VU' => 'VUV', 'SB' => 'SBD',
    ];

    public static function forCountry(?string $countryCode): ?string {
        if (!$countryCode) return null;
        return self::MAP[strtoupper($countryCode)] ?? null;
    }
}
