#pragma once

// Clean-room implementation for HyperTwist algorithm-language subsystem
// Implemented from governance docs only (Phase 0R-D, Phase 1R, Phase 5R-A)
// Source: Behavioral contracts from cubing/alg.js Model A handoff (GPL-3.0-or-later lane)
//         No source code inspection. Clean-room workflow only.
// Date: 2026-05-15
// Bound 3 - validation profiles and typed validation failures

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

UENUM(BlueprintType)
enum class EHyperTwistAlgorithmValidationIssueCode : uint8
{
	UnsupportedProfile UMETA(DisplayName = "UnsupportedProfile"),
	ContainerNotAllowed UMETA(DisplayName = "ContainerNotAllowed"),
	UnknownMoveFamily UMETA(DisplayName = "UnknownMoveFamily"),
	LayerIndexMustBePositive UMETA(DisplayName = "LayerIndexMustBePositive"),
	LayerRangeMustBePositive UMETA(DisplayName = "LayerRangeMustBePositive"),
	LayerRangeMustAscend UMETA(DisplayName = "LayerRangeMustAscend"),
	LayerPrefixNotAllowedForFamily UMETA(DisplayName = "LayerPrefixNotAllowedForFamily")
};

USTRUCT(BlueprintType)
struct FHyperTwistAlgorithmValidationIssue
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Validation")
	EHyperTwistAlgorithmValidationIssueCode IssueCode =
		EHyperTwistAlgorithmValidationIssueCode::UnsupportedProfile;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Validation")
	FString NodePath;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Validation")
	FString Message;
};

USTRUCT(BlueprintType)
struct FHyperTwistAlgorithmValidationResult
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Validation")
	bool bIsValid = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Validation")
	FString ProfileName = TEXT("permissive");

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Algorithm|Validation")
	TArray<FHyperTwistAlgorithmValidationIssue> Issues;
};

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

public:
	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm|Validation")
	static FHyperTwistAlgorithmValidationResult ValidateSequenceForProfile(
		const FHyperTwistAlgorithmSequence& Sequence,
		const FString& NotationProfile
	);

	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm|Validation")
	static FHyperTwistAlgorithmValidationResult ValidateSequenceFlatOnly(
		const FHyperTwistAlgorithmSequence& Sequence
	);

	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm|Validation")
	static FHyperTwistAlgorithmValidationResult ValidateSequenceClassicWca(
		const FHyperTwistAlgorithmSequence& Sequence
	);
};
