// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagic120CellPhase6RALReferenceBundleTest,
	"HyperTwist.Permissive.Magic120Cell.Phase6R.AL.ReferenceBundle",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagic120CellPhase6RALReferenceBundleTest::RunTest(const FString& Parameters)
{
	const FHyperTwistTrainingMagic120CellReferenceBundle Bundle =
		UHyperTwistTrainingRuntimeLibrary::GetBundledMagic120CellReferenceBundle();

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

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagic120CellPhase6RALViewProfileContractTest,
	"HyperTwist.Permissive.Magic120Cell.Phase6R.AL.ViewProfileContract",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagic120CellPhase6RALViewProfileContractTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingMagic120CellViewProfileContract Contract;
	TestTrue(
		TEXT("The Magic120Cell focus view profile must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledMagic120CellViewProfileContract(
			TEXT("magic120cell-focus-view-profile"),
			Contract
		)
	);
	TestEqual(TEXT("The view profile id must stay stable."), Contract.ContractId, TEXT("magic120cell-focus-view-profile"));
	TestTrue(
		TEXT("The view profile must keep the Magic120Cell settings package as a required input."),
		Contract.RequiredPackageIds.Contains(TEXT("package/magic120cell-settings"))
	);
	TestTrue(
		TEXT("The view profile must preserve 4D projection distance semantics."),
		Contract.ProjectionSurfaceTags.Contains(TEXT("4D projection distance"))
	);
	TestTrue(
		TEXT("The view profile must preserve the layer-display default symmetry preset."),
		Contract.SymmetryPresetTags.Contains(TEXT("layer-display default symmetry"))
	);
	TestTrue(
		TEXT("The view profile must preserve logical visibility depth ladder semantics."),
		Contract.VisibilityPresetTags.Contains(TEXT("logical visibility depth ladder"))
	);
	TestTrue(
		TEXT("The view profile must preserve center-cell recentering focus posture."),
		Contract.FocusSurfaceTags.Contains(TEXT("center-cell recentering"))
	);
	TestEqual(
		TEXT("The view profile must keep the direct donor source repo."),
		Contract.SourceAttribution.SourceRepo,
		TEXT("roice3/Magic120Cell")
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistMagic120CellPhase6RALViewProfileExclusionTest,
	"HyperTwist.Permissive.Magic120Cell.Phase6R.AL.ViewProfileExclusions",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistMagic120CellPhase6RALViewProfileExclusionTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingMagic120CellViewProfileContract Contract;
	TestTrue(
		TEXT("The Magic120Cell focus view profile must still resolve for exclusion checks."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledMagic120CellViewProfileContract(
			TEXT("magic120cell-focus-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 broad renderer ownership excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("broad renderer ownership"))
	);
	TestTrue(
		TEXT("The view profile must keep broad interaction-shell widening excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("broad interaction-shell widening"))
	);
	return true;
}

#endif
