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

#pragma once

#include "CoreMinimal.h"
#include "Graph/InworldGraphRuntimeData.h"
#include "InworldCharacterTypes.h"

#include "InworldGraphRuntimeData_EmotionState.generated.h"

/**
 * @class UInworldGraphRuntimeData_EmotionState
 * @brief Runtime data component for managing character emotional states.
 *
 * This runtime data component tracks and manages a character's current emotional state,
 * which can influence their behavior, dialogue tone, and responses during interactions.
 * Emotion states can be explicitly set or derived from AI-generated responses.
 */
UCLASS(BlueprintType, meta = (DisplayName = "EmotionState Data"))
class INWORLDCHARACTER_API UInworldGraphRuntimeData_EmotionState : public UInworldGraphRuntimeData
{
	GENERATED_BODY()

public:
	/**
	 * @brief Default constructor for the emotion state runtime data.
	 */
	UInworldGraphRuntimeData_EmotionState();

	/**
	 * @brief Retrieves the emotion state as a data handle for graph processing.
	 * @return Data handle containing the current emotion state.
	 */
	virtual FInworldDataHandle GetData() override;

	/**
	 * @brief Retrieves the current emotion state.
	 * @return The current emotion state structure.
	 */
	UFUNCTION(BlueprintCallable, Category = "Inworld|Emotion State Runtime Data")
	FInworldEmotion GetEmotion() const;

	/**
	 * @brief Retrieves the emotion label as a human-readable string.
	 * @return String representation of the current emotion label.
	 */
	UFUNCTION(BlueprintCallable, Category = "Inworld|Emotion State Runtime Data")
	FString GetEmotionLabelString() const;

	/**
	 * @brief Retrieves the current emotion label enum value.
	 * @return The current emotion label enum.
	 */
	UFUNCTION(BlueprintCallable, Category = "Inworld|Emotion State Runtime Data")
	EInworldEmotionLabel GetEmotionLabel() const;

	/**
	 * @brief Sets the character's emotion to a specific label.
	 * @param InEmotionLabel The new emotion label to set.
	 */
	UFUNCTION(BlueprintCallable, Category = "Inworld|Emotion State Runtime Data")
	void SetEmotionLabel(const EInworldEmotionLabel& InEmotionLabel);

	/**
	 * @brief Updates the emotion state by parsing an AI-generated text response.
	 * @param TextResponse The text response to parse for emotion information.
	 */
	void UpdateEmotion(const FString& TextResponse);

private:
	/**
	 * @brief Parses a text response to extract emotion label information.
	 * @param TextResponse The text response to parse.
	 * @return Optional emotion label if successfully parsed, empty otherwise.
	 */
	TOptional<EInworldEmotionLabel> ParseEmotionResponse(const FString& TextResponse);

protected:
	/** The current emotional state of the character, defaults to NEUTRAL */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Emotion State Runtime Data",
		meta = (ExposeOnSpawn = "true", ToolTip = "The current emotional state of the character, defaults to NEUTRAL"))
	FInworldEmotion Emotion{EInworldEmotionLabel::NEUTRAL};
};
