#ifndef ITEM_RECIPE_REGISTRY_HPP_
#define ITEM_RECIPE_REGISTRY_HPP_

#include <vector>
#include <ItemRecipe/ItemRecipe.hpp>

/**
 * @brief A registry of item recipes.
 */
class ItemRecipeRegistry
{
private:
    std::vector<ItemRecipe*> recipes;

    template<typename TRecipe = ItemRecipe, typename... TArgs>
    TRecipe* registerRecipe(ItemRecipe::Level level, ItemStack outputStack, TArgs... inputStacks)
    {
        uint32_t id = (uint32_t) recipes.size();
        TRecipe *recipe = new TRecipe(id, level, outputStack, inputStacks...);
        recipes.push_back(recipe);
        return recipe;
    }

public:
    /**
     * @brief Cleanup (call this just before exiting).
     */
    void shutdown();

    /**
     * @brief Register all recipes.
     */
    void registerAllRecipes();

    /**
     * @brief Return a list of item recipes which match a query.
     * 
     * @param maxLevel The maximum construction level allowed.
     * @param query The query.
     * @return A list of matching recipes.
     */
    std::vector<ItemRecipe*> search(ItemRecipe::Level maxLevel, std::string query);

    /**
     * @brief Get the recipe by ID.
     * 
     * @param id Recipe ID.
     * @return The item recipe, or `nullptr` if the ID is invalid.
     */
    ItemRecipe* getRecipeByID(uint32_t id);

    int getTotalRecipes();

    friend class ConstructionUsageProvider;
};

extern ItemRecipeRegistry itemRecipeRegistry;

#endif