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

#pragma once
#include "Primitives/TextEmbedder/InworldTextEmbedding.h"

#include "InworldTextEmbedder.generated.h"

namespace inworld
{
class TextEmbedderInterface;
}

/** Blueprint delegate called when text embedding operation completes */
DECLARE_DYNAMIC_DELEGATE_TwoParams(FOnTextEmbedded, bool, bSuccess, const TArray<FInworldTextEmbedding>&, TextEmbeddings);

/** Native delegate called when text embedding operation completes */
DECLARE_DELEGATE_TwoParams(FOnTextEmbeddedNative, bool /*bSuccess*/, const TArray<FInworldTextEmbedding>& /*TextEmbeddings*/);

/**
 * @class UInworldTextEmbedder
 * @brief Provides functionality to embed text as vector embeddings using Inworld AI's Text Embedding services.
 *
 * This class offers both synchronous and asynchronous methods for embedding text inputs into high-dimensional
 * vector representations. Delegates can be used to handle asynchronous results, which include success indicators
 * and the resulting embeddings. Text embeddings are useful for semantic similarity comparisons, intent matching,
 * and knowledge retrieval operations.
 */

UCLASS(BlueprintType)
class INWORLDRUNTIME_API UInworldTextEmbedder : public UObject
{
	GENERATED_BODY()

public:
	/**
	 * @brief Creates an instance of UInworldTextEmbedder with the given configuration ID.
	 * @param ConfigId Identifier for the configuration to use for creating the text embedder.
	 * @return A pointer to the instance of UInworldTextEmbedder.
	 */
	UFUNCTION(BlueprintCallable, Category = "Inworld|Text Embedder")
	static UInworldTextEmbedder* CreateInworldTextEmbedder(const FString& ConfigId);

	/**
	 * @brief Embeds the input text into embeddings synchronously.
	 * @param Text An array of text strings to embed.
	 * @param OutTextEmbeddings Outputs the resulting embeddings if embedding succeeds.
	 * @return True if the embedding operation is successful, false otherwise.
	 */
	UFUNCTION(BlueprintCallable, Category = "Inworld|Text Embedder")
	bool Embed(const TArray<FString>& Text, TArray<FInworldTextEmbedding>& OutTextEmbeddings);

	/**
	 * @brief Embeds the input text into embeddings asynchronously.
	 * @param Text An array of text strings to embed.
	 * @param Callback A delegate to handle the embedding result asynchronously.
	 */
	UFUNCTION(BlueprintCallable, Category = "Inworld|Text Embedder")
	void EmbedAsync(const TArray<FString>& Text, FOnTextEmbedded Callback);
	void EmbedAsync(const TArray<FString>& Text, FOnTextEmbeddedNative Callback) const;

private:
	/** Internal interface to the native text embedding functionality */
	TSharedPtr<inworld::TextEmbedderInterface> TextEmbedderInterface;
};
