// Copyright HyperTwist, Inc. All Rights Reserved.

#include "Misc/AutomationTest.h"

#include "HyperTwistTraining/HyperTwistTrainingRuntimeLibrary.h"

#if WITH_AUTOMATION_TESTS

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistValidationPhaseJAReplayIntegrityContractTest,
	"HyperTwist.FirstParty.Validation.PhaseJA.ReplayIntegrity",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistValidationPhaseJAReplayIntegrityContractTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingReplayIntegrityContract Contract;
	TestTrue(
		TEXT("The replay-integrity contract must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledReplayIntegrityContract(
			TEXT("validation-replay-integrity-contract"),
			Contract
		)
	);
	TestEqual(
		TEXT("The replay-integrity contract id must stay stable."),
		Contract.ContractId,
		TEXT("validation-replay-integrity-contract")
	);
	TestTrue(
		TEXT("The replay-integrity contract must preserve the timer-start anchor."),
		Contract.RequiredAnchorIds.Contains(TEXT("replay-anchor/timer-start"))
	);
	TestTrue(
		TEXT("The replay-integrity contract must preserve the timer-start before solve-end guard."),
		Contract.IntegrityGuardTags.Contains(TEXT("timer-start before solve-end guard"))
	);
	TestTrue(
		TEXT("The replay-integrity contract must preserve imported-source sparse-anchor tolerance."),
		Contract.ImportedReplayToleranceTags.Contains(TEXT("imported-source sparse-anchor tolerance"))
	);
	TestTrue(
		TEXT("The replay-integrity contract must keep generic media timeline ownership excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("generic media timeline ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistValidationPhaseJAPuzzleValidationAndBenchmarkProfileTest,
	"HyperTwist.FirstParty.Validation.PhaseJA.PuzzleValidationAndBenchmarkProfiles",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistValidationPhaseJAPuzzleValidationAndBenchmarkProfileTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingPuzzleValidationContract PuzzleContract;
	TestTrue(
		TEXT("The puzzle-validation contract must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledPuzzleValidationContract(
			TEXT("validation-puzzle-state-contract"),
			PuzzleContract
		)
	);
	TestTrue(
		TEXT("The puzzle-validation contract must preserve solvability verification."),
		PuzzleContract.ValidationSurfaceTags.Contains(TEXT("solvability verification"))
	);
	TestTrue(
		TEXT("The puzzle-validation contract must preserve the is-solvable validation flag."),
		PuzzleContract.RequiredResultFlags.Contains(TEXT("validation-flag/is-solvable"))
	);
	TestTrue(
		TEXT("The puzzle-validation contract must keep external oracle replacement ownership excluded."),
		PuzzleContract.ExplicitExclusions.Contains(TEXT("external oracle replacement ownership"))
	);

	FHyperTwistTrainingBenchmarkProfileBoundary Boundary;
	TestTrue(
		TEXT("The benchmark-profile boundary must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledBenchmarkProfileBoundary(
			TEXT("validation-benchmark-profile-boundary"),
			Boundary
		)
	);
	TestTrue(
		TEXT("The benchmark-profile boundary must preserve the replay-review-integrity profile."),
		Boundary.BenchmarkProfileIds.Contains(TEXT("benchmark-profile/replay-review-integrity"))
	);
	TestTrue(
		TEXT("The benchmark-profile boundary must preserve comparison repeatability posture."),
		Boundary.MetricSurfaceTags.Contains(TEXT("comparison repeatability posture"))
	);
	TestTrue(
		TEXT("The benchmark-profile boundary must keep public benchmark ladder ownership excluded."),
		Boundary.ExplicitExclusions.Contains(TEXT("public benchmark ladder ownership"))
	);
	return true;
}

IMPLEMENT_SIMPLE_AUTOMATION_TEST(
	FHyperTwistValidationPhaseJAScorecardContractTest,
	"HyperTwist.FirstParty.Validation.PhaseJA.Scorecards",
	EAutomationTestFlags::EditorContext | EAutomationTestFlags::EngineFilter
)

bool FHyperTwistValidationPhaseJAScorecardContractTest::RunTest(const FString& Parameters)
{
	FHyperTwistTrainingValidationScorecardContract Contract;
	TestTrue(
		TEXT("The validation-scorecard contract must resolve from the runtime library."),
		UHyperTwistTrainingRuntimeLibrary::TryGetBundledValidationScorecardContract(
			TEXT("validation-scorecard-contract"),
			Contract
		)
	);
	TestEqual(
		TEXT("The validation-scorecard contract id must stay stable."),
		Contract.ContractId,
		TEXT("validation-scorecard-contract")
	);
	TestTrue(
		TEXT("The validation-scorecard contract must preserve the regression-watch section."),
		Contract.ScorecardSectionIds.Contains(TEXT("scorecard/regression-watch"))
	);
	TestTrue(
		TEXT("The validation-scorecard contract must preserve benchmark drift note framing."),
		Contract.OutcomeSurfaceTags.Contains(TEXT("benchmark drift note"))
	);
	TestTrue(
		TEXT("The validation-scorecard contract must preserve anchor coverage regression."),
		Contract.RegressionSignalTags.Contains(TEXT("anchor coverage regression"))
	);
	TestTrue(
		TEXT("The validation-scorecard contract must keep cross-product release gate authority excluded."),
		Contract.ExplicitExclusions.Contains(TEXT("cross-product release gate authority"))
	);
	return true;
}

#endif
