#include "DeerStudio/StudioAPI/Engine.h"
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
#include "DeerStudio/StudioAPI/Debug.h"

namespace Deer {
	void AngelScriptEngine::registerEngineFunctions() {
		scriptEngine->SetDefaultNamespace("Engine");
		REGISTER_GLOBAL_FUNC("void print(const string&in text)", StudioAPI::print);
		scriptEngine->SetDefaultNamespace("");

		scriptEngine->SetDefaultNamespace("Path");
		REGISTER_GLOBAL_FUNC("string getParent(const string&in path)", StudioAPI::getParentPath);
		REGISTER_GLOBAL_FUNC("string getParentName(const string&in path)", StudioAPI::getParentPathName);
		REGISTER_GLOBAL_FUNC("string getName(const string&in path)", StudioAPI::getPathName);
		REGISTER_GLOBAL_FUNC("array<string>@ divide(const string&in path)", StudioAPI::dividePath_angelscript);
		scriptEngine->SetDefaultNamespace("");
	}

	void AngelScriptEngine::registerEngineStructs() {
		AS_RET_CHECK(scriptEngine->RegisterInterface("Panel"));
		AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("Panel", "void render()"));

		AS_RET_CHECK(scriptEngine->RegisterInterface("Service"));

		AS_CHECK(scriptEngine->RegisterFuncdef("void Callback()"));
		AS_CHECK(scriptEngine->RegisterFuncdef("void AnyCallback(any@)"));

		AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunc(any@)"));
		AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunc(any@, any@)"));
	}

	void AngelScriptEngine::extractBaseTypes() {
		panelBaseType = scriptEngine->GetTypeInfoByDecl("Panel");
		serviceBaseType = scriptEngine->GetTypeInfoByDecl("Service");
		arrayStringBaseType = scriptEngine->GetTypeInfoByDecl("array<string>");
	}
} // namespace Deer