#ifndef DATA_WIRING_HPP_
#define DATA_WIRING_HPP_

#include <memory>
#include <vector>

#include <WorldComponent/Wiring/Wiring.hpp>
#include <DataLink/DataLink.hpp>

/**
 * @brief Defines the data wiring system.
 */
class DataWiring : public Wiring
{
private:
    std::vector<std::shared_ptr<DataLink>> links;
    bool linksCreatedYet = false;

    void updateFrom(LocalWorld &world, std::shared_ptr<WorldGridNode> node, std::vector<Port> &ports);

public:
    static size_t compIndex;
    static std::string compName;

    /**
     * @brief Construct an data wiring node from serialized data.
     */
    DataWiring(const uint8_t *data, size_t size);

    /**
     * @brief Get the data link, starting at the specified port.
     */
    std::shared_ptr<DataLink> getLink(
        LocalWorld &world,
        glm::ivec3 pos,
        Side side
    );

    virtual void onMachinePortsChanged(LocalWorld &world, std::shared_ptr<WorldGridNode> node, std::vector<Port> &ports) override;
    virtual bool isWalkableBlock(LocalWorld &world, int id) override;
    virtual std::string getDumpDirName() override;
};

#endif