#ifndef MINING_RIG_ENTITY_HPP_
#define MINING_RIG_ENTITY_HPP_

#include <Display/WidgetDisplay/WorldDisplay/WorldDisplay.hpp>
#include <Entity/Entity.hpp>
#include <BoundingBox/BoundingBox.hpp>
#include <GraphicsContext/GraphicsContext.hpp>
#include <Serialize/Serialize.hpp>
#include <VoxelSprite/VoxelSprite.hpp>

class MMiningRig;

/**
 * @brief An entity which displays the animation of the mining rig.
 */
class MiningRigEntity final : public Entity
{
private:
    std::weak_ptr<MMiningRig> rigMachine;
    glm::ivec3 machinePos;
    bool initialized = false;
    BoundingBox<int> drillAreaBB = {};
    glm::ivec3 drillPos = glm::ivec3(0);

    void drawElement(GraphicsContext &context, WorldDisplay &display, Model &model, glm::ivec3 pos);

public:
    enum class MessageType : uint8_t
    {
        Init = 0,
        Update = 1,
    };

    MiningRigEntity(
        World &world,
        std::string typeId,
        uint64_t id
    );

    MiningRigEntity(
        World &world,
        uint64_t id,
        glm::ivec3 machinePos
    );

    virtual void update() override;
    virtual void draw(GraphicsContext &context, WorldDisplay &display) override;
    virtual void onMessage(const void *msg, size_t size) override;
    virtual void serializeState(std::vector<uint8_t> &outBytes) override;
    virtual size_t deserializeState(const uint8_t *data, size_t size) override;
};

DERIVE_STATIC_CAST_SERIALIZER(MiningRigEntity::MessageType, uint8_t);

#endif