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

#pragma once

#include "CoreMinimal.h"
#include "Graph/InworldNode.h"
#include "Primitives/KeywordMatcher/InworldKeywordMatcherTypes.h"

#include "InworldNode_KeywordMatcher.generated.h"

/**
 * @class UInworldNode_KeywordMatcher
 * @brief A node that matches text content against keyword groups.
 *
 * This node takes text input and matches it against configured keyword groups.
 * It can be used for various purposes such as safety checking, content
 * categorization, sentiment analysis, or any other keyword-based filtering.
 * It inherits from TypedNode with MatchedKeywords as output and Text as input.
 *
 * @input FInworldData_Text
 * @output FInworldData_ClassificationResult
 */
UCLASS()
class INWORLDRUNTIME_API UInworldNode_KeywordMatcher : public UInworldNode
{
	GENERATED_BODY()

public:
	/**
	 * @brief Default constructor for the keyword matching node.
	 *
	 * Initializes the node with default settings for keyword matching operations.
	 */
	UInworldNode_KeywordMatcher();

	/** Configuration settings for keyword matcher creation including keyword groups and matching options */
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Inworld",
		Meta = (ToolTip = "Configuration settings for keyword matcher creation including keyword groups and matching options"))
	FInworldKeywordMatcherNodeCreationConfig CreationConfig{};

private:
	/**
	 * @brief Generates JSON configuration for the keyword matching node.
	 *
	 * This override generates the JSON configuration needed for the keyword matcher node's
	 * processing operations, including keyword groups, matching rules, and filtering options.
	 *
	 * @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 text input to identify matching keywords from configured keyword groups.
	 *
	 * This function analyzes the input text against the configured keyword groups to identify
	 * any matches. It's useful for content filtering, safety checking, categorization, or
	 * any other keyword-based text analysis operations.
	 *
	 * @param Text The input text to analyze for keyword matches
	 * @return Data structure containing matched keywords organized by group
	 */
	UFUNCTION()
	UPARAM(meta = (DisplayName = "Matched Keywords"))
	FInworldData_MatchedKeywords Process_Text(const FInworldData_Text& Text)
	{
		checkNoEntry();
		return {};
	}
};
