// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistImmersivePhaseIBPresenceControlTest,
	"HyperTwist.FirstParty.Immersive.PhaseIB.PresenceControl",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistImmersivePhaseIBPresenceControlTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingImmersivePresenceControlContract Contract;
	TestTrue(
		TEXT("The immersive presence-control contract must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledImmersivePresenceControlContract(
			TEXT("immersive-training-presence-control-contract"),
			Contract
		)
	);
	TestEqual(
		TEXT("The immersive presence-control id must stay stable."),
		Contract.ContractId,
		TEXT("immersive-training-presence-control-contract")
	);
	TestTrue(
		TEXT("The immersive presence-control contract must preserve deep-presence intensity."),
		Contract.ImmersionIntensityIds.Contains(TEXT("intensity/deep-presence"))
	);
	TestTrue(
		TEXT("The immersive presence-control contract must preserve reduced-distraction review posture."),
		Contract.ReducedDistractionPresetIds.Contains(TEXT("preset/reduced-distraction-review"))
	);
	TestTrue(
		TEXT("The immersive presence-control contract must preserve session-local presence tuning."),
		Contract.PresenceSurfaceTags.Contains(TEXT("session-local presence tuning"))
	);
	TestTrue(
		TEXT("The immersive presence-control contract must keep platform-global XR settings excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("platform-global XR settings ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistImmersivePhaseIBComfortPostureTest,
	"HyperTwist.FirstParty.Immersive.PhaseIB.ComfortAndPosture",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistImmersivePhaseIBComfortPostureTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingImmersiveComfortBoundary ComfortBoundary;
	TestTrue(
		TEXT("The immersive comfort boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledImmersiveComfortBoundary(
			TEXT("immersive-training-comfort-boundary"),
			ComfortBoundary
		)
	);
	TestTrue(
		TEXT("The immersive comfort boundary must preserve strong vignette posture."),
		ComfortBoundary.ComfortOptionIds.Contains(TEXT("comfort/strong-vignette"))
	);
	TestTrue(
		TEXT("The immersive comfort boundary must preserve edge-softening vignette behavior."),
		ComfortBoundary.VignetteSurfaceTags.Contains(TEXT("edge-softening vignette"))
	);
	TestTrue(
		TEXT("The immersive comfort boundary must keep platform locomotion ownership excluded."),
		ComfortBoundary.ExplicitExclusions.Contains(TEXT("platform-level locomotion shell ownership"))
	);

	FHyperTwistTrainingImmersivePostureVariantContract PostureContract;
	TestTrue(
		TEXT("The immersive posture-variant contract must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledImmersivePostureVariantContract(
			TEXT("immersive-training-posture-variant-contract"),
			PostureContract
		)
	);
	TestTrue(
		TEXT("The immersive posture-variant contract must preserve seated stable posture."),
		PostureContract.PostureVariantIds.Contains(TEXT("posture/seated-stable"))
	);
	TestTrue(
		TEXT("The immersive posture-variant contract must preserve puzzle dais height offset."),
		PostureContract.AnchorAdjustmentSurfaceTags.Contains(TEXT("puzzle dais height offset"))
	);
	TestTrue(
		TEXT("The immersive posture-variant contract must preserve comfort-safe recentering."),
		PostureContract.ComfortSurfaceTags.Contains(TEXT("comfort-safe recentering"))
	);
	TestTrue(
		TEXT("The immersive posture-variant contract must keep locomotion rigs excluded."),
		PostureContract.ExplicitExclusions.Contains(TEXT("full locomotion rig ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistImmersivePhaseIBSessionRecallTest,
	"HyperTwist.FirstParty.Immersive.PhaseIB.SessionRecall",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistImmersivePhaseIBSessionRecallTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingImmersiveSessionRecallBoundary Boundary;
	TestTrue(
		TEXT("The immersive session recall boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledImmersiveSessionRecallBoundary(
			TEXT("immersive-training-session-recall-boundary"),
			Boundary
		)
	);
	TestEqual(
		TEXT("The immersive session recall id must stay stable."),
		Boundary.BoundaryId,
		TEXT("immersive-training-session-recall-boundary")
	);
	TestTrue(
		TEXT("The immersive session recall boundary must preserve session-local recall."),
		Boundary.RecallScopeIds.Contains(TEXT("recall/session-local"))
	);
	TestTrue(
		TEXT("The immersive session recall boundary must preserve immersion intensity preference recall."),
		Boundary.PreferenceFieldTags.Contains(TEXT("immersion intensity id"))
	);
	TestTrue(
		TEXT("The immersive session recall boundary must preserve manual reset."),
		Boundary.ResetSurfaceTags.Contains(TEXT("manual reset to default focus posture"))
	);
	TestTrue(
		TEXT("The immersive session recall boundary must keep cloud profile ownership excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("cross-session cloud profile ownership"))
	);
	return true;
}

#endif
