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

#pragma once

#include "CoreMinimal.h"
#include "InworldCharacterTypes.h"
#include "UObject/Interface.h"

#include "InworldCharacterData.generated.h"

namespace inworld
{
class BaseData;
}	 // namespace inworld

enum class EInworldGoalResponseType : uint8;

/**
 * @struct FInworldCharacterTrigger
 * @brief Represents a character goal trigger with associated parameters.
 *
 * This structure defines a trigger that can activate character goals or behaviors,
 * including the goal identifier and a map of custom parameters that provide context
 * for the goal execution.
 */
USTRUCT(BlueprintType)
struct INWORLDCHARACTER_API FInworldCharacterTrigger
{
	GENERATED_BODY()

public:
	/** The name/identifier of the goal to trigger */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Graph",
		Meta = (ToolTip = "The name/identifier of the goal to trigger"))
	FName GoalName{""};

	/** Key-value pairs providing contextual parameters for the goal execution */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Graph",
		Meta = (ToolTip = "Key-value pairs providing contextual parameters for the goal execution"))
	TMap<FString, FString> Parameters{};
};

/**
 * @struct FInworldCharacterAction
 * @brief Represents a character action in response to a goal trigger.
 *
 * This structure defines an action that should be executed when a character goal
 * is triggered, including the goal identifier, the type of response, and the
 * specific action to perform.
 */
USTRUCT(BlueprintType)
struct INWORLDCHARACTER_API FInworldCharacterAction
{
	GENERATED_BODY()

public:
	/** The name/identifier of the goal associated with this action */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Graph",
		Meta = (ToolTip = "The name/identifier of the goal associated with this action"))
	FName GoalName{""};

	/** The type of response this action represents (verbatim, instruction) */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Graph",
		Meta = (ToolTip = "The type of response this action represents (verbatim, instruction)"))
	EInworldGoalResponseType ResponseType{};

	/** The action content or description to be executed */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Graph",
		Meta = (ToolTip = "The action content or description to be executed"))
	FString Action{""};
};

/**
 * @class UInworldGoalParameterInterface
 * @brief Unreal interface wrapper for IInworldGoalParameterInterface.
 *
 * This is the UINTERFACE wrapper required by Unreal's reflection system for the
 * IInworldGoalParameterInterface. Implement the corresponding IInworldGoalParameterInterface
 * in your class to provide goal parameter data.
 */
UINTERFACE()
class INWORLDCHARACTER_API UInworldGoalParameterInterface : public UInterface
{
	GENERATED_BODY()
};

/**
 * @class IInworldGoalParameterInterface
 * @brief Interface for providing dynamic parameter data to character goals.
 *
 * Implement this interface in any UObject class to act as a source of parameter data
 * for dialogue-triggered character goals. Register the implementing object with the
 * UInworldGraphRuntimeData_Goals component to enable dynamic goal parameter resolution.
 *
 * This allows goals to access contextual runtime data (e.g., player stats, game state,
 * inventory items) when they are triggered, enabling more dynamic and responsive character behaviors.
 */
class INWORLDCHARACTER_API IInworldGoalParameterInterface
{
	GENERATED_BODY()

public:
	/**
	 * @brief Provides parameter data for a triggered character goal.
	 *
	 * This function is called when a goal is triggered to populate the parameter map
	 * with contextual data needed for goal execution. Implementations should fill the
	 * OutParameters map with key-value pairs relevant to the specified goal.
	 *
	 * @param GoalId The name/identifier of the goal requesting parameters
	 * @param OutParameters Output map to be filled with parameter key-value pairs
	 */
	virtual void GetGoalParameters(const FName& GoalId, TMap<FString, FString>& OutParameters) const
		PURE_VIRTUAL(IInworldGoalParameterInterface::GetGoalParameters, return;);
};

/**
 * @struct FInworldGoalsData
 * @brief Container for character goals and their parameter resolution interface.
 *
 * This structure manages the collection of character goals and provides a reference
 * to an object implementing the goal parameter interface for dynamic parameter resolution.
 * It serves as the central data structure for goal-driven character behaviors.
 */
USTRUCT(BlueprintType)
struct INWORLDCHARACTER_API FInworldGoalsData
{
	GENERATED_BODY()

public:
	/** Interface implementation providing dynamic parameter data for goal execution */
	UPROPERTY(Meta = (ToolTip = "Interface implementation providing dynamic parameter data for goal execution"))
	TScriptInterface<IInworldGoalParameterInterface> GoalParameterInterface;

	/** Map of all available character goals indexed by their unique names */
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Inworld|Graph",
		Meta = (ToolTip = "Map of all available character goals indexed by their unique names"))
	TMap<FName, FInworldGoal> GoalsMap;
};
