#include <SmeltingRule/DustSmeltingRule/DustSmeltingRule.hpp>
#include <ItemRegistry/ItemRegistry.hpp>

bool DustSmeltingRule::canSmelt(ItemStack &stack)
{
    if (stack.isEmpty())
    {
        return false;
    }
    
    std::string inputName = stack.getItem()->name;
    if (inputName.size() < 5)
    {
        return false;
    }

    if (inputName.substr(inputName.size()-4, 4) != "Dust")
    {
        return false;
    }

    std::string outputName = inputName.substr(0, inputName.size()-4) + "Ingot";
    return itemRegistry.getItemByName(outputName) != nullptr;
}

ItemStack DustSmeltingRule::getSmeltingResult(ItemStack &input)
{
    return ItemStack(input.getItem()->name.substr(0, input.getItem()->name.size()-4) + "Ingot");
}