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

#include "SCW_UK2Node_CallFunction.h"

#include "K2Node_CallFunction.h"
#include "SCW_UFunction.h"
#include "SourcifyCoreUEWrapperModule.h"

using namespace Sourcify;

SCW_UK2Node_CallFunction::SCW_UK2Node_CallFunction(UK2Node_CallFunction* InK2Node_CallFunction) : SCW_UK2Node(InK2Node_CallFunction), K2Node_CallFunction(InK2Node_CallFunction)
{

}

ISCW_UEdGraphPtr SCW_UK2Node_CallFunction::GetFunctionGraph() const
{
	const UEdGraphNode* OutGraphNode = nullptr;
	if (UEdGraph* Graph = K2Node_CallFunction->GetFunctionGraph(OutGraphNode))
	{
		return FSourcifyCoreUEWrapper::Get().Wrap(*Graph);
	}

	return nullptr;
}

ISCW_FMemberReferencePtr SCW_UK2Node_CallFunction::GetFunctionReference() const
{
	return FSourcifyCoreUEWrapper::Get().Wrap(K2Node_CallFunction->FunctionReference);
}

void SCW_UK2Node_CallFunction::SetFromFunction(ISCW_UFunctionConstPtr Function)
{
	K2Node_CallFunction->SetFromFunction(dynamic_cast<const SCW_UFunction*>(Function.get())->ToUFunction());
}

ISCW_UFunctionPtr SCW_UK2Node_CallFunction::GetTargetFunction() const
{
	return K2Node_CallFunction->GetTargetFunction() ? FSourcifyCoreUEWrapper::Get().Wrap(*K2Node_CallFunction->GetTargetFunction()) : nullptr;
}

UK2Node_CallFunction* SCW_UK2Node_CallFunction::ToUK2Node_CallFunction() const
{
	return K2Node_CallFunction;
}

ISCW_UK2Node_CallFunctionPtr SCW_UK2Node_CallFunction::ToUK2Node_CallFunctionPtr()
{
	return GetSharedThisAs<SCW_UK2Node_CallFunction>();
}

ISCW_UK2Node_CallFunctionConstPtr SCW_UK2Node_CallFunction::ToUK2Node_CallFunctionPtr() const
{
	return GetSharedThisAs<SCW_UK2Node_CallFunction>();
}