// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagicCube5DPhase6RJRuntimeProfileTest,
	"HyperTwist.Permissive.MagicCube5D.Phase6R.J.RuntimeProfile",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagicCube5DPhase6RJRuntimeProfileTest::RunTest(const FString& Parameters)
{
	const FHyperTwistTrainingMagicCube5DReferenceBundle Bundle =
		UHyperTwistTrainingRuntimeLibrary::GetBundledMagicCube5DReferenceBundle();

	TestTrue(TEXT("The MagicCube5D bundle must be structurally valid."), Bundle.IsStructurallyValid());
	TestTrue(TEXT("The MagicCube5D bundle must preserve multiple package references."), Bundle.PackageReferences.Num() >= 5);

	FHyperTwistTrainingMagicCube5DRuntimeProfileContract Contract;
	TestTrue(
		TEXT("The primary MagicCube5D runtime profile must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledMagicCube5DRuntimeProfileContract(
			Bundle.PrimaryRuntimeProfileContractId,
			Contract
		)
	);
	TestEqual(TEXT("The runtime profile id must stay stable."), Contract.ContractId, TEXT("magiccube5d-runtime-profile"));
	TestTrue(
		TEXT("The runtime profile must keep the family-core package as a required input."),
		Contract.RequiredPackageIds.Contains(TEXT("package/magiccube5d-family-core"))
	);
	TestTrue(
		TEXT("The runtime profile must preserve ten-face signed-axis family semantics."),
		Contract.OrderSurfaceTags.Contains(TEXT("ten-face signed-axis family"))
	);
	TestTrue(
		TEXT("The runtime profile must preserve control-click fifth-axis view rotation."),
		Contract.InteractionSurfaceTags.Contains(TEXT("control-click fifth-axis view rotation"))
	);
	TestTrue(
		TEXT("The runtime profile must preserve cubie-class solved counts."),
		Contract.ProgressSurfaceTags.Contains(TEXT("cubie-class solved counts"))
	);
	TestTrue(
		TEXT("The runtime profile must keep generic non-Euclidean topology ownership excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("generic non-Euclidean topology ownership"))
	);
	TestEqual(TEXT("The runtime profile must keep the direct donor source repo."), Contract.SourceAttribution.SourceRepo, TEXT("roice3/MagicCube5D"));
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagicCube5DPhase6RJPersistenceBoundaryTest,
	"HyperTwist.Permissive.MagicCube5D.Phase6R.J.PersistenceBoundary",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagicCube5DPhase6RJPersistenceBoundaryTest::RunTest(const FString& Parameters)
{
	const FHyperTwistTrainingMagicCube5DReferenceBundle Bundle =
		UHyperTwistTrainingRuntimeLibrary::GetBundledMagicCube5DReferenceBundle();

	FHyperTwistTrainingMagicCube5DPersistenceBoundary Boundary;
	TestTrue(
		TEXT("The MagicCube5D persistence boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledMagicCube5DPersistenceBoundary(
			Bundle.PrimaryPersistenceBoundaryId,
			Boundary
		)
	);
	TestEqual(TEXT("The persistence boundary id must stay stable."), Boundary.BoundaryId, TEXT("magiccube5d-persistence-boundary"));
	TestTrue(
		TEXT("The persistence boundary must preserve the MagicCube5D Version1 header tag."),
		Boundary.PersistenceSurfaceTags.Contains(TEXT("MagicCube5D Version1 header"))
	);
	TestTrue(
		TEXT("The persistence boundary must preserve the view-rotation sentinel."),
		Boundary.TwistHistorySurfaceTags.Contains(TEXT("view-rotation sentinel -1"))
	);
	TestTrue(
		TEXT("The persistence boundary must preserve the macro-sidecar persistence tag."),
		Boundary.PersistenceSurfaceTags.Contains(TEXT("MagicCube5D.macros sidecar persistence"))
	);
	TestTrue(
		TEXT("The persistence boundary must preserve the macro record lifecycle tag."),
		Boundary.MacroSurfaceTags.Contains(TEXT("macro record lifecycle"))
	);
	TestTrue(
		TEXT("The persistence boundary must keep canonical replay ownership excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("first-party canonical replay or verification ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagicCube5DPhase6RJPackageChecklistTest,
	"HyperTwist.Permissive.MagicCube5D.Phase6R.J.PackageChecklist",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagicCube5DPhase6RJPackageChecklistTest::RunTest(const FString& Parameters)
{
	const FString Checklist = UHyperTwistTrainingRuntimeLibrary::BuildBundledMagicCube5DPackageChecklistTsv();
	TestTrue(TEXT("The MagicCube5D package checklist must not be empty."), !Checklist.IsEmpty());
	TestTrue(
		TEXT("The checklist must preserve the family-core package id."),
		Checklist.Contains(TEXT("package/magiccube5d-family-core"))
	);
	TestTrue(
		TEXT("The checklist must preserve the loader export path."),
		Checklist.Contains(TEXT("./MagicCube5D/workFiles/loader.cpp"))
	);
	TestTrue(
		TEXT("The checklist must preserve the direct permissive donor posture."),
		Checklist.Contains(TEXT("direct permissive donor"))
	);
	return true;
}

#endif
