// Copyright (c) 2024 Codemongous LLC. All Rights Reserved.

#include "SCW_USimpleConstructionScript.h"
#include "Engine/SimpleConstructionScript.h"
#include "SCW_USCS_Node.h"
#include "SourcifyCoreUEWrapperModule.h"

using namespace Sourcify;

SCW_USimpleConstructionScript::SCW_USimpleConstructionScript(USimpleConstructionScript* InSimpleConstructionScript) : SCW_UObject(InSimpleConstructionScript), SimpleConstructionScript(InSimpleConstructionScript)
{

}

USimpleConstructionScript* SCW_USimpleConstructionScript::ToUSimpleConstructionScript() const
{
	return SimpleConstructionScript;
}

ISCW_USimpleConstructionScriptPtr SCW_USimpleConstructionScript::ToUSimpleConstructionScriptPtr()
{
	return GetSharedThisAs<SCW_USimpleConstructionScript>();
}

ISCW_USimpleConstructionScriptConstPtr SCW_USimpleConstructionScript::ToUSimpleConstructionScriptPtr() const
{
	return GetSharedThisAs<SCW_USimpleConstructionScript>();
}

ISCW_USCS_NodePtr SCW_USimpleConstructionScript::FindSCSNode(const wstring& NodeName) const
{
	USCS_Node* Node = SimpleConstructionScript->FindSCSNode(NodeName.c_str());
	return Node ? FSourcifyCoreUEWrapper::Get().Wrap(*Node) : nullptr;
}

vector<ISCW_USCS_NodePtr> SCW_USimpleConstructionScript::GetAllNodes() const
{
	vector<ISCW_USCS_NodePtr> Result;
	for (USCS_Node* Node : SimpleConstructionScript->GetAllNodes())
	{
		Result.push_back(FSourcifyCoreUEWrapper::Get().Wrap(*Node));
	}
	return Result;
}

ISCW_UBlueprintPtr SCW_USimpleConstructionScript::GetBlueprint() const
{
	return FSourcifyCoreUEWrapper::Get().Wrap(*SimpleConstructionScript->GetBlueprint());
}

ISCW_USCS_NodeConstPtr SCW_USimpleConstructionScript::GetDefaultSceneRootNode() const
{
	return GetDefaultSceneRootNode();
}

ISCW_USCS_NodePtr SCW_USimpleConstructionScript::GetDefaultSceneRootNode()
{
	return FSourcifyCoreUEWrapper::Get().Wrap(*SimpleConstructionScript->GetDefaultSceneRootNode());
}

vector<ISCW_USCS_NodePtr> SCW_USimpleConstructionScript::GetRootNodes() const
{
	vector<ISCW_USCS_NodePtr> Result;
	for (USCS_Node* Node : SimpleConstructionScript->GetRootNodes())
	{
		Result.push_back(FSourcifyCoreUEWrapper::Get().Wrap(*Node));
	}
	return Result;
}

void SCW_USimpleConstructionScript::RemoveNodeAndPromoteChildren(ISCW_USCS_NodePtr Node)
{
	SimpleConstructionScript->RemoveNodeAndPromoteChildren(dynamic_cast<SCW_USCS_Node*>(Node.get())->ToUSCS_Node());
}

void SCW_USimpleConstructionScript::ValidateSceneRootNodes() const 
{
	SimpleConstructionScript->ValidateSceneRootNodes();
}