#pragma once
#include "CrashBandicoot/Scene/CrashScene.h"
#include "Scenegraph/GameObject.h"
#include "Components/Components.h"
#pragma warning(push)
#pragma warning (disable:4996)
#pragma warning (disable:4244)
#pragma warning (disable:4458)
#pragma warning (disable:4267)
#include "csv.h"
#pragma warning(pop)

template 
class StaticObjectLoader
{
public:
	StaticObjectLoader(const std::string& filePath, CrashScene* scene);
	~StaticObjectLoader() = default;

	void LoadObjects();
private:
	std::string m_FilePath;
	CrashScene* m_pScene;

	// -------------------------
	// Disabling default copy constructor and default 
	// assignment operator.
	// -------------------------
	StaticObjectLoader(const StaticObjectLoader& obj) = delete;
	StaticObjectLoader& operator=(const StaticObjectLoader& obj) = delete;
};

template
inline StaticObjectLoader::StaticObjectLoader(const std::string& filePath, CrashScene * scene)
	:m_FilePath(filePath) ,m_pScene(scene)
{
}

template
inline void StaticObjectLoader::LoadObjects()
{
	io::CSVReader<7> in(m_FilePath);
	in.read_header(io::ignore_extra_column, "OvlX", "OvlY", "OvlZ", "OvlRotX", "OvlRotY", "OvlRotZ", "Idx");
	double posX, posY, posZ, rotX, rotY, rotZ;
	int idx;

	while(in.read_row(posX, posY, posZ, rotX, rotY, rotZ, idx))
	{
		T* object = new T(idx);
		static_cast(object)->GetTransform()->Translate(float(posX), float(posY), float(posZ));
		static_cast(object)->GetTransform()->Rotate(float(rotX), float(rotY), float(rotZ), false);
		m_pScene->AddChild(object);
	}
}