#ifndef ELECTRIC_WIRING_HPP_
#define ELECTRIC_WIRING_HPP_

#include <memory>
#include <vector>

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

/**
 * @brief Defines the electric wiring system.
 */
class ElectricWiring : public Wiring
{
private:
    std::vector<std::shared_ptr<ElectricLink>> 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 electric wiring node from serialized data.
     */
    ElectricWiring(const uint8_t *data, size_t size);

    /**
     * @brief Get the electric link, starting at the specified port.
     */
    std::shared_ptr<ElectricLink> 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