#ifndef BASIC_TOOL_HPP_
#define BASIC_TOOL_HPP_

#include <Item/StatefulItem/StatefulItem.hpp>
#include <Item/ITool.hpp>
#include <Serialize/Serialize.hpp>
#include <World/World.hpp>

struct BasicToolState
{
    uint32_t uses;

    BasicToolState() : uses(0) {}
};

bool operator==(const BasicToolState &a, const BasicToolState &b);

DERIVE_STRUCT_SERIALIZER(BasicToolState, self.uses);

/**
 * @brief Base class for basic tools which take damage when used.
 */
class BasicTool : public StatefulItem<BasicToolState>, public ITool
{
private:
    Material &m_material;

    glm::vec4 getUsesColor(int uses);

protected:
    const uint32_t m_maxUses;

    /**
     * @brief Construct the basic tool.
     * 
     * @param name The item name.
     * @param maxUses Maximum number of uses.
     */
    BasicTool(std::string name, Material &mat, uint32_t maxUses);

    /**
     * @brief Get the reference to the number of times this was used. 
     * 
     * @param stack 
     * @return int& 
     */
    const uint32_t& uses(const ItemStack &stack);

    /**
     * @brief Get the reference to the number of times this was used. 
     * 
     * @param stack 
     * @return int& 
     */
    uint32_t& uses(ItemStack &stack);

public:
    virtual void draw(GraphicsContext &context, int x, int y, const ItemStack &stack) override;
    virtual void draw3D(GraphicsContext &context, WorldDisplay &worldDisplay, glm::vec3 pos, ItemStack &stack) override;
    virtual void drawFlat(GraphicsContext &context, WorldDisplay &worldDisplay, glm::mat4 matrix, ItemStack &stack) override;
    virtual void harvest(ItemStack &stack, LocalWorld &world, glm::ivec3 pos) override;
    virtual void getExtraToolTipLines(const ItemStack &stack, ToolTip &tip) override;
};

#endif