#pragma once

#include "AbstractVisualNode.h"

#include "ElectronicCircuit.h"

#include <unordered_map>

class WireNode;
class TerminalNode;
class LogicGateNode;
class Wire;
class CircuitElementNode;

class ElectronicCircuitNode : public AbstractVisualNode
{
public:
    ElectronicCircuitNode(const Transform& transform);

    virtual ~ElectronicCircuitNode();

    void setContent(ElectronicCircuit* content);

    void update(SceneInfo* sceneInfo);

private:
    void createOrUpdateGeometry(SceneInfo* sceneInfo);

    void buildWireConnections();

    ElectronicCircuit* mContent{ nullptr };
    bool mContentDirty{ true };

    std::vector<std::unique_ptr<TerminalNode> > mInputTerminalNodes;
    std::vector<std::unique_ptr<TerminalNode> > mOutputTerminalNodes;
    std::vector<std::unique_ptr<WireNode> > mWireNodes;
    std::vector<std::unique_ptr<LogicGateNode> > mLogicGateNodes;

    std::unordered_map<Wire*, CircuitElement*> mWireInputConnections;
    std::unordered_map<Wire*, CircuitElement*> mWireOutputConnections;

    std::unordered_map<CircuitElement*, CircuitElementNode*> mNodesForContent;
};
