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

#pragma once

#include "CoreMinimal.h"
#include "Graph/InworldNode.h"
#include "InworldRuntimeSubsystem.h"
#include "Primitives/STT/InworldSTTTypes.h"

#include "InworldNode_STT.generated.h"

/**
 * @class UInworldNode_STT
 * @brief A node that converts audio input to text using Speech-to-Text
 * functionality.
 *
 * This node takes audio input and processes it through a Speech-to-Text service
 * to generate text output. It inherits from TypedNode with Text as output and
 * Audio as input.
 *
 * @input FInworldData_Audio OR FInworldData_DataStream_AudioChunk (Audio data to convert to text)
 * @output FInworldData_Text
 */
UCLASS()
class INWORLDRUNTIME_API UInworldNode_STT : public UInworldNode
{
	GENERATED_BODY()

public:
	/**
	 * @brief Default constructor for the speech-to-text node.
	 *
	 * Initializes the node with default settings for speech-to-text processing.
	 */
	UInworldNode_STT();

	/**
	 * @brief Native utility function. Creates a new STT 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 ExecutionConfig The configuration for executing the node
	 * @return Newly created STT node instance
	 */
	static UInworldNode_STT* CreateNative(
		class UObject* Outer, const FString& NodeName, const FInworldSTTNodeExecutionConfig& ExecutionConfig);

	/** Configuration settings for STT node execution including streaming mode, component IDs, and model selection */
	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Inworld",
		Meta = (ToolTip =
					"Configuration settings for STT node execution including streaming mode, component IDs, and model selection"))
	FInworldSTTNodeExecutionConfig ExecutionConfig{};

private:
	/**
	 * @brief Generates JSON configuration for the speech-to-text node.
	 *
	 * This override generates the JSON configuration needed for the STT node's
	 * processing operations, including streaming mode settings, component IDs,
	 * model selection, and language configuration.
	 *
	 * @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 audio data to generate text transcription using speech-to-text services.
	 *
	 * This function handles complete audio clips by sending them to the configured STT service
	 * (local or remote) for transcription. The audio is processed as a single unit and
	 * returns the complete transcribed text.
	 *
	 * @param Audio The input audio data to transcribe to text
	 * @return Text data containing the transcribed speech content
	 */
	UFUNCTION()
	UPARAM(meta = (DisplayName = "Text"))
	FInworldData_Text Process_Audio(const FInworldData_Audio& Audio)
	{
		checkNoEntry();
		return {};
	}

	/**
	 * @brief Processes streaming audio chunks to generate text transcription using speech-to-text services.
	 *
	 * This function handles streaming audio input by processing audio chunks incrementally
	 * through the configured STT service. This is useful for real-time transcription of
	 * ongoing speech or long audio streams.
	 *
	 * @param Audio The input audio stream chunks to transcribe to text
	 * @return Text data containing the transcribed speech content from the audio stream
	 */
	UFUNCTION()
	UPARAM(meta = (DisplayName = "Text"))
	FInworldData_Text Process_AudioStream(const FInworldData_DataStream_AudioChunk& Audio)
	{
		checkNoEntry();
		return {};
	}
};
