#pragma once

// Clean-room implementation for HyperTwist algorithm-language subsystem
// Implemented from governance docs only (Phase 0R-D, Phase 1R, Phase 5R-A)
// Date: 2026-05-16
// Bound 4 - keyboard mapping helpers

#include "CoreMinimal.h"
#include "InputCoreTypes.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "HyperTwistAlgorithm/HyperTwistAlgorithmTypes.h"
#include "HyperTwistAlgorithmKeyboard.generated.h"

UENUM(BlueprintType)
enum class EHyperTwistAlgorithmKeyboardMappingStatus : uint8
{
	ProducedMove UMETA(DisplayName = "Produced Move"),
	NoMapping UMETA(DisplayName = "No Mapping"),
	SuppressedByModifier UMETA(DisplayName = "Suppressed By Modifier"),
	SuppressedByRepeat UMETA(DisplayName = "Suppressed By Repeat"),
	UnsupportedProfile UMETA(DisplayName = "Unsupported Profile")
};

USTRUCT(BlueprintType)
struct FHyperTwistAlgorithmKeyboardEvent
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FKey Key;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bCtrlPressed = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bAltPressed = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bShiftPressed = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bMetaPressed = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bIsRepeat = false;
};

USTRUCT(BlueprintType)
struct FHyperTwistAlgorithmKeyboardPolicy
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bSuppressCtrl = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bSuppressAlt = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bSuppressMeta = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bSuppressRepeat = false;
};

USTRUCT(BlueprintType)
struct FHyperTwistAlgorithmKeyboardBinding
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FKey Key;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bRequiresShift = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bRequiresNoShift = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FHyperTwistAlgorithmBlockMove Move;
};

USTRUCT(BlueprintType)
struct FHyperTwistAlgorithmKeyboardProfile
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FString ProfileName;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FHyperTwistAlgorithmKeyboardPolicy Policy;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	TArray<FHyperTwistAlgorithmKeyboardBinding> Bindings;
};

USTRUCT(BlueprintType)
struct FHyperTwistAlgorithmKeyboardMappingResult
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	EHyperTwistAlgorithmKeyboardMappingStatus Status =
		EHyperTwistAlgorithmKeyboardMappingStatus::NoMapping;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FString ResolvedProfileName;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FString CanonicalText;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	FHyperTwistAlgorithmBlockMove Move;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Keyboard")
	bool bHasMoveIntent = false;
};

UCLASS()
class UNREALHYPERTWIST_API UHyperTwistAlgorithmKeyboardLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm|Keyboard")
	static FString GetDefaultKeyboardProfileName();

	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm|Keyboard")
	static FHyperTwistAlgorithmKeyboardProfile GetClassicWcaKeyboardProfile();

	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm|Keyboard")
	static FHyperTwistAlgorithmKeyboardMappingResult MapKeyboardEvent(
		const FHyperTwistAlgorithmKeyboardEvent& KeyboardEvent,
		const FHyperTwistAlgorithmKeyboardProfile& Profile
	);

	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm|Keyboard")
	static FHyperTwistAlgorithmKeyboardMappingResult MapKeyboardEventForProfile(
		const FHyperTwistAlgorithmKeyboardEvent& KeyboardEvent,
		const FString& ProfileName
	);
};
