/**
 * Copyright 2022-2025 Theai, Inc. dba Inworld AI
 */

#include "Graph/Nodes/InworldNode_TextAggregator.h"

#include "Async/Async.h"
#include "Dom/JsonObject.h"
#include "Graph/InworldGraph.h"
#include "Misc/TVariant.h"
#include "Serialization/JsonSerializer.h"

UInworldNode_TextAggregator::UInworldNode_TextAggregator()
{
	NodeName = "Text Aggregator";
}

EInworldRuntimeErrors UInworldNode_TextAggregator::GetJsonConfig(const TSharedRef<FJsonObject>& GraphJson)
{
	TSharedPtr<FJsonObject> NodeObj = MakeShared<FJsonObject>();
	NodeObj->SetStringField(TEXT("id"), GetNodeName());
	NodeObj->SetStringField(TEXT("type"), TEXT("TextAggregatorNode"));

	TSharedPtr<FJsonObject> Main = GraphJson->GetObjectField(TEXT("main"));
	TArray<TSharedPtr<FJsonValue>> Nodes = Main->GetArrayField(TEXT("nodes"));
	Nodes.Add(MakeShared<FJsonValueObject>(NodeObj));
	Main->SetArrayField(TEXT("nodes"), Nodes);

	return EInworldRuntimeErrors::SUCCESS;
}
