// Georgy Treshchev 2026 All Rights Reserved.

#pragma once

#include "CoreMinimal.h"
#include "RuntimeVoskModelTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Async/Future.h"
#include "RuntimeVoskModelLibrary.generated.h"

/**
 * Library for browsing the predefined catalog of Vosk models and for managing model files
 * downloaded/extracted directly to disk (Content/RuntimeSpeechRecognizerVosk/Models)
 */
UCLASS()
class RUNTIMESPEECHRECOGNIZERVOSK_API URuntimeVoskModelLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	/** Full predefined catalog of Vosk models, grouped by language/section as published on the Vosk model server */
	UFUNCTION(BlueprintCallable, Category = "Runtime Speech Recognizer|Vosk")
	static TArray<FVoskModelLanguageGroup> GetPredefinedVoskModels();

	/** Find a model variant by its ModelId across the predefined catalog */
	UFUNCTION(BlueprintCallable, Category = "Runtime Speech Recognizer|Vosk")
	static bool FindVoskModelVariant(const FString& ModelId, FVoskModelVariant& OutVariant);

	/** Names of all Vosk models that have already been extracted to disk */
	static TArray<FName> GetExtractedVoskModelNames();

	/** Whether the given model has already been extracted to disk and can be used immediately */
	static bool IsVoskModelOnDisk(const FString& ModelId);

	/** Names of all Vosk models ready to use right now, whether or not they've been extracted yet.
	 *  Used with the GetOptions meta for Blueprint dropdowns */
	UFUNCTION(BlueprintCallable, Category = "Runtime Speech Recognizer|Vosk")
	static TArray<FName> GetAvailableVoskModelNames();

	/** Whether the given model is ready to use without downloading anything, whether or not it's
	 *  been extracted to disk yet. Prefer this over IsVoskModelOnDisk in most cases */
	UFUNCTION(BlueprintCallable, Category = "Runtime Speech Recognizer|Vosk")
	static bool IsVoskModelAvailable(const FString& ModelId);

	static TFuture<bool> MakeVoskModelReadyOnAndroid(const FString& ModelId);

	/** Absolute path to the extracted model folder for the given ModelId (regardless of whether it currently exists) */
	UFUNCTION(BlueprintCallable, Category = "Runtime Speech Recognizer|Vosk")
	static FString GetVoskModelFolderPath(const FString& ModelId);

	/** Absolute path to the directory Vosk models are read from at runtime */
	UFUNCTION(BlueprintCallable, Category = "Runtime Speech Recognizer|Vosk")
	static FString GetVoskModelsDirectory();

	/** Content-relative path to the models directory, e.g. "RuntimeSpeechRecognizerVosk/Models" */
	static FString GetVoskModelsContentRelativePath();

	/** Whether the model's folder is present in the packaged build (e.g. still inside the APK/OBB on Android) */
	static bool IsVoskModelInPackagedContent(const FString& ModelId);

	/** Delete a model's extracted folder from disk */
	UFUNCTION(BlueprintCallable, Category = "Runtime Speech Recognizer|Vosk")
	static bool DeleteVoskModelFiles(const FString& ModelId);

	/** Name of the marker file written into a model folder once extraction/copy has fully completed */
	static FString GetModelCompleteMarkerFileName();
};