    {-|

    Currency names, symbols and codes.
    Reference:
    - https://www.xe.com/symbols
    - https://www.xe.com/currency

    -}

    {-# LANGUAGE OverloadedStrings    #-}

    module Hledger.Data.Currency (
      currencies,
      currencySymbolToCode,
      currencyCodeToSymbol,
    )
    where
    import Data.Map qualified as M
    import           Data.Text (Text)

    -- | An ISO 4217 currency code, like EUR. Usually three upper case letters.
    type CurrencyCode = Text

    -- | A traditional currency symbol, like $. Usually one character, sometimes more.
    -- Different from hledger's more general "CommoditySymbol" type.
    type CurrencySymbol = Text

    -- | Look for a ISO 4217 currency code corresponding to this currency symbol.
    --
    -- >>> currencySymbolToCode ""
    -- Nothing
    -- >>> currencySymbolToCode "$"
    -- Just "USD"
    currencySymbolToCode :: CurrencySymbol -> Maybe CurrencyCode
    currencySymbolToCode :: CurrencyCode -> Maybe CurrencyCode
    currencySymbolToCode CurrencyCode
    s = CurrencyCode -> Map CurrencyCode CurrencyCode -> Maybe CurrencyCode
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup CurrencyCode
    s Map CurrencyCode CurrencyCode
    currencyCodesBySymbol

    -- | Look for a currency symbol corresponding to this ISO 4217 currency code.
    --
    -- >>> currencyCodeToSymbol "CZK"  -- Just "Kč"
    -- Just "K\269"
    currencyCodeToSymbol :: CurrencyCode -> Maybe CurrencySymbol
    currencyCodeToSymbol :: CurrencyCode -> Maybe CurrencyCode
    currencyCodeToSymbol CurrencyCode
    c = CurrencyCode -> Map CurrencyCode CurrencyCode -> Maybe CurrencyCode
    forall k a. Ord k => k -> Map k a -> Maybe a
    M.lookup CurrencyCode
    c Map CurrencyCode CurrencyCode
    currencySymbolsByCode

    currencyCodesBySymbol :: Map CurrencyCode CurrencyCode
    currencyCodesBySymbol = [(CurrencyCode, CurrencyCode)] -> Map CurrencyCode CurrencyCode
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList [(CurrencyCode
    s,CurrencyCode
    c) | ([Char]
    _,CurrencyCode
    c,CurrencyCode
    s) <- [([Char], CurrencyCode, CurrencyCode)]
    currencies]
    currencySymbolsByCode :: Map CurrencyCode CurrencyCode
    currencySymbolsByCode = [(CurrencyCode, CurrencyCode)] -> Map CurrencyCode CurrencyCode
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList [(CurrencyCode
    c,CurrencyCode
    s) | ([Char]
    _,CurrencyCode
    c,CurrencyCode
    s) <- [([Char], CurrencyCode, CurrencyCode)]
    currencies]

    currencies :: [([Char], CurrencyCode, CurrencyCode)]
    currencies = [
      -- country and currency name           ISO 4217 code  symbol
      ([Char]
    "Albania Lek",                               CurrencyCode
    "ALL",  CurrencyCode
    "Lek"),
      ([Char]
    "Afghanistan Afghani",                       CurrencyCode
    "AFN",  CurrencyCode
    "؋"),
      ([Char]
    "Argentina Peso",                            CurrencyCode
    "ARS",  CurrencyCode
    "$"),
      ([Char]
    "Aruba Guilder",                             CurrencyCode
    "AWG",  CurrencyCode
    "ƒ"),
      ([Char]
    "Australia Dollar",                          CurrencyCode
    "AUD",  CurrencyCode
    "$"),
      ([Char]
    "Azerbaijan Manat",                          CurrencyCode
    "AZN",  CurrencyCode
    "₼"),
      ([Char]
    "Bahamas Dollar",                            CurrencyCode
    "BSD",  CurrencyCode
    "$"),
      ([Char]
    "Barbados Dollar",                           CurrencyCode
    "BBD",  CurrencyCode
    "$"),
      ([Char]
    "Belarus Ruble",                             CurrencyCode
    "BYN",  CurrencyCode
    "Br"),
      ([Char]
    "Belize Dollar",                             CurrencyCode
    "BZD",  CurrencyCode
    "BZ$"),
      ([Char]
    "Bermuda Dollar",                            CurrencyCode
    "BMD",  CurrencyCode
    "$"),
      ([Char]
    "Bolivia Bolíviano",                         CurrencyCode
    "BOB",  CurrencyCode
    "$b"),
      ([Char]
    "Bosnia and Herzegovina Convertible Mark",   CurrencyCode
    "BAM",  CurrencyCode
    "KM"),
      ([Char]
    "Botswana Pula",                             CurrencyCode
    "BWP",  CurrencyCode
    "P"),
      ([Char]
    "Bulgaria Lev",                              CurrencyCode
    "BGN",  CurrencyCode
    "лв"),
      ([Char]
    "Brazil Real",                               CurrencyCode
    "BRL",  CurrencyCode
    "R$"),
      ([Char]
    "Brunei Darussalam Dollar",                  CurrencyCode
    "BND",  CurrencyCode
    "$"),
      ([Char]
    "Cambodia Riel",                             CurrencyCode
    "KHR",  CurrencyCode
    "៛"),
      ([Char]
    "Canada Dollar",                             CurrencyCode
    "CAD",  CurrencyCode
    "$"),
      ([Char]
    "Cayman Islands Dollar",                     CurrencyCode
    "KYD",  CurrencyCode
    "$"),
      ([Char]
    "Chile Peso",                                CurrencyCode
    "CLP",  CurrencyCode
    "$"),
      ([Char]
    "China Yuan Renminbi",                       CurrencyCode
    "CNY",  CurrencyCode
    "¥"),
      ([Char]
    "Colombia Peso",                             CurrencyCode
    "COP",  CurrencyCode
    "$"),
      ([Char]
    "Costa Rica Colon",                          CurrencyCode
    "CRC",  CurrencyCode
    "₡"),
      ([Char]
    "Croatia Kuna",                              CurrencyCode
    "HRK",  CurrencyCode
    "kn"),
      ([Char]
    "Cuba Peso",                                 CurrencyCode
    "CUP",  CurrencyCode
    "₱"),
      ([Char]
    "Czech Republic Koruna",                     CurrencyCode
    "CZK",  CurrencyCode
    "Kč"),
      ([Char]
    "Denmark Krone",                             CurrencyCode
    "DKK",  CurrencyCode
    "kr"),
      ([Char]
    "Dominican Republic Peso",                   CurrencyCode
    "DOP",  CurrencyCode
    "RD$"),
      ([Char]
    "East Caribbean Dollar",                     CurrencyCode
    "XCD",  CurrencyCode
    "$"),
      ([Char]
    "Egypt Pound",                               CurrencyCode
    "EGP",  CurrencyCode
    "£"),
      ([Char]
    "El Salvador Colon",                         CurrencyCode
    "SVC",  CurrencyCode
    "$"),
      ([Char]
    "Euro Member Countries",                     CurrencyCode
    "EUR",  CurrencyCode
    "€"),
      ([Char]
    "Falkland Islands (Malvinas) Pound",         CurrencyCode
    "FKP",  CurrencyCode
    "£"),
      ([Char]
    "Fiji Dollar",                               CurrencyCode
    "FJD",  CurrencyCode
    "$"),
      ([Char]
    "Ghana Cedi",                                CurrencyCode
    "GHS",  CurrencyCode
    "¢"),
      ([Char]
    "Gibraltar Pound",                           CurrencyCode
    "GIP",  CurrencyCode
    "£"),
      ([Char]
    "Guatemala Quetzal",                         CurrencyCode
    "GTQ",  CurrencyCode
    "Q"),
      ([Char]
    "Guernsey Pound",                            CurrencyCode
    "GGP",  CurrencyCode
    "£"),
      ([Char]
    "Guyana Dollar",                             CurrencyCode
    "GYD",  CurrencyCode
    "$"),
      ([Char]
    "Honduras Lempira",                          CurrencyCode
    "HNL",  CurrencyCode
    "L"),
      ([Char]
    "Hong Kong Dollar",                          CurrencyCode
    "HKD",  CurrencyCode
    "$"),
      ([Char]
    "Hungary Forint",                            CurrencyCode
    "HUF",  CurrencyCode
    "Ft"),
      ([Char]
    "Iceland Krona",                             CurrencyCode
    "ISK",  CurrencyCode
    "kr"),
      ([Char]
    "India Rupee",                               CurrencyCode
    "INR",  CurrencyCode
    "₹"),
      ([Char]
    "Indonesia Rupiah",                          CurrencyCode
    "IDR",  CurrencyCode
    "Rp"),
      ([Char]
    "Iran Rial",                                 CurrencyCode
    "IRR",  CurrencyCode
    "﷼"),
      ([Char]
    "Isle of Man Pound",                         CurrencyCode
    "IMP",  CurrencyCode
    "£"),
      ([Char]
    "Israel Shekel",                             CurrencyCode
    "ILS",  CurrencyCode
    "₪"),
      ([Char]
    "Jamaica Dollar",                            CurrencyCode
    "JMD",  CurrencyCode
    "J$"),
      ([Char]
    "Japan Yen",                                 CurrencyCode
    "JPY",  CurrencyCode
    "¥"),
      ([Char]
    "Jersey Pound",                              CurrencyCode
    "JEP",  CurrencyCode
    "£"),
      ([Char]
    "Kazakhstan Tenge",                          CurrencyCode
    "KZT",  CurrencyCode
    "лв"),
      ([Char]
    "Korea (North) Won",                         CurrencyCode
    "KPW",  CurrencyCode
    "₩"),
      ([Char]
    "Korea (South) Won",                         CurrencyCode
    "KRW",  CurrencyCode
    "₩"),
      ([Char]
    "Kyrgyzstan Som",                            CurrencyCode
    "KGS",  CurrencyCode
    "лв"),
      ([Char]
    "Laos Kip",                                  CurrencyCode
    "LAK",  CurrencyCode
    "₭"),
      ([Char]
    "Lebanon Pound",                             CurrencyCode
    "LBP",  CurrencyCode
    "£"),
      ([Char]
    "Liberia Dollar",                            CurrencyCode
    "LRD",  CurrencyCode
    "$"),
      ([Char]
    "Macedonia Denar",                           CurrencyCode
    "MKD",  CurrencyCode
    "ден"),
      ([Char]
    "Malaysia Ringgit",                          CurrencyCode
    "MYR",  CurrencyCode
    "RM"),
      ([Char]
    "Mauritius Rupee",                           CurrencyCode
    "MUR",  CurrencyCode
    "₨"),
      ([Char]
    "Mexico Peso",                               CurrencyCode
    "MXN",  CurrencyCode
    "$"),
      ([Char]
    "Mongolia Tughrik",                          CurrencyCode
    "MNT",  CurrencyCode
    "₮"),
      ([Char]
    "Mozambique Metical",                        CurrencyCode
    "MZN",  CurrencyCode
    "MT"),
      ([Char]
    "Namibia Dollar",                            CurrencyCode
    "NAD",  CurrencyCode
    "$"),
      ([Char]
    "Nepal Rupee",                               CurrencyCode
    "NPR",  CurrencyCode
    "₨"),
      ([Char]
    "Netherlands Antilles Guilder",              CurrencyCode
    "ANG",  CurrencyCode
    "ƒ"),
      ([Char]
    "New Zealand Dollar",                        CurrencyCode
    "NZD",  CurrencyCode
    "$"),
      ([Char]
    "Nicaragua Cordoba",                         CurrencyCode
    "NIO",  CurrencyCode
    "C$"),
      ([Char]
    "Nigeria Naira",                             CurrencyCode
    "NGN",  CurrencyCode
    "₦"),
      ([Char]
    "Norway Krone",                              CurrencyCode
    "NOK",  CurrencyCode
    "kr"),
      ([Char]
    "Oman Rial",                                 CurrencyCode
    "OMR",  CurrencyCode
    "﷼"),
      ([Char]
    "Pakistan Rupee",                            CurrencyCode
    "PKR",  CurrencyCode
    "₨"),
      ([Char]
    "Panama Balboa",                             CurrencyCode
    "PAB",  CurrencyCode
    "B/."),
      ([Char]
    "Paraguay Guarani",                          CurrencyCode
    "PYG",  CurrencyCode
    "Gs"),
      ([Char]
    "Peru Sol",                                  CurrencyCode
    "PEN",  CurrencyCode
    "S/."),
      ([Char]
    "Philippines Peso",                          CurrencyCode
    "PHP",  CurrencyCode
    "₱"),
      ([Char]
    "Poland Zloty",                              CurrencyCode
    "PLN",  CurrencyCode
    "zł"),
      ([Char]
    "Qatar Riyal",                               CurrencyCode
    "QAR",  CurrencyCode
    "﷼"),
      ([Char]
    "Romania Leu",                               CurrencyCode
    "RON",  CurrencyCode
    "lei"),
      ([Char]
    "Russia Ruble",                              CurrencyCode
    "RUB",  CurrencyCode
    "₽"),
      ([Char]
    "Saint Helena Pound",                        CurrencyCode
    "SHP",  CurrencyCode
    "£"),
      ([Char]
    "Saudi Arabia Riyal",                        CurrencyCode
    "SAR",  CurrencyCode
    "﷼"),
      ([Char]
    "Serbia Dinar",                              CurrencyCode
    "RSD",  CurrencyCode
    "Дин."),
      ([Char]
    "Seychelles Rupee",                          CurrencyCode
    "SCR",  CurrencyCode
    "₨"),
      ([Char]
    "Singapore Dollar",                          CurrencyCode
    "SGD",  CurrencyCode
    "$"),
      ([Char]
    "Solomon Islands Dollar",                    CurrencyCode
    "SBD",  CurrencyCode
    "$"),
      ([Char]
    "Somalia Shilling",                          CurrencyCode
    "SOS",  CurrencyCode
    "S"),
      ([Char]
    "South Africa Rand",                         CurrencyCode
    "ZAR",  CurrencyCode
    "R"),
      ([Char]
    "Sri Lanka Rupee",                           CurrencyCode
    "LKR",  CurrencyCode
    "₨"),
      ([Char]
    "Sweden Krona",                              CurrencyCode
    "SEK",  CurrencyCode
    "kr"),
      ([Char]
    "Switzerland Franc",                         CurrencyCode
    "CHF",  CurrencyCode
    "CHF"),
      ([Char]
    "Suriname Dollar",                           CurrencyCode
    "SRD",  CurrencyCode
    "$"),
      ([Char]
    "Syria Pound",                               CurrencyCode
    "SYP",  CurrencyCode
    "£"),
      ([Char]
    "Taiwan New Dollar",                         CurrencyCode
    "TWD",  CurrencyCode
    "NT$"),
      ([Char]
    "Thailand Baht",                             CurrencyCode
    "THB",  CurrencyCode
    "฿"),
      ([Char]
    "Trinidad and Tobago Dollar",                CurrencyCode
    "TTD",  CurrencyCode
    "TT$"),
      ([Char]
    "Turkey Lira",                               CurrencyCode
    "TRY",  CurrencyCode
    "₺"),
      ([Char]
    "Tuvalu Dollar",                             CurrencyCode
    "TVD",  CurrencyCode
    "$"),
      ([Char]
    "Ukraine Hryvnia",                           CurrencyCode
    "UAH",  CurrencyCode
    "₴"),
      ([Char]
    "United Kingdom Pound",                      CurrencyCode
    "GBP",  CurrencyCode
    "£"),
      ([Char]
    "United States Dollar",                      CurrencyCode
    "USD",  CurrencyCode
    "$"),
      ([Char]
    "Uruguay Peso",                              CurrencyCode
    "UYU",  CurrencyCode
    "$U"),
      ([Char]
    "Uzbekistan Som",                            CurrencyCode
    "UZS",  CurrencyCode
    "лв"),
      ([Char]
    "Venezuela Bolívar",                         CurrencyCode
    "VEF",  CurrencyCode
    "Bs"),
      ([Char]
    "Viet Nam Dong",                             CurrencyCode
    "VND",  CurrencyCode
    "₫"),
      ([Char]
    "Yemen Rial",                                CurrencyCode
    "YER",  CurrencyCode
    "﷼"),
      ([Char]
    "Zimbabwe Dollar",                           CurrencyCode
    "ZWD",  CurrencyCode
    "Z$")
      ]

    -- tests_Currency = testGroup "Currency" []