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

#pragma once

#include "CoreMinimal.h"
#include "Graph/InworldNode.h"

#include "InworldNode_TextChunking.generated.h"

/**
 * @class UInworldNode_TextChunking
 * @brief A node that chunks text input into a stream of token chunks.
 *
 * This node takes either a single text input or a stream of text inputs and
 * converts them into a stream of text chunks. It inherits from TypedNode with
 * specific input/output types for handling text data streams.
 *
 * @input FInworldData_Text OR FInworldData_DataStream_String
 * @output FInworldData_DataStream_String
 */
UCLASS()
class INWORLDRUNTIME_API UInworldNode_TextChunking : public UInworldNode
{
	GENERATED_BODY()

public:
	/**
	 * @brief Default constructor for the text chunking node.
	 *
	 * Initializes the node with default settings for text chunking operations.
	 */
	UInworldNode_TextChunking();

private:
	/**
	 * @brief Generates JSON configuration for the text chunking node.
	 *
	 * This override generates the JSON configuration needed for the text chunking node's
	 * processing operations, including chunk size parameters and token handling settings.
	 *
	 * @param GraphJson The JSON object to populate with the node's configuration data
	 * @return Error code indicating success or failure of configuration generation
	 */
	virtual EInworldRuntimeErrors GetJsonConfig(const TSharedRef<FJsonObject>& GraphJson) override;

	/**
	 * @brief Processes single text input and converts it into a text chunk stream.
	 *
	 * This function takes a complete text input and splits it into smaller chunks,
	 * creating a stream of text data suitable for incremental processing by downstream
	 * nodes such as TTS or text processing components.
	 *
	 * @param Text The input text to be chunked into a stream
	 * @return Text data stream containing the chunked text segments
	 */
	UFUNCTION()
	UPARAM(meta = (DisplayName = "Text Stream"))
	FInworldData_DataStream_String Process_Text(const FInworldData_Text& Text)
	{
		checkNoEntry();
		return {};
	}

	/**
	 * @brief Processes an existing text stream and re-chunks it with different parameters.
	 *
	 * This function takes an existing text stream and re-processes it with potentially
	 * different chunking parameters. This can be useful for adjusting chunk sizes or
	 * applying different tokenization strategies to an existing stream.
	 *
	 * @param TextStream The input text stream to be re-chunked
	 * @return Text data stream containing the re-chunked text segments
	 */
	UFUNCTION()
	UPARAM(meta = (DisplayName = "Text Stream"))
	FInworldData_DataStream_String Process_TextStream(const FInworldData_DataStream_String& TextStream)
	{
		checkNoEntry();
		return {};
	}
};
