// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagicCube5DPhase6RAMReferenceBundleTest,
	"HyperTwist.Permissive.MagicCube5D.Phase6R.AM.ReferenceBundle",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

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

	TestTrue(TEXT("The MagicCube5D bundle must remain structurally valid after Phase 6R-AM."), Bundle.IsStructurallyValid());
	TestEqual(
		TEXT("The primary MagicCube5D view profile id must stay stable."),
		Bundle.PrimaryViewProfileContractId,
		TEXT("magiccube5d-projection-view-profile")
	);
	TestTrue(
		TEXT("The MagicCube5D bundle must expose one or more view profile contracts."),
		Bundle.ViewProfileContracts.Num() >= 1
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagicCube5DPhase6RAMViewProfileContractTest,
	"HyperTwist.Permissive.MagicCube5D.Phase6R.AM.ViewProfileContract",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagicCube5DPhase6RAMViewProfileContractTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingMagicCube5DViewProfileContract Contract;
	TestTrue(
		TEXT("The MagicCube5D projection view profile must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledMagicCube5DViewProfileContract(
			TEXT("magiccube5d-projection-view-profile"),
			Contract
		)
	);
	TestEqual(TEXT("The view profile id must stay stable."), Contract.ContractId, TEXT("magiccube5d-projection-view-profile"));
	TestTrue(
		TEXT("The view profile must keep the MagicCube5D settings package as a required input."),
		Contract.RequiredPackageIds.Contains(TEXT("package/magiccube5d-settings"))
	);
	TestTrue(
		TEXT("The view profile must preserve 5D projection distance semantics."),
		Contract.ProjectionSurfaceTags.Contains(TEXT("5D projection distance"))
	);
	TestTrue(
		TEXT("The view profile must preserve cross-eyed stereo posture."),
		Contract.StereoSurfaceTags.Contains(TEXT("cross-eyed stereo posture"))
	);
	TestTrue(
		TEXT("The view profile must preserve per-face invisibility semantics."),
		Contract.VisibilitySurfaceTags.Contains(TEXT("per-face invisibility vector"))
	);
	TestTrue(
		TEXT("The view profile must preserve fifth-axis view rotation focus posture."),
		Contract.FocusSurfaceTags.Contains(TEXT("control-click fifth-axis view rotation"))
	);
	TestEqual(
		TEXT("The view profile must keep the direct donor source repo."),
		Contract.SourceAttribution.SourceRepo,
		TEXT("roice3/MagicCube5D")
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagicCube5DPhase6RAMViewProfileExclusionTest,
	"HyperTwist.Permissive.MagicCube5D.Phase6R.AM.ViewProfileExclusions",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagicCube5DPhase6RAMViewProfileExclusionTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingMagicCube5DViewProfileContract Contract;
	TestTrue(
		TEXT("The MagicCube5D projection view profile must still resolve for exclusion checks."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledMagicCube5DViewProfileContract(
			TEXT("magiccube5d-projection-view-profile"),
			Contract
		)
	);
	TestTrue(
		TEXT("The view profile must keep host-shell ownership excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("WinForms/OpenGL host-shell ownership"))
	);
	TestTrue(
		TEXT("The view profile must keep stereo/anaglyph renderer ownership excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("stereo/anaglyph renderer ownership"))
	);
	TestTrue(
		TEXT("The view profile must keep broad macro/tutorial shell widening excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("broad macro/tutorial shell widening"))
	);
	return true;
}

#endif
