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

#pragma once

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

#include "InworldNode_RandomCannedText.generated.h"

/**
 * @class UInworldNode_RandomCannedText
 * @brief A node that selects a random text from a list of predefined phrases.
 *
 * This node takes no input and produces a Text output containing a randomly
 * selected phrase from its internal list. It inherits from the base Node class
 * and is useful for generating varied responses or fallback content.
 *
 * @input FInworldData (Anything)
 * @output FInworldData_Text (One of the configured canned responses)
 */
UCLASS()
class INWORLDRUNTIME_API UInworldNode_RandomCannedText : public UInworldNode
{
	GENERATED_BODY()

public:
	/**
	 * @brief Default constructor for the random canned text node.
	 *
	 * Initializes the node with default settings for random phrase selection.
	 */
	UInworldNode_RandomCannedText();

	/**
	 * @brief Native utility function. Creates a new canned response node instance with the specified configuration
	 * @param Outer The UObject that will own this node
	 * @param NodeName The name to assign to the node
	 * @param CannedPhrases List of phrases to randomly respond with
	 * @return Newly created RandomCannedText node instance
	 */
	static UInworldNode_RandomCannedText* CreateNative(
		class UObject* Outer, const FString& NodeName, const TArray<FString>& CannedPhrases);

	/**
	 * @brief Array of predefined text phrases for random selection.
	 *
	 * This array contains all the possible text responses that can be randomly selected
	 * by this node. Each execution will choose one phrase at random from this list.
	 * Useful for creating varied responses, fallback content, or simple chatbot replies.
	 */
	UPROPERTY(
		EditDefaultsOnly, BlueprintReadWrite, Category = "Inworld", Meta = (ToolTip = "List of phrases to randomly respond with"))
	TArray<FString> CannedPhrases;

private:
	/**
	 * @brief Generates JSON configuration for the random canned text node.
	 *
	 * This override generates the JSON configuration needed for the random canned text node's
	 * processing operations, including the list of available phrases for random selection.
	 *
	 * @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 Selects and returns a random text phrase from the configured list.
	 *
	 * This function performs the core random selection logic by choosing one phrase
	 * at random from the CannedPhrases array. Each execution will potentially return
	 * a different phrase, providing varied responses for dynamic content generation.
	 *
	 * @return Text data containing a randomly selected phrase from the canned phrases array
	 */
	UFUNCTION()
	UPARAM(meta = (DisplayName = "Text"))
	FInworldData_Text Process_RandomCannedText()
	{
		checkNoEntry();
		return {};
	}
};
