#pragma once
#include <map>
#include "component.h"
#include "asset/asset.h"
namespace engineapi {
	class GameObject {
	protected:
		string mName;
		uint32_t mLayer = 0;
		GameObject* mParent = nullptr;
		vector<GameObject*> mChildren;
		std::multimap<ComponentType, Component*> mComponents = {};
	public:
		GameObject();
		~GameObject();
		void AddComponent(ComponentType type, Component* component);
		GameObject* GetParent() {
			return mParent;
		}
	public:
		template<class T>
		T* GetComponent();
	};
	template<class T>
	inline T* GameObject::GetComponent()
	{
		ComponentType type = T::GetType();
		auto iter = mComponents.find(type);
		if (iter != mComponents.end()) {
			return static_cast<T*> (iter->second);
		}
		else {
			return static_cast<T*> (nullptr);
		}
	}
};