/**
 * This file is for handling the Randomize Rupee Names enhancement
 */
#include <soh/OTRGlobals.h>
#include "soh/Enhancements/randomizer/randomizer.h"

extern "C" {
#include "variables.h"
}

static const char* englishRupeeNames[] = {
    "[P]",
    "Bad RNG Rolls",
    "Baht",
    "Bananas",
    "Beanbean Coins",
    "Beans",
    "Beli",
    "Bells",
    "Berries",
    "Bison Dollars",
    "Bitcoin",
    "Blue Essence",
    "Bolts",
    "Bones",
    "Boondollars",
    "Bottle Caps",
    "Bratwürste",
    "Bucks",
    "BugFrags",
    "Canadian Dollars",
    "Cards",
    "Cents",
    "Chaos Orbs",
    "Clams",
    "Coal",
    "Cocoa Beans",
    "Coins",
    "Cookies",
    "Copper",
    "Cor",
    "Cornflakes",
    "Credits",
    "Crimebucks",
    "Crystal Shards",
    "Cubits",
    "Cucumbers",
    "Dalmations",
    "Dampécoin",
    "Dark Elixir",
    "Darseks",
    "Dead Memes",
    "Diamonds",
    "Dimes",
    "Dinars",
    "DNA",
    "Doll Hairs",
    "Dollars",
    "Dollarydoos",
    "Dosh",
    "Doubloons",
    "Drakes",
    "Dwarfbucks",
    "ECU",
    "Elexit",
    "Emeralds",
    "Energon",
    "Eris",
    "Ether",
    "Euro",
    "Experience",
    "Extinction Points",
    "Floopies",
    "Flurbos",
    "FPS",
    "Friends",
    "Frog Coins",
    "Gald",
    "Gekz",
    "Gems",
    "Geo",
    "Gil",
    "Glimmer",
    "Glitches",
    "Gold",
    "Gold Dragons",
    "Goober Dollars",
    "Green Herbs",
    "Greg Siblings",
    "Grouses",
    "Gummybears",
    "Hell",
    "Hyrule Loaches",
    "Ice Traps",
    "ISK",
    "Jiggies",
    "KF7 Ammo",
    "Kinstones",
    "Kremcoins",
    "Kronor",
    "Leaves",
    "Lemmings",
    "Lien",
    "Lira",
    "Lumber",
    "Lungmen Dollars",
    "Macca",
    "Mana",
    "Mann Co. Keys",
    "Meat",
    "Meat Stacks",
    "Medaparts",
    "Meseta",
    "Mesetas",
    "Minerals",
    "Monopoly Money",
    "Moons",
    "Mora",
    "Mumbo Tokens",
    "Munny",
    "Mushrooms",
    "Mysteries",
    "Naira",
    "Neopoints",
    "Nickels",
    "Notes",
    "Nuyen",
    "Orbs",
    "Ore",
    "Pence",
    "Pix",
    "Pixels",
    "Plastyks",
    "Platinum",
    "Pokédollars",
    "Pokémon",
    "Poko",
    "Pokos",
    "Potch",
    "Pounds",
    "Power Pellets",
    "Primogems",
    "Rand",
    "Reais",
    "Refined Metal",
    "Remote Mines",
    "Retweets",
    "Rhinu",
    "Rials",
    "Rings",
    "Riot Points",
    "Riyals",
    "Robux",
    "Rubies",
    "Rubles",
    "Runite Ore",
    "Rupees",
    "Saint Quartz",
    "Sapphires",
    "Septims",
    "Shekels",
    "Shillings",
    "Silver",
    "Simoleons",
    "Smackaroos",
    "Social Credit",
    "Souls",
    "Spent Casings",
    "Spice",
    "Spondulicks",
    "Spoons",
    "Star Bits",
    "Star Chips",
    "Stars",
    "Stones of Jordan",
    "Store Credit",
    "Strawbs",
    "Studs",
    "Super Sea Snails",
    "Talent",
    "Teef",
    "Telecrystals",
    "Tiberium",
    "TokKul",
    "Toys",
    "Turnips",
    "Upvotes",
    "V-Bucks",
    "Vespene Gas",
    "Watts",
    "Widgets",
    "Won",
    "Woolongs",
    "World Dollars",
    "Wumpa Fruit",
    "Yen",
    "Yuan",
    "Zenny",
    "Zorkmids",
};

