#pragma once

#include "CoreMinimal.h"
#include "Graph/Nodes/InworldNode_Custom.h"
#include "Graph/RuntimeData/InworldGraphRuntimeData_Memory.h"

#include "InworldNode_Memory.generated.h"

/**
 * @class UInworldNode_MemoryRetrieval
 * @brief A node that retrieves a memory summary based on text input queries.
 *
 * @input FInworldData_Text (Query)
 * @input FInworldData_Struct (FInworldMemory)
 * @output FInworldData_Text (text-based summary of relevant and recent long-term memory)
 */
UCLASS()
class INWORLDCHARACTER_API UInworldNode_MemoryRetrieval : public UInworldNode_Custom
{
	GENERATED_BODY()

public:
	/**
	 * @brief Default constructor for the memory retrieval node.
	 *
	 * Initializes the node with default settings for memory retrieval operations.
	 */
	UInworldNode_MemoryRetrieval();

private:
	/**
	 * @brief Processes text queries to retrieve relevant flash and long-term memory entries.
	 *
	 * This function performs returns a combination of flash memory entries (recent memory) with semantically similar long-term
	 * memory entries
	 *
	 * @param ProcessContext Runtime context containing execution state and runtime data
	 * @param Text The query text to search memory for
	 * @param Memory The structure containing flash and long-term memory data
	 * @return Text summary of memory
	 */
	UFUNCTION()
	virtual UPARAM(meta = (DisplayName = "Summary")) FInworldData_Text Process_Default(
		const UInworldProcessContext* ProcessContext, const FInworldData_Text& Text, const FInworldMemory& Memory) const;

protected:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Memory",
		Meta = (ToolTip = "The number of flash memory entries to include in summary requests."))
	int32 FlashMemorySize{5};

	/** The text embedder component ID to use for generating query embeddings and performing semantic search */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Memory",
		Meta = (GetOptions = "InworldRuntimeSettings.GetTextEmbedderIds",
			ToolTip = "The text embedder component ID to use for generating query embeddings and performing semantic search"))
	FString EmbedderComponentId{"Default"};

	/** Configuration settings for memory retrieval including top-K results, similarity thresholds, and source filtering */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Memory",
		Meta = (ToolTip =
					"Configuration settings for memory retrieval including top-K results, similarity thresholds, and source filtering"))
	FInworldRetrievalConfig RetrievalConfig;
};
