#include <Milestone/BrickByBrickMilestone/BrickByBrickMilestone.hpp>
#include <Milestone/DripMilestone/DripMilestone.hpp>
#include <BlockRegistry/BlockRegistry.hpp>
#include <GraphicsContext/GraphicsContext.hpp>
#include <Material/Material.hpp>
#include <Milestone/CarpentryMilestone/CarpentryMilestone.hpp>
#include <Color/Color.hpp>
#include <Milestone/ElectronicsMilestone/ElectronicsMilestone.hpp>
#include <Milestone/MetalWorkingMilestone/MetalWorkingMilestone.hpp>
#include <sstream>

const std::string DripMilestone::ID = "main:Drip";

DripMilestone::DripMilestone() :
    Milestone(
        blockRegistry.getBlockByName("main:agaricMushroom").iconMaterial,
        blockRegistry.getBlockByName("main:agaricMushroom").iconMaterial,
        "Drip"
    )
{
    std::stringstream ss;
    blockRegistry.forEachBlock([&ss](Block &block)
    {
        if (block.isSuffixed("Mushroom"))
        {
            ss << "*{block|" << block.name << "}" << std::endl;
        }
    });

    addAchievement(
        CollectMushroom,
        blockRegistry.getBlockByName("main:agaricMushroom").iconMaterial,
        blockRegistry.getBlockByName("main:agaricMushroom").iconMaterial,
        "Collect a mushroom",
        formatString(
            "*Find one of the mushrooms on the floor of a forest:\n"
            "$+"
            "*Click and hold it to dig it.\n"
            "*Approach the mushroom to collect it.\n",
            ss.str()
        )
    );

    ss.clear();
    ss.str("");
    blockRegistry.forEachBlock([&ss](Block &block)
    {
        if (block.isSuffixed("Mushroom"))
        {
            ss << "@manualConstruct|main:mushroomLeather|1|" << block.name << "|16" << std::endl;
        }
    });

    addAchievement(
        MakeMushroomLeather,
        Material::mushroomLeather,
        Material::mushroomLeather,
        "Make mushroom leather",
        formatString(
            "*Collect 16 mushrooms of the same type.\n"
            "*Open your inventory.\n"
            "*Find {item|main:mushroomLeather} in the {menu|Construction} panel.\n"
            "*Click on {action|>>} to make it.\n"
            "$+",
            ss.str()
        ),
        Dependency{ID, CollectMushroom}
    );

    addAchievement(
        RunningShoes,
        Material::runningShoes,
        Material::runningShoes,
        "Running shoes",
        "*Construct {item|main:runningShoes}.\n"
        "@constructTable|main:runningShoes|1|main:mushroomLeather|16|main:rubber|4\n"
        "*Open your inventory.\n"
        "*Place the {item|main:runningShoes} in an {equipmentSlot} to {action|equip} it.\n"
        "*You will now be able to sprint faster, until the shoes wear out.\n",
        Dependency{ID, MakeMushroomLeather},
        Dependency{BrickByBrickMilestone::ID, BrickByBrickMilestone::MakeRubber},
        Dependency{CarpentryMilestone::ID, CarpentryMilestone::ConstructTable}
    );

    addAchievement(
        Backpack,
        Material::backpack,
        Material::backpack,
        "Backpacks",
        "*Construct a {item|main:backpack}.\n"
        "@constructTable|main:backpack|1|main:mushroomLeather|16|main:rubber|8\n"
        "*Open your inventory.\n"
        "*Place the {item|main:backpack} in an {equipmentSlot} to {action|equip} it.\n"
        "*You will now see the backpack's item slots in your inventory.\n",
        Dependency{ID, MakeMushroomLeather},
        Dependency{BrickByBrickMilestone::ID, BrickByBrickMilestone::MakeRubber},
        Dependency{CarpentryMilestone::ID, CarpentryMilestone::ConstructTable}
    );

    addAchievement(
        ConstructJetpack,
        Material::jetpack,
        Material::jetpack,
        "Construct the jetpack",
        "*Construct a {item|main:jetpack}.\n"
        "@engTable|main:jetpack|1|main:coil|16|main:goldIngot|4|main:steelIngot|16\n",
        Dependency{ElectronicsMilestone::ID, ElectronicsMilestone::EngineeringTable},
        Dependency{MetalWorkingMilestone::ID, MetalWorkingMilestone::MineGold}
    );

    addAchievement(
        EquipFuelledJetpack,
        Material::jetpack,
        Material::jetpack,
        "Fuel and equip a jetpack",
        "*Open a {machine|main:combustionGenerator} or {machine|main:steelBarrel} with petrol.\n"
        "*Place the {item|main:jetpack} in a {petrolSlot}.\n"
        "*Place the fuelled {item|main:jetpack} in an {equipmentSlot} to {action|equip} it.\n"
        "*Hold the jump key while mid-air to fly!\n",
        Dependency{ID, ConstructJetpack}
    );
}