static const char* germanRupeeNames[] = { "Baht",
                                          "Baklava",
                                          "Bananen",
                                          "Bitcoin",
                                          "Bonbons",
                                          "Bonschen",
                                          "Brause UFOs",
                                          "Bucks",
                                          "Burek",
                                          "Cent",
                                          "Chickenwing",
                                          "Diamanten",
                                          "Dinar",
                                          "Diridari",
                                          "Dollar",
                                          "Draken",
                                          "ECU",
                                          "Eis",
                                          "Elexit",
                                          "Erz",
                                          "Erzbrocken",
                                          "Ethereum",
                                          "Euro",
                                          "EXP",
                                          "Fartcoin",
                                          "Forint",
                                          "Franken",
                                          "Freunde",
                                          "Geister",
                                          "Gil",
                                          "Gold",
                                          "Groschen",
                                          "Gulden",
                                          "Haribo",
                                          "Heller",
                                          "Juwelen",
                                          "Kapseln",
                                          "Karolin",
                                          "Kartoffeln",
                                          "Keks",
                                          "Kies",
                                          "Knete",
                                          "Knochen",
                                          "Knuspertaler",
                                          "Kohle",
                                          "Kraniche",
                                          "Kreuzer",
                                          "Kronen",
                                          "Kronkorken",
                                          "Lauchcoins",
                                          "Lira",
                                          "Mana",
                                          "Mark",
                                          "Monde",
                                          "Moos",
                                          "Naira",
                                          "Nugget",
                                          "Penunze",
                                          "Pesa",
                                          "Peso",
                                          "Pfandflaschen",
                                          "Pfennig",
                                          "Pfund",
                                          "Pillen",
                                          "Pilze",
                                          "Plastiks",
                                          "Pok\x96"
                                          "dollar",
                                          "Poster",
                                          "Puzzle",
                                          "Radieschen",
                                          "Rand",
                                          "Rappen",
                                          "Real",
                                          "Rial",
                                          "Riesennugget",
                                          "Riyal",
                                          "Rubine",
                                          "Rupien",
                                          "Saphire",
                                          "Schilling",
                                          "Schokobon",
                                          "Seelen",
                                          "Septime",
                                          "Shitcoin",
                                          "Smaragde",
                                          "Solana",
                                          "Sosis",
                                          "Steine",
                                          "Sterne",
                                          "Sternis",
                                          "Tael",
                                          "Taler",
                                          "Tokens",
                                          "Wagenchips",
                                          "Won",
                                          "Wumpas",
                                          "Yen",
                                          "Yuan",
                                          "Zenny",
                                          "M\x93use",
                                          "M\x9Enzen",
                                          "Kr\x9Bten",
                                          "D\x9Bner",
                                          "W\x9Erstchen",
                                          "Kn\x9B"
                                          "del",
                                          "R\x9Bsti",
                                          "H\x9Brnli",
                                          "R\x9E"
                                          "ebli",
                                          "K\x9B"
                                          "fte",
                                          "Bratw\x9E"
                                          "rste",
                                          "Br\x98"
                                          "tchen",
                                          "Gummib\x93"
                                          "ren",
                                          "Moorh\x9E"
                                          "hner" };

static const char* frenchRupeeNames[] = {
    "Anneaux",  "Baguettes",   "Balles",      "Bananes", "Bitcoin",    "Blés",     "Bling",   "Capsules",
    "Centimes", "Champignons", "Clochettes",  "Crédits", "Croissants", "Diamants", "Dollars", "Émeraudes",
    "Éthers",   "Étoiles",     "Euros",       "Florens", "Francs",     "Galds",    "Gils",    "Grouses",
    "Halos",    "Joyaux",      "Lunes",       "Mailles", "Munnies",    "Orbes",    "Orens",   "Pépètes",
    "Pièces",   "Plastyks",    "Pokédollars", "Pokémon", "Radis",      "Rubis",    "Zennies",
};

void BuildRupeeMessage(uint16_t* textId, bool* loadFromMessageTable) {
    CustomMessage msg =
        CustomMessage("You found [[color]][[amount]] [[rupee]]%w!", "Du hast [[color]][[amount]] [[rupee]]%w gefunden!",
                      "Vous obtenez [[color]][[amount]] [[rupee]]%w!");
    std::string color;
    std::string amount;
    CustomMessage rupee =
        CustomMessage(ShipUtils::RandomElement(englishRupeeNames), ShipUtils::RandomElement(germanRupeeNames),
                      ShipUtils::RandomElement(frenchRupeeNames));
    switch (*textId) {
        case TEXT_BLUE_RUPEE:
            color = "%b";
            amount = "5";
            break;
        case TEXT_RED_RUPEE:
            color = "%r";
            amount = "20";
            break;
        case TEXT_PURPLE_RUPEE:
            color = "%p";
            amount = "50";
            break;
        case TEXT_HUGE_RUPEE:
            color = "%y";
            amount = "200";
            break;
        default:
            assert(false);
            return;
    }
    msg.Replace("[[color]]", color);
    msg.Replace("[[amount]]", amount);
    msg.Replace("[[rupee]]", rupee);
    msg.AutoFormat();
    msg.LoadIntoFont();
    *loadFromMessageTable = false;
}

void RegisterRandomRupeeNames() {
    COND_ID_HOOK(OnOpenText, TEXT_BLUE_RUPEE,
                 IS_RANDO && CVarGetInteger(CVAR_RANDOMIZER_ENHANCEMENT("RandomizeRupeeNames"), 1), BuildRupeeMessage);
    COND_ID_HOOK(OnOpenText, TEXT_RED_RUPEE,
                 IS_RANDO && CVarGetInteger(CVAR_RANDOMIZER_ENHANCEMENT("RandomizeRupeeNames"), 1), BuildRupeeMessage);
    COND_ID_HOOK(OnOpenText, TEXT_PURPLE_RUPEE,
                 IS_RANDO && CVarGetInteger(CVAR_RANDOMIZER_ENHANCEMENT("RandomizeRupeeNames"), 1), BuildRupeeMessage);
    COND_ID_HOOK(OnOpenText, TEXT_HUGE_RUPEE,
                 IS_RANDO && CVarGetInteger(CVAR_RANDOMIZER_ENHANCEMENT("RandomizeRupeeNames"), 1), BuildRupeeMessage);
}

static RegisterShipInitFunc initFunc(RegisterRandomRupeeNames,
                                     { CVAR_RANDOMIZER_ENHANCEMENT("RandomizeRupeeNames"), "IS_RANDO" });