#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-15
// Model: Claude (Model B, Bound 1 contribution)

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

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

public:
	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Algorithm")
	static bool TryCanonicalizeAlgorithmText(
		const FString& AlgorithmText,
		FString& OutCanonicalText,
		FString& OutErrorMessage,
		int32& OutErrorPosition
	);

	// Round-trip validation: Parse → Serialize → Parse → Compare
	UFUNCTION(BlueprintCallable, Category = "HyperTwist|Algorithm")
	static bool ValidateRoundTrip(
		const FString& AlgorithmText,
		FString& OutReserializedText,
		bool& bOutStructurallyEqual
	);

	// Diagnostic TSV export
	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm")
	static FString BuildAlgorithmDebugTsv(const FHyperTwistAlgorithmSequence& Sequence);

	// Structural equality check
	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm")
	static bool AreAlgorithmsStructurallyEqual(
		const FHyperTwistAlgorithmSequence& A,
		const FHyperTwistAlgorithmSequence& B
	);

	// Get subsystem provenance information
	UFUNCTION(BlueprintPure, Category = "HyperTwist|Algorithm")
	static FString GetAlgorithmSubsystemProvenance();
};
