#ifndef TREE_NODE_HPP
#define TREE_NODE_HPP

#include "Body.hpp"
#include "Box.hpp"
#include "Tree.hpp"
#include "BarnesHutTree.hpp"
#include <cstdlib>
#include <vector>

namespace nbody {
	using namespace std;

	class TreeNode {
		friend void Tree::clean();
		friend void BarnesHutTree::build(vector<Body> bodies);
		friend bool Tree::isCorrect();
		friend unsigned long Tree::numberOfNodes();
	protected:
		Box bb;
		vector<Body> bodies;
		TreeNode* prev;
		TreeNode* next;
		TreeNode* afterSubtree;
		bool leaf;
		Tree* tree;
		Body representative;
	public:
		TreeNode(Tree* tree);
		virtual ~TreeNode();
		virtual bool isSplitable();
		virtual void extendBBforBodies();
		virtual void extendBBtoCube();
		virtual Box getBB();
		virtual vector<Body> getBodies();
		virtual void insertBefore(TreeNode* node);
		virtual void insertAfter(TreeNode* node);
		virtual void unlink();
		virtual void update();
		virtual bool isCorrect();
		virtual void print();
	};
}

#endif
