#pragma once

#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "UObject/Object.h"
#include "HyperTwistRecognition/HyperTwistRecognitionTypes.h"
#include "HyperTwistVoiceClient.generated.h"

UINTERFACE(BlueprintType)
class UNREALHYPERTWIST_API UHyperTwistVoiceClient : public UInterface
{
	GENERATED_BODY()
};

class UNREALHYPERTWIST_API IHyperTwistVoiceClient
{
	GENERATED_BODY()

public:
	virtual TArray<FHyperTwistVoiceProfileSummary> ListVoiceProfiles() const = 0;
	virtual FHyperTwistNarrationSynthesisResult SynthesizeNarration(
		const FHyperTwistNarrationSynthesisRequest& Request
	) = 0;
	virtual FHyperTwistVoiceServiceHealth GetVoiceServiceHealth() const = 0;
};

UCLASS(BlueprintType)
class UNREALHYPERTWIST_API UHyperTwistMockVoiceClient : public UObject, public IHyperTwistVoiceClient
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Recognition")
	virtual TArray<FHyperTwistVoiceProfileSummary> ListVoiceProfiles() const override;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Recognition")
	virtual FHyperTwistNarrationSynthesisResult SynthesizeNarration(
		const FHyperTwistNarrationSynthesisRequest& Request
	) override;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Recognition")
	virtual FHyperTwistVoiceServiceHealth GetVoiceServiceHealth() const override;
};

UCLASS(BlueprintType, Config = Game, DefaultConfig)
class UNREALHYPERTWIST_API UHyperTwistHttpVoiceClient : public UObject, public IHyperTwistVoiceClient
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Config, Category = "HyperTwist|Recognition")
	FString ProviderLabel = TEXT("local-http-sidecar");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Config, Category = "HyperTwist|Recognition")
	FString ServiceBaseUrl = TEXT("http://127.0.0.1:8766");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Config, Category = "HyperTwist|Recognition")
	FString ProfilesPath = TEXT("/voice/profiles");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Config, Category = "HyperTwist|Recognition")
	FString SynthesizePath = TEXT("/voice/narrate");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Config, Category = "HyperTwist|Recognition")
	FString HealthPath = TEXT("/voice/health");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Config, Category = "HyperTwist|Recognition")
	float RequestTimeoutSeconds = 5.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Config, Category = "HyperTwist|Recognition")
	FString AuthorizationToken;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Recognition")
	virtual TArray<FHyperTwistVoiceProfileSummary> ListVoiceProfiles() const override;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Recognition")
	virtual FHyperTwistNarrationSynthesisResult SynthesizeNarration(
		const FHyperTwistNarrationSynthesisRequest& Request
	) override;

	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Recognition")
	virtual FHyperTwistVoiceServiceHealth GetVoiceServiceHealth() const override;

private:
	mutable FString LastTransportError;
};
