#include "HyperTwistTraining/HyperTwistTrainingHigherDimensionalRuntimeLibrary.h"

#include "JsonObjectConverter.h"

namespace HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal
{
	const TCHAR* Magic120CellDedicatedTrainingMapPath =
		TEXT("/Game/HyperTwistTraining/Maps/L_HyperTwist_Magic120CellTraining");
	const TCHAR* MagicCube5DDedicatedTrainingMapPath =
		TEXT("/Game/HyperTwistTraining/Maps/L_HyperTwist_MagicCube5DTraining");

	template <typename TStringArrayType>
	void AppendUniqueStrings(TArray<FString>& OutValues, const TStringArrayType& InValues)
	{
		for (const FString& Value : InValues)
		{
			if (!Value.IsEmpty())
			{
				OutValues.AddUnique(Value);
			}
		}
	}

	FHyperTwistTrainingSourceAttribution MakeActivationAttribution(
		const FString& ActivationProfileId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceTrackId = TEXT("phase6c/higher-dimensional-runtime-activation");
		Attribution.SourceCaseId = ActivationProfileId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingSourceAttribution MakeLaunchAttribution(
		const FString& LaunchSurfaceId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceTrackId = TEXT("phase6c/higher-dimensional-runtime-launch");
		Attribution.SourceCaseId = LaunchSurfaceId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingSourceAttribution MakeHostAttribution(
		const FString& HostSurfaceId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceTrackId = TEXT("phase6c/higher-dimensional-runtime-host");
		Attribution.SourceCaseId = HostSurfaceId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingSourceAttribution MakeViewContextAttribution(
		const FString& ViewContextSurfaceId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceTrackId = TEXT("phase6c/higher-dimensional-runtime-view-context");
		Attribution.SourceCaseId = ViewContextSurfaceId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingSourceAttribution MakeSessionAttribution(
		const FString& SessionSurfaceId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceTrackId = TEXT("phase6c/higher-dimensional-runtime-session");
		Attribution.SourceCaseId = SessionSurfaceId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingSourceAttribution MakeInteractiveSceneAttribution(
		const FString& SceneSurfaceId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceTrackId = TEXT("phase6c/higher-dimensional-interactive-scene");
		Attribution.SourceCaseId = SceneSurfaceId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingImportedRuntimeSelector MakeSelector(
		const FString& SelectorId,
		const FString& Label,
		const FString& SelectorBinding
	)
	{
		FHyperTwistTrainingImportedRuntimeSelector Selector;
		Selector.SelectorId = SelectorId;
		Selector.Label = Label;
		Selector.SelectorBinding = SelectorBinding;
		return Selector;
	}

	FHyperTwistTrainingImportedRuntimeSelectorChoice MakeChoice(
		const FString& SelectorId,
		const FString& SelectorBinding,
		const FString& SelectedValue,
		const FString& DisplayValue
	)
	{
		FHyperTwistTrainingImportedRuntimeSelectorChoice Choice;
		Choice.SelectorId = SelectorId;
		Choice.SelectorBinding = SelectorBinding;
		Choice.SelectedValue = SelectedValue;
		Choice.DisplayValue = DisplayValue;
		return Choice;
	}

	template <typename TStruct>
	FString SerializeStructToJson(const TStruct& Value)
	{
		FString Json;
		FJsonObjectConverter::UStructToJsonObjectString(TStruct::StaticStruct(), &Value, Json, 0, 0);
		return Json;
	}

	template <typename TStruct>
	bool DeserializeJsonString(const FString& Json, TStruct& OutValue)
	{
		return !Json.IsEmpty()
			&& FJsonObjectConverter::JsonObjectStringToUStruct(
				Json,
				&OutValue,
				0,
				0);
	}

	bool AreImportedRuntimeSelectorsConsistent(
		const TArray<FHyperTwistTrainingImportedRuntimeSelector>& Selectors,
		const TArray<FHyperTwistTrainingImportedRuntimeSelectorChoice>& DefaultSelectorChoices
	)
	{
		if (Selectors.Num() == 0 || DefaultSelectorChoices.Num() == 0)
		{
			return false;
		}

		TSet<FString> SeenSelectorIds;
		for (const FHyperTwistTrainingImportedRuntimeSelector& Selector : Selectors)
		{
			if (!Selector.IsStructurallyValid())
			{
				return false;
			}

			const FString NormalizedSelectorId = Selector.SelectorId.ToLower();
			if (SeenSelectorIds.Contains(NormalizedSelectorId))
			{
				return false;
			}

			SeenSelectorIds.Add(NormalizedSelectorId);
		}

		TSet<FString> SeenChoiceSelectorIds;
		for (const FHyperTwistTrainingImportedRuntimeSelectorChoice& Choice : DefaultSelectorChoices)
		{
			if (!Choice.IsStructurallyValid())
			{
				return false;
			}

			const FString NormalizedSelectorId = Choice.SelectorId.ToLower();
			if (!SeenSelectorIds.Contains(NormalizedSelectorId)
				|| SeenChoiceSelectorIds.Contains(NormalizedSelectorId))
			{
				return false;
			}

			SeenChoiceSelectorIds.Add(NormalizedSelectorId);
		}

		return SeenChoiceSelectorIds.Num() == SeenSelectorIds.Num();
	}

	bool TryGetMagic120CellContracts(
		FHyperTwistTrainingMagic120CellRuntimeProfileContract& OutRuntimeProfile,
		FHyperTwistTrainingMagic120CellPersistenceBoundary& OutPersistenceBoundary,
		FHyperTwistTrainingMagic120CellViewProfileContract& OutViewProfile
	)
	{
		const FHyperTwistTrainingMagic120CellReferenceBundle Bundle =
			UHyperTwistTrainingMagic120CellLibrary::BuildBundledMagic120CellReferenceBundle();
		return UHyperTwistTrainingMagic120CellLibrary::TryGetRuntimeProfileContractById(
				Bundle,
				Bundle.PrimaryRuntimeProfileContractId,
				OutRuntimeProfile)
			&& UHyperTwistTrainingMagic120CellLibrary::TryGetPersistenceBoundaryById(
				Bundle,
				Bundle.PrimaryPersistenceBoundaryId,
				OutPersistenceBoundary)
			&& UHyperTwistTrainingMagic120CellLibrary::TryGetViewProfileContractById(
				Bundle,
				Bundle.PrimaryViewProfileContractId,
				OutViewProfile);
	}

	bool TryGetMagicCube5DContracts(
		FHyperTwistTrainingMagicCube5DRuntimeProfileContract& OutRuntimeProfile,
		FHyperTwistTrainingMagicCube5DPersistenceBoundary& OutPersistenceBoundary,
		FHyperTwistTrainingMagicCube5DViewProfileContract& OutViewProfile
	)
	{
		const FHyperTwistTrainingMagicCube5DReferenceBundle Bundle =
			UHyperTwistTrainingMagicCube5DLibrary::BuildBundledMagicCube5DReferenceBundle();
		return UHyperTwistTrainingMagicCube5DLibrary::TryGetRuntimeProfileContractById(
				Bundle,
				Bundle.PrimaryRuntimeProfileContractId,
				OutRuntimeProfile)
			&& UHyperTwistTrainingMagicCube5DLibrary::TryGetPersistenceBoundaryById(
				Bundle,
				Bundle.PrimaryPersistenceBoundaryId,
				OutPersistenceBoundary)
			&& UHyperTwistTrainingMagicCube5DLibrary::TryGetViewProfileContractById(
				Bundle,
				Bundle.PrimaryViewProfileContractId,
				OutViewProfile);
	}

	FHyperTwistSimulationSceneContext BuildInteractiveSceneContext(
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile,
		const FString& SessionSurfaceId,
		const FString& SceneContextId,
		const EHyperTwistStateEncodingKind StateEncodingKind,
		const FString& EncodingProfile,
		const FString& PayloadJson,
		const FString& OrientationReference,
		const FString& ProjectionProfile,
		const float ProjectionDepth,
		const FString& RenderStateProfile,
		const FString& Notes
	)
	{
		FHyperTwistSimulationSceneContext SceneContext;
		if (!Profile.IsStructurallyValid())
		{
			return SceneContext;
		}

		SceneContext.SceneContextId = SceneContextId;
		SceneContext.PuzzleState.Definition = Profile.ToDefinitionRef();
		SceneContext.PuzzleState.StateEncodingKind = StateEncodingKind;
		SceneContext.PuzzleState.StateEncoding.EncodingProfile = EncodingProfile;
		SceneContext.PuzzleState.StateEncoding.PayloadJson = PayloadJson;
		SceneContext.PuzzleState.OrientationFrame.Reference = OrientationReference;
		SceneContext.PuzzleState.bIsSolved = true;
		SceneContext.PuzzleState.Source = EHyperTwistStateSource::Runtime;
		SceneContext.PuzzleState.CapturedAtUtc = TEXT("2026-06-18T00:00:00Z");
		SceneContext.PuzzleState.SourceSessionId = SessionSurfaceId;
		SceneContext.PuzzleState.Notes = Notes;
		SceneContext.ProjectionSettings.ProjectionKind = EHyperTwistProjectionKind::HyperProjection;
		SceneContext.ProjectionSettings.ProjectionProfile = ProjectionProfile;
		SceneContext.ProjectionSettings.ProjectionDepth = ProjectionDepth;
		SceneContext.RenderStateProfile = RenderStateProfile;
		return SceneContext;
	}

	bool ContainsSelectorId(
		const TArray<FHyperTwistTrainingImportedRuntimeSelector>& Selectors,
		const FString& SelectorId
	)
	{
		for (const FHyperTwistTrainingImportedRuntimeSelector& Selector : Selectors)
		{
			if (Selector.SelectorId.Equals(SelectorId, ESearchCase::IgnoreCase))
			{
				return true;
			}
		}

		return false;
	}

	bool ContainsSelectorChoiceId(
		const TArray<FHyperTwistTrainingImportedRuntimeSelectorChoice>& Choices,
		const FString& SelectorId
	)
	{
		for (const FHyperTwistTrainingImportedRuntimeSelectorChoice& Choice : Choices)
		{
			if (Choice.SelectorId.Equals(SelectorId, ESearchCase::IgnoreCase))
			{
				return true;
			}
		}

		return false;
	}

	void AppendUniqueSelectors(
		TArray<FHyperTwistTrainingImportedRuntimeSelector>& OutSelectors,
		const TArray<FHyperTwistTrainingImportedRuntimeSelector>& InSelectors
	)
	{
		for (const FHyperTwistTrainingImportedRuntimeSelector& Selector : InSelectors)
		{
			if (Selector.IsStructurallyValid()
				&& !ContainsSelectorId(OutSelectors, Selector.SelectorId))
			{
				OutSelectors.Add(Selector);
			}
		}
	}

	void AppendUniqueSelectorChoices(
		TArray<FHyperTwistTrainingImportedRuntimeSelectorChoice>& OutChoices,
		const TArray<FHyperTwistTrainingImportedRuntimeSelectorChoice>& InChoices
	)
	{
		for (const FHyperTwistTrainingImportedRuntimeSelectorChoice& Choice : InChoices)
		{
			if (Choice.IsStructurallyValid()
				&& !ContainsSelectorChoiceId(OutChoices, Choice.SelectorId))
			{
				OutChoices.Add(Choice);
			}
		}
	}

	void AppendMagic120CellCapabilityTags(
		const FHyperTwistTrainingMagic120CellRuntimeProfileContract& RuntimeProfile,
		const FHyperTwistTrainingMagic120CellPersistenceBoundary& PersistenceBoundary,
		const FHyperTwistTrainingMagic120CellViewProfileContract& ViewProfile,
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& OutProfile
	)
	{
		AppendUniqueStrings(OutProfile.RequiredPackageIds, RuntimeProfile.RequiredPackageIds);
		AppendUniqueStrings(OutProfile.RequiredPackageIds, PersistenceBoundary.RequiredPackageIds);
		AppendUniqueStrings(OutProfile.RequiredPackageIds, ViewProfile.RequiredPackageIds);

		AppendUniqueStrings(OutProfile.CapabilityTags, RuntimeProfile.PuzzleTypeSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, RuntimeProfile.SymmetrySurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, RuntimeProfile.VisibilitySurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, PersistenceBoundary.PersistenceSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, PersistenceBoundary.TwistHistorySurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.ProjectionSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.SymmetryPresetTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.VisibilityPresetTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.FocusSurfaceTags);
	}

	void AppendMagicCube5DCapabilityTags(
		const FHyperTwistTrainingMagicCube5DRuntimeProfileContract& RuntimeProfile,
		const FHyperTwistTrainingMagicCube5DPersistenceBoundary& PersistenceBoundary,
		const FHyperTwistTrainingMagicCube5DViewProfileContract& ViewProfile,
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& OutProfile
	)
	{
		AppendUniqueStrings(OutProfile.RequiredPackageIds, RuntimeProfile.RequiredPackageIds);
		AppendUniqueStrings(OutProfile.RequiredPackageIds, PersistenceBoundary.RequiredPackageIds);
		AppendUniqueStrings(OutProfile.RequiredPackageIds, ViewProfile.RequiredPackageIds);

		AppendUniqueStrings(OutProfile.CapabilityTags, RuntimeProfile.OrderSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, RuntimeProfile.InteractionSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, RuntimeProfile.ProgressSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, PersistenceBoundary.PersistenceSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, PersistenceBoundary.TwistHistorySurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, PersistenceBoundary.MacroSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.ProjectionSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.StereoSurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.VisibilitySurfaceTags);
		AppendUniqueStrings(OutProfile.CapabilityTags, ViewProfile.FocusSurfaceTags);
	}

	FHyperTwistTrainingMagic120CellInteractiveSceneStateEnvelope
	BuildMagic120CellInteractiveSceneStateEnvelope(
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile,
		const FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& SessionSurface,
		const FHyperTwistTrainingMagic120CellPersistenceBoundary& PersistenceBoundary,
		const FHyperTwistTrainingMagic120CellViewProfileContract& ViewProfile
	)
	{
		FHyperTwistTrainingMagic120CellInteractiveSceneStateEnvelope Envelope;
		if (!Profile.IsStructurallyValid() || !SessionSurface.IsStructurallyValid())
		{
			return Envelope;
		}

		Envelope.EnvelopeId = TEXT("phase6c/magic120cell/interactive-scene-state");
		Envelope.SessionSurfaceId = SessionSurface.SessionSurfaceId;
		Envelope.ActivationProfileId = Profile.ActivationProfileId;
		Envelope.PuzzleId = Profile.PuzzleId;
		Envelope.RuntimeModeId = SessionSurface.RuntimeModeId;
		Envelope.PersistenceBoundaryId = PersistenceBoundary.BoundaryId;
		Envelope.ViewProfileContractId = ViewProfile.ContractId;
		Envelope.ProjectionProfile = TEXT("magic120cell-4d-projection-distance-v1");
		Envelope.ProjectionDepth = 4.0f;
		Envelope.PuzzleTypeModeId = TEXT("full-puzzle-default-mode");
		Envelope.SymmetryPresetId = TEXT("torus-visibility-groups");
		Envelope.VisibilityPresetId = TEXT("logical-visibility-depth-ladder");
		Envelope.FocusPresetId = TEXT("center-cell-recentering");
		Envelope.PersistenceFormatId = TEXT("magic120cell/version1-header-hex-facelets-v1");
		Envelope.TwistHistoryFormatId = TEXT("magic120cell/twist-history-ledger-v1");
		Envelope.ViewRotationPolicyId = TEXT("magic120cell/view-rotation-guard-rails-v1");
		Envelope.VisibleGroupIds =
		{
			TEXT("torus-groups"),
			TEXT("hypercube-groups"),
			TEXT("layer-groups"),
			TEXT("ring-groups")
		};
		AppendUniqueStrings(
			Envelope.PersistenceSurfaceTags,
			PersistenceBoundary.PersistenceSurfaceTags);
		AppendUniqueStrings(
			Envelope.PersistenceSurfaceTags,
			PersistenceBoundary.TwistHistorySurfaceTags);
		AppendUniqueStrings(
			Envelope.PersistenceSurfaceTags,
			ViewProfile.ProjectionSurfaceTags);
		AppendUniqueStrings(
			Envelope.PersistenceSurfaceTags,
			ViewProfile.VisibilityPresetTags);
		return Envelope;
	}

	FHyperTwistTrainingMagicCube5DInteractiveSceneStateEnvelope
	BuildMagicCube5DInteractiveSceneStateEnvelope(
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile,
		const FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& SessionSurface,
		const FHyperTwistTrainingMagicCube5DPersistenceBoundary& PersistenceBoundary,
		const FHyperTwistTrainingMagicCube5DViewProfileContract& ViewProfile
	)
	{
		FHyperTwistTrainingMagicCube5DInteractiveSceneStateEnvelope Envelope;
		if (!Profile.IsStructurallyValid() || !SessionSurface.IsStructurallyValid())
		{
			return Envelope;
		}

		Envelope.EnvelopeId = TEXT("phase6c/magiccube5d/interactive-scene-state");
		Envelope.SessionSurfaceId = SessionSurface.SessionSurfaceId;
		Envelope.ActivationProfileId = Profile.ActivationProfileId;
		Envelope.PuzzleId = Profile.PuzzleId;
		Envelope.RuntimeModeId = SessionSurface.RuntimeModeId;
		Envelope.PersistenceBoundaryId = PersistenceBoundary.BoundaryId;
		Envelope.ViewProfileContractId = ViewProfile.ContractId;
		Envelope.ProjectionProfile = TEXT("magiccube5d-5d-projection-distance-v1");
		Envelope.ProjectionDepth = 5.0f;
		Envelope.PuzzleOrder = 3;
		Envelope.StereoModeId = TEXT("stereo-disabled-default");
		Envelope.VisibilityPresetId = TEXT("all-faces-visible-default");
		Envelope.FocusPresetId = TEXT("view-centered-solved-progress");
		Envelope.AccentProfileId = TEXT("order-three-default-accent");
		Envelope.PersistenceFormatId = TEXT("magiccube5d/version1-ten-face-state-matrix-v1");
		Envelope.TwistHistoryFormatId = TEXT("magiccube5d/compact-twist-token-v1");
		Envelope.MacroFormatId = TEXT("magiccube5d/macros-sidecar-v1");
		Envelope.VisibleFaceIds =
		{
			TEXT("x-negative"),
			TEXT("x-positive"),
			TEXT("y-negative"),
			TEXT("y-positive"),
			TEXT("z-negative"),
			TEXT("z-positive"),
			TEXT("w-negative"),
			TEXT("w-positive"),
			TEXT("v-negative"),
			TEXT("v-positive")
		};
		AppendUniqueStrings(
			Envelope.SolvedProgressSurfaceTags,
			PersistenceBoundary.PersistenceSurfaceTags);
		AppendUniqueStrings(
			Envelope.SolvedProgressSurfaceTags,
			PersistenceBoundary.TwistHistorySurfaceTags);
		AppendUniqueStrings(
			Envelope.SolvedProgressSurfaceTags,
			PersistenceBoundary.MacroSurfaceTags);
		AppendUniqueStrings(
			Envelope.SolvedProgressSurfaceTags,
			ViewProfile.FocusSurfaceTags);
		return Envelope;
	}

	FHyperTwistSimulationSceneContext BuildMagic120CellInteractiveSceneContext(
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile,
		const FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& SessionSurface,
		const FHyperTwistTrainingMagic120CellInteractiveSceneStateEnvelope& Envelope
	)
	{
		return BuildInteractiveSceneContext(
			Profile,
			SessionSurface.SessionSurfaceId,
			TEXT("phase6c/magic120cell/interactive-scene-context"),
			EHyperTwistStateEncodingKind::FamilySpecific,
			TEXT("magic120cell-family-owned-scene-state-v1"),
			SerializeStructToJson(Envelope),
			TEXT("magic120cell-center-cell-runtime-frame-v1"),
			Envelope.ProjectionProfile,
			Envelope.ProjectionDepth,
			TEXT("magic120cell-center-cell-focus-scene-runtime-v1"),
			TEXT("Family-owned Magic120Cell interactive scene state envelope with dedicated persistence, projection, symmetry, and focus ownership above the dedicated family training shell.")
		);
	}

	FHyperTwistSimulationSceneContext BuildMagicCube5DInteractiveSceneContext(
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile,
		const FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& SessionSurface,
		const FHyperTwistTrainingMagicCube5DInteractiveSceneStateEnvelope& Envelope
	)
	{
		return BuildInteractiveSceneContext(
			Profile,
			SessionSurface.SessionSurfaceId,
			TEXT("phase6c/magiccube5d/interactive-scene-context"),
			EHyperTwistStateEncodingKind::FamilySpecific,
			TEXT("magiccube5d-family-owned-scene-state-v1"),
			SerializeStructToJson(Envelope),
			TEXT("magiccube5d-signed-axis-runtime-frame-v1"),
			Envelope.ProjectionProfile,
			Envelope.ProjectionDepth,
			TEXT("magiccube5d-order3-scene-runtime-v1"),
			TEXT("Family-owned MagicCube5D interactive scene state envelope with dedicated persistence, solved-progress, projection, stereo, visibility, and focus ownership above the dedicated family training shell.")
		);
	}

	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile BuildMagic120CellActivationProfile()
	{
		const FHyperTwistTrainingMagic120CellReferenceBundle Bundle =
			UHyperTwistTrainingMagic120CellLibrary::BuildBundledMagic120CellReferenceBundle();

		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!Bundle.IsStructurallyValid())
		{
			return Profile;
		}

		FHyperTwistTrainingMagic120CellRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagic120CellPersistenceBoundary PersistenceBoundary;
		FHyperTwistTrainingMagic120CellViewProfileContract ViewProfile;
		FHyperTwistTrainingMagic120CellAttributionBoundary AttributionBoundary;
		if (!UHyperTwistTrainingMagic120CellLibrary::TryGetRuntimeProfileContractById(
				Bundle,
				Bundle.PrimaryRuntimeProfileContractId,
				RuntimeProfile
			)
			|| !UHyperTwistTrainingMagic120CellLibrary::TryGetPersistenceBoundaryById(
				Bundle,
				Bundle.PrimaryPersistenceBoundaryId,
				PersistenceBoundary
			)
			|| !UHyperTwistTrainingMagic120CellLibrary::TryGetViewProfileContractById(
				Bundle,
				Bundle.PrimaryViewProfileContractId,
				ViewProfile
			)
			|| !UHyperTwistTrainingMagic120CellLibrary::TryGetAttributionBoundaryById(
				Bundle,
				Bundle.PrimaryAttributionBoundaryId,
				AttributionBoundary
			))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
		}

		Profile.ActivationProfileId = TEXT("magic120cell-cleanroom-runtime-activation");
		Profile.Title = TEXT("Magic120Cell clean-room runtime activation");
		Profile.Summary = TEXT("First-party HyperTwist activation profile for the dedicated Magic120Cell family above the bounded retained donor contracts and the retained Hyperspeedcube runtime anchor.");
		Profile.PuzzleId = TEXT("polychoron/magic120cell");
		Profile.RuntimeModeId = TEXT("magic120cell-full-color-runtime-v1");
		Profile.RuntimeStrategyId = TEXT("phase6c/unreal-cleanroom-family-runtime");
		Profile.RuntimeAnchorId = TEXT("retained/hyperspeedcube-runtime-anchor");
		Profile.PuzzleFamily = EHyperTwistPuzzleFamily::Other;
		Profile.Dimension = 4;
		Profile.DefinitionVersion = TEXT("2026.06");
		Profile.NotationProfile = TEXT("magic120cell-family");
		Profile.Variant = TEXT("full-color");
		Profile.bRequiresExternalProcess = false;
		Profile.PrimaryRuntimeProfileContractId = RuntimeProfile.ContractId;
		Profile.PrimaryPersistenceBoundaryId = PersistenceBoundary.BoundaryId;
		Profile.PrimaryViewProfileContractId = ViewProfile.ContractId;
		Profile.PrimaryAttributionBoundaryId = AttributionBoundary.BoundaryId;
		Profile.DefaultSelectionTags =
		{
			TEXT("full-color puzzle type"),
			TEXT("full-puzzle default mode"),
			TEXT("logical visibility depth ladder"),
			TEXT("center-cell recentering")
		};

		AppendMagic120CellCapabilityTags(RuntimeProfile, PersistenceBoundary, ViewProfile, Profile);
		Profile.RequiredNoticeActions = AttributionBoundary.RequiredNoticeActions;
		AppendUniqueStrings(Profile.ExplicitExclusions, RuntimeProfile.ExplicitExclusions);
		AppendUniqueStrings(Profile.ExplicitExclusions, PersistenceBoundary.ExplicitExclusions);
		AppendUniqueStrings(Profile.ExplicitExclusions, ViewProfile.ExplicitExclusions);
		AppendUniqueStrings(Profile.ExplicitExclusions, AttributionBoundary.ExplicitExclusions);
		Profile.SourceAttribution = MakeActivationAttribution(
			Profile.ActivationProfileId,
			TEXT("First-party Phase 6C clean-room activation profile layered above the bounded Magic120Cell donor contracts without widening into a generic topology shell or external-process host.")
		);
		return Profile;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeHostSurface BuildMagic120CellHostSurface()
	{
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog ActivationCatalog =
			UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeActivationCatalog();
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileById(
				ActivationCatalog,
				TEXT("magic120cell-cleanroom-runtime-activation"),
				Profile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeHostSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		HostSurface.HostSurfaceId = TEXT("phase6c/magic120cell/runtime-host-surface");
		HostSurface.ActivationProfileId = Profile.ActivationProfileId;
		HostSurface.Title = TEXT("Magic120Cell dedicated-family host surface");
		HostSurface.Summary = TEXT("Explicit dedicated-family host seam for Magic120Cell that now boots through the authored first-party family training shell and no longer falls back to the shared higher-dimensional map.");
		HostSurface.PreferredHostMapPath = Magic120CellDedicatedTrainingMapPath;
		HostSurface.PreferredHostMapRouteId = TEXT("phase6c/magic120cell/dedicated-training-map-host");
		HostSurface.PreferredHostMapLabel = TEXT("Magic120Cell dedicated training shell");
		HostSurface.EffectiveHostMapPath = Magic120CellDedicatedTrainingMapPath;
		HostSurface.EffectiveHostMapRouteId = TEXT("phase6c/magic120cell/dedicated-training-map-host");
		HostSurface.EffectiveHostMapLabel = TEXT("Magic120Cell dedicated training shell");
		HostSurface.bDedicatedFamilyHostMapAuthored = true;
		HostSurface.bUsesSharedTrainingMapFallback = false;
		HostSurface.HostTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("host-surface"),
			TEXT("family:magic120cell"),
			TEXT("preferred-host:dedicated-family-map"),
			TEXT("effective-host:dedicated-family-map")
		};
		HostSurface.SourceAttribution = MakeHostAttribution(
			HostSurface.HostSurfaceId,
			TEXT("Phase 6C explicit host-surface seam for Magic120Cell that now routes owned launch and runtime execution through the authored dedicated-family training map.")
		);
		return HostSurface;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface BuildMagic120CellLaunchSurface()
	{
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog ActivationCatalog =
			UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeActivationCatalog();
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileById(
				ActivationCatalog,
				TEXT("magic120cell-cleanroom-runtime-activation"),
				Profile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeHostCatalog(),
				Profile.ActivationProfileId,
				HostSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		}

		FHyperTwistTrainingMagic120CellRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagic120CellPersistenceBoundary PersistenceBoundary;
		FHyperTwistTrainingMagic120CellViewProfileContract ViewProfile;
		if (!TryGetMagic120CellContracts(
				RuntimeProfile,
				PersistenceBoundary,
				ViewProfile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface LaunchSurface;
		LaunchSurface.LaunchSurfaceId = TEXT("phase6c/magic120cell/dedicated-training-launch-surface");
		LaunchSurface.ActivationProfileId = Profile.ActivationProfileId;
		LaunchSurface.HostSurfaceId = HostSurface.HostSurfaceId;
		LaunchSurface.Title = TEXT("Magic120Cell dedicated-family launch surface");
		LaunchSurface.Summary = TEXT("Dedicated-family launch surface that binds the Magic120Cell clean-room activation profile to the authored dedicated training shell, owned selector defaults, and the family-owned persistence execution path.");
		LaunchSurface.HostMapPath = HostSurface.EffectiveHostMapPath;
		LaunchSurface.HostMapRouteId = HostSurface.EffectiveHostMapRouteId;
		LaunchSurface.HostMapLabel = HostSurface.EffectiveHostMapLabel;
		LaunchSurface.bUsesSharedTrainingMapFallback = HostSurface.bUsesSharedTrainingMapFallback;
		LaunchSurface.DeckId = TEXT("phase6c/magic120cell/launch");
		LaunchSurface.SeedCaseId = TEXT("phase6c/magic120cell/launch/seed");
		LaunchSurface.SeedPromptLabel = TEXT("Magic120Cell launch seed");
		LaunchSurface.SurfaceId = TEXT("phase6c/magic120cell/generated-runtime-surface");
		LaunchSurface.SurfaceLabel = TEXT("Magic120Cell Runtime Surface");
		LaunchSurface.RuntimeModeId = Profile.RuntimeModeId;
		LaunchSurface.GeneratorType = TEXT("phase6c-higher-dimensional-dedicated-family");
		LaunchSurface.PrimaryPersistenceBoundaryId = PersistenceBoundary.BoundaryId;
		AppendUniqueStrings(
			LaunchSurface.PersistenceSurfaceTags,
			PersistenceBoundary.PersistenceSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.PersistenceSurfaceTags,
			PersistenceBoundary.TwistHistorySurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.InteractionSurfaceTags,
			RuntimeProfile.PuzzleTypeSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.InteractionSurfaceTags,
			RuntimeProfile.SymmetrySurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.InteractionSurfaceTags,
			RuntimeProfile.VisibilitySurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.ViewSurfaceTags,
			ViewProfile.ProjectionSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.ViewSurfaceTags,
			ViewProfile.VisibilityPresetTags);
		AppendUniqueStrings(
			LaunchSurface.ViewSurfaceTags,
			ViewProfile.FocusSurfaceTags);
		AppendUniqueStrings(LaunchSurface.LaunchTags, Profile.DefaultSelectionTags);
		AppendUniqueStrings(LaunchSurface.LaunchTags, Profile.CapabilityTags);
		AppendUniqueStrings(LaunchSurface.LaunchTags, HostSurface.HostTags);
		LaunchSurface.RequiredNoticeActions = Profile.RequiredNoticeActions;
		LaunchSurface.Selectors =
		{
			MakeSelector(TEXT("puzzle-type"), TEXT("Puzzle Type"), TEXT("puzzle-type")),
			MakeSelector(TEXT("visibility-depth"), TEXT("Visibility Depth"), TEXT("visibility-depth")),
			MakeSelector(TEXT("focus-mode"), TEXT("Focus Mode"), TEXT("focus-mode"))
		};
		LaunchSurface.DefaultSelectorChoices =
		{
			MakeChoice(TEXT("puzzle-type"), TEXT("puzzle-type"), TEXT("full-color"), TEXT("Full Color")),
			MakeChoice(TEXT("visibility-depth"), TEXT("visibility-depth"), TEXT("full-puzzle"), TEXT("Full Puzzle")),
			MakeChoice(TEXT("focus-mode"), TEXT("focus-mode"), TEXT("center-cell"), TEXT("Center Cell"))
		};
		LaunchSurface.SourceAttribution = MakeLaunchAttribution(
			LaunchSurface.LaunchSurfaceId,
			TEXT("Phase 6C dedicated-family launch surface for Magic120Cell on the authored host seam, replacing the shared-map bridge with a dedicated family training shell for owned generated-mode execution.")
		);
		return LaunchSurface;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile BuildMagicCube5DActivationProfile()
	{
		const FHyperTwistTrainingMagicCube5DReferenceBundle Bundle =
			UHyperTwistTrainingMagicCube5DLibrary::BuildBundledMagicCube5DReferenceBundle();

		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!Bundle.IsStructurallyValid())
		{
			return Profile;
		}

		FHyperTwistTrainingMagicCube5DRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagicCube5DPersistenceBoundary PersistenceBoundary;
		FHyperTwistTrainingMagicCube5DViewProfileContract ViewProfile;
		FHyperTwistTrainingMagicCube5DAttributionBoundary AttributionBoundary;
		if (!UHyperTwistTrainingMagicCube5DLibrary::TryGetRuntimeProfileContractById(
				Bundle,
				Bundle.PrimaryRuntimeProfileContractId,
				RuntimeProfile
			)
			|| !UHyperTwistTrainingMagicCube5DLibrary::TryGetPersistenceBoundaryById(
				Bundle,
				Bundle.PrimaryPersistenceBoundaryId,
				PersistenceBoundary
			)
			|| !UHyperTwistTrainingMagicCube5DLibrary::TryGetViewProfileContractById(
				Bundle,
				Bundle.PrimaryViewProfileContractId,
				ViewProfile
			)
			|| !UHyperTwistTrainingMagicCube5DLibrary::TryGetAttributionBoundaryById(
				Bundle,
				Bundle.PrimaryAttributionBoundaryId,
				AttributionBoundary
			))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
		}

		Profile.ActivationProfileId = TEXT("magiccube5d-cleanroom-runtime-activation");
		Profile.Title = TEXT("MagicCube5D clean-room runtime activation");
		Profile.Summary = TEXT("First-party HyperTwist activation profile for the bounded order-three MagicCube5D launch posture above the retained donor contracts and the retained Hyperspeedcube runtime anchor.");
		Profile.PuzzleId = TEXT("hypercube/magiccube5d/order3");
		Profile.RuntimeModeId = TEXT("magiccube5d-order3-runtime-v1");
		Profile.RuntimeStrategyId = TEXT("phase6c/unreal-cleanroom-family-runtime");
		Profile.RuntimeAnchorId = TEXT("retained/hyperspeedcube-runtime-anchor");
		Profile.PuzzleFamily = EHyperTwistPuzzleFamily::Hypercube;
		Profile.Dimension = 5;
		Profile.DefinitionVersion = TEXT("2026.06");
		Profile.NotationProfile = TEXT("magiccube5d-family");
		Profile.SizeVector = {3, 3, 3, 3, 3};
		Profile.Variant = TEXT("order-3");
		Profile.bRequiresExternalProcess = false;
		Profile.PrimaryRuntimeProfileContractId = RuntimeProfile.ContractId;
		Profile.PrimaryPersistenceBoundaryId = PersistenceBoundary.BoundaryId;
		Profile.PrimaryViewProfileContractId = ViewProfile.ContractId;
		Profile.PrimaryAttributionBoundaryId = AttributionBoundary.BoundaryId;
		Profile.DefaultSelectionTags =
		{
			TEXT("order-three default family mode"),
			TEXT("stereo disabled default"),
			TEXT("all-faces visible default"),
			TEXT("control-click fifth-axis view rotation")
		};

		AppendMagicCube5DCapabilityTags(RuntimeProfile, PersistenceBoundary, ViewProfile, Profile);
		Profile.RequiredNoticeActions = AttributionBoundary.RequiredNoticeActions;
		AppendUniqueStrings(Profile.ExplicitExclusions, RuntimeProfile.ExplicitExclusions);
		AppendUniqueStrings(Profile.ExplicitExclusions, PersistenceBoundary.ExplicitExclusions);
		AppendUniqueStrings(Profile.ExplicitExclusions, ViewProfile.ExplicitExclusions);
		AppendUniqueStrings(Profile.ExplicitExclusions, AttributionBoundary.ExplicitExclusions);
		Profile.SourceAttribution = MakeActivationAttribution(
			Profile.ActivationProfileId,
			TEXT("First-party Phase 6C clean-room activation profile layered above the bounded MagicCube5D donor contracts without widening into a generic hyper-runtime shell or external-process host.")
		);
		return Profile;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeHostSurface BuildMagicCube5DHostSurface()
	{
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog ActivationCatalog =
			UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeActivationCatalog();
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileById(
				ActivationCatalog,
				TEXT("magiccube5d-cleanroom-runtime-activation"),
				Profile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeHostSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		HostSurface.HostSurfaceId = TEXT("phase6c/magiccube5d/runtime-host-surface");
		HostSurface.ActivationProfileId = Profile.ActivationProfileId;
		HostSurface.Title = TEXT("MagicCube5D dedicated-family host surface");
		HostSurface.Summary = TEXT("Explicit dedicated-family host seam for MagicCube5D that now boots through the authored first-party family training shell and no longer falls back to the shared higher-dimensional map.");
		HostSurface.PreferredHostMapPath = MagicCube5DDedicatedTrainingMapPath;
		HostSurface.PreferredHostMapRouteId = TEXT("phase6c/magiccube5d/dedicated-training-map-host");
		HostSurface.PreferredHostMapLabel = TEXT("MagicCube5D dedicated training shell");
		HostSurface.EffectiveHostMapPath = MagicCube5DDedicatedTrainingMapPath;
		HostSurface.EffectiveHostMapRouteId = TEXT("phase6c/magiccube5d/dedicated-training-map-host");
		HostSurface.EffectiveHostMapLabel = TEXT("MagicCube5D dedicated training shell");
		HostSurface.bDedicatedFamilyHostMapAuthored = true;
		HostSurface.bUsesSharedTrainingMapFallback = false;
		HostSurface.HostTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("host-surface"),
			TEXT("family:magiccube5d"),
			TEXT("preferred-host:dedicated-family-map"),
			TEXT("effective-host:dedicated-family-map")
		};
		HostSurface.SourceAttribution = MakeHostAttribution(
			HostSurface.HostSurfaceId,
			TEXT("Phase 6C explicit host-surface seam for MagicCube5D that now routes owned launch and runtime execution through the authored dedicated-family training map.")
		);
		return HostSurface;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface BuildMagicCube5DLaunchSurface()
	{
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog ActivationCatalog =
			UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeActivationCatalog();
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileById(
				ActivationCatalog,
				TEXT("magiccube5d-cleanroom-runtime-activation"),
				Profile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeHostCatalog(),
				Profile.ActivationProfileId,
				HostSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		}

		FHyperTwistTrainingMagicCube5DRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagicCube5DPersistenceBoundary PersistenceBoundary;
		FHyperTwistTrainingMagicCube5DViewProfileContract ViewProfile;
		if (!TryGetMagicCube5DContracts(
				RuntimeProfile,
				PersistenceBoundary,
				ViewProfile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface LaunchSurface;
		LaunchSurface.LaunchSurfaceId = TEXT("phase6c/magiccube5d/dedicated-training-launch-surface");
		LaunchSurface.ActivationProfileId = Profile.ActivationProfileId;
		LaunchSurface.HostSurfaceId = HostSurface.HostSurfaceId;
		LaunchSurface.Title = TEXT("MagicCube5D dedicated-family launch surface");
		LaunchSurface.Summary = TEXT("Dedicated-family launch surface that binds the MagicCube5D clean-room activation profile to the authored dedicated training shell, owned selector defaults, and the family-owned persistence execution path.");
		LaunchSurface.HostMapPath = HostSurface.EffectiveHostMapPath;
		LaunchSurface.HostMapRouteId = HostSurface.EffectiveHostMapRouteId;
		LaunchSurface.HostMapLabel = HostSurface.EffectiveHostMapLabel;
		LaunchSurface.bUsesSharedTrainingMapFallback = HostSurface.bUsesSharedTrainingMapFallback;
		LaunchSurface.DeckId = TEXT("phase6c/magiccube5d/launch");
		LaunchSurface.SeedCaseId = TEXT("phase6c/magiccube5d/launch/seed");
		LaunchSurface.SeedPromptLabel = TEXT("MagicCube5D launch seed");
		LaunchSurface.SurfaceId = TEXT("phase6c/magiccube5d/generated-runtime-surface");
		LaunchSurface.SurfaceLabel = TEXT("MagicCube5D Runtime Surface");
		LaunchSurface.RuntimeModeId = Profile.RuntimeModeId;
		LaunchSurface.GeneratorType = TEXT("phase6c-higher-dimensional-dedicated-family");
		LaunchSurface.PrimaryPersistenceBoundaryId = PersistenceBoundary.BoundaryId;
		AppendUniqueStrings(
			LaunchSurface.PersistenceSurfaceTags,
			PersistenceBoundary.PersistenceSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.PersistenceSurfaceTags,
			PersistenceBoundary.TwistHistorySurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.PersistenceSurfaceTags,
			PersistenceBoundary.MacroSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.InteractionSurfaceTags,
			RuntimeProfile.OrderSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.InteractionSurfaceTags,
			RuntimeProfile.InteractionSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.InteractionSurfaceTags,
			RuntimeProfile.ProgressSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.ViewSurfaceTags,
			ViewProfile.ProjectionSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.ViewSurfaceTags,
			ViewProfile.StereoSurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.ViewSurfaceTags,
			ViewProfile.VisibilitySurfaceTags);
		AppendUniqueStrings(
			LaunchSurface.ViewSurfaceTags,
			ViewProfile.FocusSurfaceTags);
		AppendUniqueStrings(LaunchSurface.LaunchTags, Profile.DefaultSelectionTags);
		AppendUniqueStrings(LaunchSurface.LaunchTags, Profile.CapabilityTags);
		AppendUniqueStrings(LaunchSurface.LaunchTags, HostSurface.HostTags);
		LaunchSurface.RequiredNoticeActions = Profile.RequiredNoticeActions;
		LaunchSurface.Selectors =
		{
			MakeSelector(TEXT("family-mode"), TEXT("Family Mode"), TEXT("family-mode")),
			MakeSelector(TEXT("stereo"), TEXT("Stereo"), TEXT("stereo")),
			MakeSelector(TEXT("visibility"), TEXT("Visibility"), TEXT("visibility"))
		};
		LaunchSurface.DefaultSelectorChoices =
		{
			MakeChoice(TEXT("family-mode"), TEXT("family-mode"), TEXT("order3"), TEXT("Order 3")),
			MakeChoice(TEXT("stereo"), TEXT("stereo"), TEXT("off"), TEXT("Stereo Off")),
			MakeChoice(TEXT("visibility"), TEXT("visibility"), TEXT("all-faces"), TEXT("All Faces"))
		};
		LaunchSurface.SourceAttribution = MakeLaunchAttribution(
			LaunchSurface.LaunchSurfaceId,
			TEXT("Phase 6C dedicated-family launch surface for MagicCube5D on the authored host seam, replacing the shared-map bridge with a dedicated family training shell for owned generated-mode execution.")
		);
		return LaunchSurface;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface BuildMagic120CellViewContextSurface()
	{
		FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface LaunchSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeLaunchSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeLaunchCatalog(),
				TEXT("magic120cell-cleanroom-runtime-activation"),
				LaunchSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeHostCatalog(),
				LaunchSurface.ActivationProfileId,
				HostSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		}

		FHyperTwistTrainingMagic120CellViewProfileContract ViewProfile;
		FHyperTwistTrainingMagic120CellRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagic120CellPersistenceBoundary PersistenceBoundary;
		if (!TryGetMagic120CellContracts(
				RuntimeProfile,
				PersistenceBoundary,
				ViewProfile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface ViewContextSurface;
		ViewContextSurface.ViewContextSurfaceId =
			TEXT("phase6c/magic120cell/dedicated-training-view-context-surface");
		ViewContextSurface.ActivationProfileId = LaunchSurface.ActivationProfileId;
		ViewContextSurface.LaunchSurfaceId = LaunchSurface.LaunchSurfaceId;
		ViewContextSurface.HostSurfaceId = HostSurface.HostSurfaceId;
		ViewContextSurface.Title = TEXT("Magic120Cell dedicated-family view context surface");
		ViewContextSurface.Summary =
			TEXT("Dedicated-family view-context surface that keeps the Magic120Cell projection, symmetry, visibility, and focus posture explicit above the dedicated family training shell.");
		ViewContextSurface.HostMapPath = HostSurface.EffectiveHostMapPath;
		ViewContextSurface.HostMapRouteId = HostSurface.EffectiveHostMapRouteId;
		ViewContextSurface.HostMapLabel = HostSurface.EffectiveHostMapLabel;
		ViewContextSurface.bUsesSharedTrainingMapFallback =
			HostSurface.bUsesSharedTrainingMapFallback;
		ViewContextSurface.PrimaryViewProfileContractId = ViewProfile.ContractId;
		AppendUniqueStrings(
			ViewContextSurface.ProjectionSurfaceTags,
			ViewProfile.ProjectionSurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.ContextSurfaceTags,
			ViewProfile.SymmetryPresetTags);
		AppendUniqueStrings(
			ViewContextSurface.ContextSurfaceTags,
			ViewProfile.VisibilityPresetTags);
		AppendUniqueStrings(
			ViewContextSurface.FocusSurfaceTags,
			ViewProfile.FocusSurfaceTags);
		ViewContextSurface.ViewTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("view-context"),
			TEXT("family:magic120cell"),
			TEXT("host:dedicated-family-map"),
			FString::Printf(TEXT("activation-profile:%s"),
				*LaunchSurface.ActivationProfileId.ToLower()),
			FString::Printf(TEXT("host-surface:%s"),
				*HostSurface.HostSurfaceId.ToLower()),
			FString::Printf(TEXT("launch-surface:%s"),
				*LaunchSurface.LaunchSurfaceId.ToLower())
		};
		AppendUniqueStrings(ViewContextSurface.ViewTags, LaunchSurface.ViewSurfaceTags);
		AppendUniqueStrings(ViewContextSurface.ViewTags, HostSurface.HostTags);
		AppendUniqueStrings(
			ViewContextSurface.ViewTags,
			ViewContextSurface.ProjectionSurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.ViewTags,
			ViewContextSurface.ContextSurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.ViewTags,
			ViewContextSurface.FocusSurfaceTags);
		ViewContextSurface.Selectors =
		{
			MakeSelector(TEXT("projection"), TEXT("Projection"), TEXT("projection")),
			MakeSelector(TEXT("symmetry"), TEXT("Symmetry"), TEXT("symmetry")),
			MakeSelector(TEXT("visibility"), TEXT("Visibility"), TEXT("visibility")),
			MakeSelector(TEXT("focus"), TEXT("Focus"), TEXT("focus"))
		};
		ViewContextSurface.DefaultSelectorChoices =
		{
			MakeChoice(TEXT("projection"), TEXT("projection"), TEXT("4d-projection-distance"), TEXT("4D Projection Distance")),
			MakeChoice(TEXT("symmetry"), TEXT("symmetry"), TEXT("full-puzzle-default-mode"), TEXT("Full Puzzle Default")),
			MakeChoice(TEXT("visibility"), TEXT("visibility"), TEXT("logical-visibility-depth-ladder"), TEXT("Logical Visibility Ladder")),
			MakeChoice(TEXT("focus"), TEXT("focus"), TEXT("center-cell-recentering"), TEXT("Center Cell Recentering"))
		};
		ViewContextSurface.SourceAttribution = MakeViewContextAttribution(
			ViewContextSurface.ViewContextSurfaceId,
			TEXT("Phase 6C dedicated-family view-context surface for Magic120Cell on the authored host seam, preserving owned projection, symmetry, visibility, and focus defaults on the dedicated family training shell.")
		);
		return ViewContextSurface;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface BuildMagicCube5DViewContextSurface()
	{
		FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface LaunchSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeLaunchSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeLaunchCatalog(),
				TEXT("magiccube5d-cleanroom-runtime-activation"),
				LaunchSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeHostCatalog(),
				LaunchSurface.ActivationProfileId,
				HostSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		}

		FHyperTwistTrainingMagicCube5DViewProfileContract ViewProfile;
		FHyperTwistTrainingMagicCube5DRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagicCube5DPersistenceBoundary PersistenceBoundary;
		if (!TryGetMagicCube5DContracts(
				RuntimeProfile,
				PersistenceBoundary,
				ViewProfile))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface ViewContextSurface;
		ViewContextSurface.ViewContextSurfaceId =
			TEXT("phase6c/magiccube5d/dedicated-training-view-context-surface");
		ViewContextSurface.ActivationProfileId = LaunchSurface.ActivationProfileId;
		ViewContextSurface.LaunchSurfaceId = LaunchSurface.LaunchSurfaceId;
		ViewContextSurface.HostSurfaceId = HostSurface.HostSurfaceId;
		ViewContextSurface.Title = TEXT("MagicCube5D dedicated-family view context surface");
		ViewContextSurface.Summary =
			TEXT("Dedicated-family view-context surface that keeps the MagicCube5D projection, stereo, visibility, and focus posture explicit above the dedicated family training shell.");
		ViewContextSurface.HostMapPath = HostSurface.EffectiveHostMapPath;
		ViewContextSurface.HostMapRouteId = HostSurface.EffectiveHostMapRouteId;
		ViewContextSurface.HostMapLabel = HostSurface.EffectiveHostMapLabel;
		ViewContextSurface.bUsesSharedTrainingMapFallback =
			HostSurface.bUsesSharedTrainingMapFallback;
		ViewContextSurface.PrimaryViewProfileContractId = ViewProfile.ContractId;
		AppendUniqueStrings(
			ViewContextSurface.ProjectionSurfaceTags,
			ViewProfile.ProjectionSurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.ContextSurfaceTags,
			ViewProfile.StereoSurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.ContextSurfaceTags,
			ViewProfile.VisibilitySurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.FocusSurfaceTags,
			ViewProfile.FocusSurfaceTags);
		ViewContextSurface.ViewTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("view-context"),
			TEXT("family:magiccube5d"),
			TEXT("host:dedicated-family-map"),
			FString::Printf(TEXT("activation-profile:%s"),
				*LaunchSurface.ActivationProfileId.ToLower()),
			FString::Printf(TEXT("host-surface:%s"),
				*HostSurface.HostSurfaceId.ToLower()),
			FString::Printf(TEXT("launch-surface:%s"),
				*LaunchSurface.LaunchSurfaceId.ToLower())
		};
		AppendUniqueStrings(ViewContextSurface.ViewTags, LaunchSurface.ViewSurfaceTags);
		AppendUniqueStrings(ViewContextSurface.ViewTags, HostSurface.HostTags);
		AppendUniqueStrings(
			ViewContextSurface.ViewTags,
			ViewContextSurface.ProjectionSurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.ViewTags,
			ViewContextSurface.ContextSurfaceTags);
		AppendUniqueStrings(
			ViewContextSurface.ViewTags,
			ViewContextSurface.FocusSurfaceTags);
		ViewContextSurface.Selectors =
		{
			MakeSelector(TEXT("projection"), TEXT("Projection"), TEXT("projection")),
			MakeSelector(TEXT("stereo"), TEXT("Stereo"), TEXT("stereo")),
			MakeSelector(TEXT("visibility"), TEXT("Visibility"), TEXT("visibility")),
			MakeSelector(TEXT("focus"), TEXT("Focus"), TEXT("focus"))
		};
		ViewContextSurface.DefaultSelectorChoices =
		{
			MakeChoice(TEXT("projection"), TEXT("projection"), TEXT("5d-projection-distance"), TEXT("5D Projection Distance")),
			MakeChoice(TEXT("stereo"), TEXT("stereo"), TEXT("stereo-disabled-default"), TEXT("Stereo Disabled Default")),
			MakeChoice(TEXT("visibility"), TEXT("visibility"), TEXT("all-faces-visible-default"), TEXT("All Faces Visible")),
			MakeChoice(TEXT("focus"), TEXT("focus"), TEXT("view-centered-solved-progress"), TEXT("View-centered Solved Progress"))
		};
		ViewContextSurface.SourceAttribution = MakeViewContextAttribution(
			ViewContextSurface.ViewContextSurfaceId,
			TEXT("Phase 6C dedicated-family view-context surface for MagicCube5D on the authored host seam, preserving owned projection, stereo, visibility, and focus defaults on the dedicated family training shell.")
		);
		return ViewContextSurface;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface BuildMagic120CellSessionSurface()
	{
		FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface LaunchSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeLaunchSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeLaunchCatalog(),
				TEXT("magic120cell-cleanroom-runtime-activation"),
				LaunchSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface ViewContextSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeViewContextSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeViewContextCatalog(),
				LaunchSurface.ActivationProfileId,
				ViewContextSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeHostCatalog(),
				LaunchSurface.ActivationProfileId,
				HostSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface SessionSurface;
		SessionSurface.SessionSurfaceId =
			TEXT("phase6c/magic120cell/dedicated-training-session-surface");
		SessionSurface.ActivationProfileId = LaunchSurface.ActivationProfileId;
		SessionSurface.HostSurfaceId = HostSurface.HostSurfaceId;
		SessionSurface.LaunchSurfaceId = LaunchSurface.LaunchSurfaceId;
		SessionSurface.ViewContextSurfaceId = ViewContextSurface.ViewContextSurfaceId;
		SessionSurface.Title = TEXT("Magic120Cell dedicated-family runtime session surface");
		SessionSurface.Summary =
			TEXT("Dedicated-family runtime session surface that merges the Magic120Cell dedicated-family launch posture with the authored projection, symmetry, visibility, and focus defaults so the executed training session carries the owned higher-dimensional interaction shell on the dedicated training shell.");
		SessionSurface.HostMapPath = HostSurface.EffectiveHostMapPath;
		SessionSurface.HostMapRouteId = HostSurface.EffectiveHostMapRouteId;
		SessionSurface.HostMapLabel = HostSurface.EffectiveHostMapLabel;
		SessionSurface.bUsesSharedTrainingMapFallback = HostSurface.bUsesSharedTrainingMapFallback;
		SessionSurface.RuntimeModeId = LaunchSurface.RuntimeModeId;
		SessionSurface.PrimaryPersistenceBoundaryId = LaunchSurface.PrimaryPersistenceBoundaryId;
		SessionSurface.PrimaryViewProfileContractId =
			ViewContextSurface.PrimaryViewProfileContractId;
		AppendUniqueStrings(
			SessionSurface.PersistenceSurfaceTags,
			LaunchSurface.PersistenceSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.InteractionSurfaceTags,
			LaunchSurface.InteractionSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			LaunchSurface.ViewSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			ViewContextSurface.ProjectionSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			ViewContextSurface.ContextSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			ViewContextSurface.FocusSurfaceTags);
		SessionSurface.SessionTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("session-surface"),
			TEXT("family:magic120cell"),
			TEXT("host:dedicated-family-map"),
			TEXT("session-defaults:launch-plus-view-context"),
			FString::Printf(TEXT("activation-profile:%s"),
				*LaunchSurface.ActivationProfileId.ToLower()),
			FString::Printf(TEXT("host-surface:%s"),
				*HostSurface.HostSurfaceId.ToLower()),
			FString::Printf(TEXT("launch-surface:%s"),
				*LaunchSurface.LaunchSurfaceId.ToLower()),
			FString::Printf(TEXT("view-context-surface:%s"),
				*ViewContextSurface.ViewContextSurfaceId.ToLower())
		};
		AppendUniqueStrings(SessionSurface.SessionTags, HostSurface.HostTags);
		AppendUniqueStrings(SessionSurface.SessionTags, LaunchSurface.LaunchTags);
		AppendUniqueStrings(SessionSurface.SessionTags, ViewContextSurface.ViewTags);
		AppendUniqueStrings(
			SessionSurface.SessionTags,
			SessionSurface.PersistenceSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.SessionTags,
			SessionSurface.InteractionSurfaceTags);
		AppendUniqueStrings(SessionSurface.SessionTags, SessionSurface.ViewSurfaceTags);
		AppendUniqueSelectors(SessionSurface.Selectors, LaunchSurface.Selectors);
		AppendUniqueSelectors(SessionSurface.Selectors, ViewContextSurface.Selectors);
		AppendUniqueSelectorChoices(
			SessionSurface.DefaultSelectorChoices,
			LaunchSurface.DefaultSelectorChoices);
		AppendUniqueSelectorChoices(
			SessionSurface.DefaultSelectorChoices,
			ViewContextSurface.DefaultSelectorChoices);
		SessionSurface.SourceAttribution = MakeSessionAttribution(
			SessionSurface.SessionSurfaceId,
			TEXT("Phase 6C dedicated-family runtime session surface for Magic120Cell that turns the authored launch and view-context posture into one executed clean-room session contract on the dedicated family training shell.")
		);
		return SessionSurface;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface BuildMagicCube5DSessionSurface()
	{
		FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface LaunchSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeLaunchSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeLaunchCatalog(),
				TEXT("magiccube5d-cleanroom-runtime-activation"),
				LaunchSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface ViewContextSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeViewContextSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeViewContextCatalog(),
				LaunchSurface.ActivationProfileId,
				ViewContextSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeHostSurface HostSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeHostCatalog(),
				LaunchSurface.ActivationProfileId,
				HostSurface))
		{
			return FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface SessionSurface;
		SessionSurface.SessionSurfaceId =
			TEXT("phase6c/magiccube5d/dedicated-training-session-surface");
		SessionSurface.ActivationProfileId = LaunchSurface.ActivationProfileId;
		SessionSurface.HostSurfaceId = HostSurface.HostSurfaceId;
		SessionSurface.LaunchSurfaceId = LaunchSurface.LaunchSurfaceId;
		SessionSurface.ViewContextSurfaceId = ViewContextSurface.ViewContextSurfaceId;
		SessionSurface.Title = TEXT("MagicCube5D dedicated-family runtime session surface");
		SessionSurface.Summary =
			TEXT("Dedicated-family runtime session surface that merges the MagicCube5D dedicated-family launch posture with the authored projection, stereo, visibility, and focus defaults so the executed training session carries the owned higher-dimensional interaction shell on the dedicated training shell.");
		SessionSurface.HostMapPath = HostSurface.EffectiveHostMapPath;
		SessionSurface.HostMapRouteId = HostSurface.EffectiveHostMapRouteId;
		SessionSurface.HostMapLabel = HostSurface.EffectiveHostMapLabel;
		SessionSurface.bUsesSharedTrainingMapFallback = HostSurface.bUsesSharedTrainingMapFallback;
		SessionSurface.RuntimeModeId = LaunchSurface.RuntimeModeId;
		SessionSurface.PrimaryPersistenceBoundaryId = LaunchSurface.PrimaryPersistenceBoundaryId;
		SessionSurface.PrimaryViewProfileContractId =
			ViewContextSurface.PrimaryViewProfileContractId;
		AppendUniqueStrings(
			SessionSurface.PersistenceSurfaceTags,
			LaunchSurface.PersistenceSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.InteractionSurfaceTags,
			LaunchSurface.InteractionSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			LaunchSurface.ViewSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			ViewContextSurface.ProjectionSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			ViewContextSurface.ContextSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.ViewSurfaceTags,
			ViewContextSurface.FocusSurfaceTags);
		SessionSurface.SessionTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("session-surface"),
			TEXT("family:magiccube5d"),
			TEXT("host:dedicated-family-map"),
			TEXT("session-defaults:launch-plus-view-context"),
			FString::Printf(TEXT("activation-profile:%s"),
				*LaunchSurface.ActivationProfileId.ToLower()),
			FString::Printf(TEXT("host-surface:%s"),
				*HostSurface.HostSurfaceId.ToLower()),
			FString::Printf(TEXT("launch-surface:%s"),
				*LaunchSurface.LaunchSurfaceId.ToLower()),
			FString::Printf(TEXT("view-context-surface:%s"),
				*ViewContextSurface.ViewContextSurfaceId.ToLower())
		};
		AppendUniqueStrings(SessionSurface.SessionTags, HostSurface.HostTags);
		AppendUniqueStrings(SessionSurface.SessionTags, LaunchSurface.LaunchTags);
		AppendUniqueStrings(SessionSurface.SessionTags, ViewContextSurface.ViewTags);
		AppendUniqueStrings(
			SessionSurface.SessionTags,
			SessionSurface.PersistenceSurfaceTags);
		AppendUniqueStrings(
			SessionSurface.SessionTags,
			SessionSurface.InteractionSurfaceTags);
		AppendUniqueStrings(SessionSurface.SessionTags, SessionSurface.ViewSurfaceTags);
		AppendUniqueSelectors(SessionSurface.Selectors, LaunchSurface.Selectors);
		AppendUniqueSelectors(SessionSurface.Selectors, ViewContextSurface.Selectors);
		AppendUniqueSelectorChoices(
			SessionSurface.DefaultSelectorChoices,
			LaunchSurface.DefaultSelectorChoices);
		AppendUniqueSelectorChoices(
			SessionSurface.DefaultSelectorChoices,
			ViewContextSurface.DefaultSelectorChoices);
		SessionSurface.SourceAttribution = MakeSessionAttribution(
			SessionSurface.SessionSurfaceId,
			TEXT("Phase 6C dedicated-family runtime session surface for MagicCube5D that turns the authored launch and view-context posture into one executed clean-room session contract on the dedicated family training shell.")
		);
		return SessionSurface;
	}

	FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface
	BuildMagic120CellInteractiveSceneSurface()
	{
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog ActivationCatalog =
			UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeActivationCatalog();
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileById(
				ActivationCatalog,
				TEXT("magic120cell-cleanroom-runtime-activation"),
				Profile))
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface SessionSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeSessionSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeSessionCatalog(),
				Profile.ActivationProfileId,
				SessionSurface))
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		FHyperTwistTrainingMagic120CellRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagic120CellPersistenceBoundary PersistenceBoundary;
		FHyperTwistTrainingMagic120CellViewProfileContract ViewProfile;
		if (!TryGetMagic120CellContracts(
				RuntimeProfile,
				PersistenceBoundary,
				ViewProfile))
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		const FHyperTwistTrainingMagic120CellInteractiveSceneStateEnvelope Envelope =
			BuildMagic120CellInteractiveSceneStateEnvelope(
				Profile,
				SessionSurface,
				PersistenceBoundary,
				ViewProfile);
		if (!Envelope.IsStructurallyValid())
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface SceneSurface;
		SceneSurface.SceneSurfaceId = TEXT("phase6c/magic120cell/interactive-scene-surface");
		SceneSurface.SessionSurfaceId = SessionSurface.SessionSurfaceId;
		SceneSurface.ActivationProfileId = SessionSurface.ActivationProfileId;
		SceneSurface.HostSurfaceId = SessionSurface.HostSurfaceId;
		SceneSurface.LaunchSurfaceId = SessionSurface.LaunchSurfaceId;
		SceneSurface.ViewContextSurfaceId = SessionSurface.ViewContextSurfaceId;
		SceneSurface.Title = TEXT("Magic120Cell interactive scene surface");
		SceneSurface.Summary =
			TEXT("Dedicated-family interactive scene surface that promotes the Magic120Cell runtime session into an explicit simulation scene-context contract with family-owned state, projection, and persistence posture on the dedicated training shell.");
		SceneSurface.HostMapPath = SessionSurface.HostMapPath;
		SceneSurface.HostMapRouteId = SessionSurface.HostMapRouteId;
		SceneSurface.HostMapLabel = SessionSurface.HostMapLabel;
		SceneSurface.bUsesSharedTrainingMapFallback =
			SessionSurface.bUsesSharedTrainingMapFallback;
		SceneSurface.RuntimeModeId = SessionSurface.RuntimeModeId;
		SceneSurface.PrimaryPersistenceBoundaryId =
			SessionSurface.PrimaryPersistenceBoundaryId;
		SceneSurface.PrimaryViewProfileContractId =
			SessionSurface.PrimaryViewProfileContractId;
		SceneSurface.StateSemanticsId =
			TEXT("phase6c/magic120cell/family-owned-scene-state");
		SceneSurface.bUsesPlaceholderStateEnvelope = false;
		SceneSurface.SceneContext = BuildMagic120CellInteractiveSceneContext(
			Profile,
			SessionSurface,
			Envelope
		);
		AppendUniqueStrings(
			SceneSurface.InteractionSurfaceTags,
			SessionSurface.InteractionSurfaceTags);
		AppendUniqueStrings(SceneSurface.ViewSurfaceTags, SessionSurface.ViewSurfaceTags);
		SceneSurface.SceneTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("interactive-scene"),
			TEXT("family:magic120cell"),
			TEXT("scene-state:family-owned-envelope"),
			TEXT("projection:magic120cell-4d-projection-distance-v1"),
			TEXT("focus:center-cell-recentering"),
			TEXT("visibility:logical-visibility-depth-ladder"),
			TEXT("host:dedicated-family-map"),
			TEXT("persistence:magic120cell-persistence-boundary"),
			FString::Printf(TEXT("activation-profile:%s"),
				*SceneSurface.ActivationProfileId.ToLower()),
			FString::Printf(TEXT("session-surface:%s"),
				*SceneSurface.SessionSurfaceId.ToLower())
		};
		AppendUniqueStrings(SceneSurface.SceneTags, SessionSurface.SessionTags);
		AppendUniqueStrings(SceneSurface.SceneTags, SceneSurface.InteractionSurfaceTags);
		AppendUniqueStrings(SceneSurface.SceneTags, SceneSurface.ViewSurfaceTags);
		AppendUniqueStrings(SceneSurface.SceneTags, Envelope.PersistenceSurfaceTags);
		SceneSurface.SourceAttribution = MakeInteractiveSceneAttribution(
			SceneSurface.SceneSurfaceId,
			TEXT("Phase 6C dedicated-family interactive scene surface for Magic120Cell that now carries a family-owned scene-state envelope, dedicated persistence ownership, and the dedicated family training shell instead of the placeholder shared-map bridge.")
		);
		return SceneSurface;
	}

	FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface
	BuildMagicCube5DInteractiveSceneSurface()
	{
		const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog ActivationCatalog =
			UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeActivationCatalog();
		FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileById(
				ActivationCatalog,
				TEXT("magiccube5d-cleanroom-runtime-activation"),
				Profile))
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface SessionSurface;
		if (!UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeSessionSurfaceByActivationProfileId(
				UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeSessionCatalog(),
				Profile.ActivationProfileId,
				SessionSurface))
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		FHyperTwistTrainingMagicCube5DRuntimeProfileContract RuntimeProfile;
		FHyperTwistTrainingMagicCube5DPersistenceBoundary PersistenceBoundary;
		FHyperTwistTrainingMagicCube5DViewProfileContract ViewProfile;
		if (!TryGetMagicCube5DContracts(
				RuntimeProfile,
				PersistenceBoundary,
				ViewProfile))
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		const FHyperTwistTrainingMagicCube5DInteractiveSceneStateEnvelope Envelope =
			BuildMagicCube5DInteractiveSceneStateEnvelope(
				Profile,
				SessionSurface,
				PersistenceBoundary,
				ViewProfile);
		if (!Envelope.IsStructurallyValid())
		{
			return FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		}

		FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface SceneSurface;
		SceneSurface.SceneSurfaceId = TEXT("phase6c/magiccube5d/interactive-scene-surface");
		SceneSurface.SessionSurfaceId = SessionSurface.SessionSurfaceId;
		SceneSurface.ActivationProfileId = SessionSurface.ActivationProfileId;
		SceneSurface.HostSurfaceId = SessionSurface.HostSurfaceId;
		SceneSurface.LaunchSurfaceId = SessionSurface.LaunchSurfaceId;
		SceneSurface.ViewContextSurfaceId = SessionSurface.ViewContextSurfaceId;
		SceneSurface.Title = TEXT("MagicCube5D interactive scene surface");
		SceneSurface.Summary =
			TEXT("Dedicated-family interactive scene surface that promotes the MagicCube5D runtime session into an explicit simulation scene-context contract with family-owned state, projection, persistence, and solved-progress posture on the dedicated training shell.");
		SceneSurface.HostMapPath = SessionSurface.HostMapPath;
		SceneSurface.HostMapRouteId = SessionSurface.HostMapRouteId;
		SceneSurface.HostMapLabel = SessionSurface.HostMapLabel;
		SceneSurface.bUsesSharedTrainingMapFallback =
			SessionSurface.bUsesSharedTrainingMapFallback;
		SceneSurface.RuntimeModeId = SessionSurface.RuntimeModeId;
		SceneSurface.PrimaryPersistenceBoundaryId =
			SessionSurface.PrimaryPersistenceBoundaryId;
		SceneSurface.PrimaryViewProfileContractId =
			SessionSurface.PrimaryViewProfileContractId;
		SceneSurface.StateSemanticsId =
			TEXT("phase6c/magiccube5d/family-owned-scene-state");
		SceneSurface.bUsesPlaceholderStateEnvelope = false;
		SceneSurface.SceneContext = BuildMagicCube5DInteractiveSceneContext(
			Profile,
			SessionSurface,
			Envelope
		);
		AppendUniqueStrings(
			SceneSurface.InteractionSurfaceTags,
			SessionSurface.InteractionSurfaceTags);
		AppendUniqueStrings(SceneSurface.ViewSurfaceTags, SessionSurface.ViewSurfaceTags);
		SceneSurface.SceneTags =
		{
			TEXT("phase6c"),
			TEXT("higher-dimensional"),
			TEXT("interactive-scene"),
			TEXT("family:magiccube5d"),
			TEXT("scene-state:family-owned-envelope"),
			TEXT("projection:magiccube5d-5d-projection-distance-v1"),
			TEXT("context:stereo-disabled-default"),
			TEXT("visibility:all-faces-visible-default"),
			TEXT("focus:view-centered-solved-progress"),
			TEXT("host:dedicated-family-map"),
			TEXT("persistence:magiccube5d-persistence-boundary"),
			FString::Printf(TEXT("activation-profile:%s"),
				*SceneSurface.ActivationProfileId.ToLower()),
			FString::Printf(TEXT("session-surface:%s"),
				*SceneSurface.SessionSurfaceId.ToLower())
		};
		AppendUniqueStrings(SceneSurface.SceneTags, SessionSurface.SessionTags);
		AppendUniqueStrings(SceneSurface.SceneTags, SceneSurface.InteractionSurfaceTags);
		AppendUniqueStrings(SceneSurface.SceneTags, SceneSurface.ViewSurfaceTags);
		AppendUniqueStrings(SceneSurface.SceneTags, Envelope.SolvedProgressSurfaceTags);
		SceneSurface.SourceAttribution = MakeInteractiveSceneAttribution(
			SceneSurface.SceneSurfaceId,
			TEXT("Phase 6C dedicated-family interactive scene surface for MagicCube5D that now carries a family-owned scene-state envelope, dedicated persistence ownership, and the dedicated family training shell instead of the placeholder shared-map bridge.")
		);
		return SceneSurface;
	}
}

bool FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog::IsStructurallyValid() const
{
	if (CatalogId.IsEmpty() || CatalogVersion.IsEmpty() || Profiles.Num() == 0)
	{
		return false;
	}

	TSet<FString> SeenProfileIds;
	TSet<FString> SeenPuzzleIds;
	TSet<FString> SeenRuntimeModeIds;
	for (const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile : Profiles)
	{
		if (!Profile.IsStructurallyValid())
		{
			return false;
		}

		const FString NormalizedProfileId = Profile.ActivationProfileId.ToLower();
		if (SeenProfileIds.Contains(NormalizedProfileId))
		{
			return false;
		}

		const FString NormalizedPuzzleId = Profile.PuzzleId.ToLower();
		if (SeenPuzzleIds.Contains(NormalizedPuzzleId))
		{
			return false;
		}

		const FString NormalizedRuntimeModeId = Profile.RuntimeModeId.ToLower();
		if (SeenRuntimeModeIds.Contains(NormalizedRuntimeModeId))
		{
			return false;
		}

		SeenProfileIds.Add(NormalizedProfileId);
		SeenPuzzleIds.Add(NormalizedPuzzleId);
		SeenRuntimeModeIds.Add(NormalizedRuntimeModeId);
	}

	return true;
}

bool FHyperTwistTrainingHigherDimensionalRuntimeHostCatalog::IsStructurallyValid() const
{
	if (CatalogId.IsEmpty() || CatalogVersion.IsEmpty() || HostSurfaces.Num() == 0)
	{
		return false;
	}

	TSet<FString> SeenHostSurfaceIds;
	TSet<FString> SeenActivationProfileIds;
	for (const FHyperTwistTrainingHigherDimensionalRuntimeHostSurface& HostSurface : HostSurfaces)
	{
		if (!HostSurface.IsStructurallyValid())
		{
			return false;
		}

		const FString NormalizedHostSurfaceId = HostSurface.HostSurfaceId.ToLower();
		if (SeenHostSurfaceIds.Contains(NormalizedHostSurfaceId))
		{
			return false;
		}

		const FString NormalizedActivationProfileId = HostSurface.ActivationProfileId.ToLower();
		if (SeenActivationProfileIds.Contains(NormalizedActivationProfileId))
		{
			return false;
		}

		SeenHostSurfaceIds.Add(NormalizedHostSurfaceId);
		SeenActivationProfileIds.Add(NormalizedActivationProfileId);
	}

	return true;
}

bool FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface::IsStructurallyValid() const
{
	if (LaunchSurfaceId.IsEmpty()
		|| ActivationProfileId.IsEmpty()
		|| HostSurfaceId.IsEmpty()
		|| Title.IsEmpty()
		|| HostMapPath.IsEmpty()
		|| HostMapRouteId.IsEmpty()
		|| DeckId.IsEmpty()
		|| SeedCaseId.IsEmpty()
		|| SeedPromptLabel.IsEmpty()
		|| SurfaceKind.IsEmpty()
		|| SurfaceId.IsEmpty()
		|| SurfaceLabel.IsEmpty()
		|| RuntimeModeId.IsEmpty()
		|| GeneratorType.IsEmpty()
		|| PrimaryPersistenceBoundaryId.IsEmpty()
		|| !SourceAttribution.IsStructurallyValid())
	{
		return false;
	}

	return HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::
		AreImportedRuntimeSelectorsConsistent(Selectors, DefaultSelectorChoices);
}

bool FHyperTwistTrainingHigherDimensionalRuntimeLaunchCatalog::IsStructurallyValid() const
{
	if (CatalogId.IsEmpty() || CatalogVersion.IsEmpty() || LaunchSurfaces.Num() == 0)
	{
		return false;
	}

	TSet<FString> SeenLaunchSurfaceIds;
	TSet<FString> SeenActivationProfileIds;
	TSet<FString> SeenSurfaceIds;
	for (const FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface& LaunchSurface :
		LaunchSurfaces)
	{
		if (!LaunchSurface.IsStructurallyValid())
		{
			return false;
		}

		const FString NormalizedLaunchSurfaceId = LaunchSurface.LaunchSurfaceId.ToLower();
		if (SeenLaunchSurfaceIds.Contains(NormalizedLaunchSurfaceId))
		{
			return false;
		}

		const FString NormalizedActivationProfileId = LaunchSurface.ActivationProfileId.ToLower();
		if (SeenActivationProfileIds.Contains(NormalizedActivationProfileId))
		{
			return false;
		}

		const FString NormalizedSurfaceId = LaunchSurface.SurfaceId.ToLower();
		if (SeenSurfaceIds.Contains(NormalizedSurfaceId))
		{
			return false;
		}

		SeenLaunchSurfaceIds.Add(NormalizedLaunchSurfaceId);
		SeenActivationProfileIds.Add(NormalizedActivationProfileId);
		SeenSurfaceIds.Add(NormalizedSurfaceId);
	}

	return true;
}

bool FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface::IsStructurallyValid() const
{
	if (ViewContextSurfaceId.IsEmpty()
		|| ActivationProfileId.IsEmpty()
		|| LaunchSurfaceId.IsEmpty()
		|| HostSurfaceId.IsEmpty()
		|| Title.IsEmpty()
		|| HostMapPath.IsEmpty()
		|| HostMapRouteId.IsEmpty()
		|| HostMapLabel.IsEmpty()
		|| PrimaryViewProfileContractId.IsEmpty()
		|| !SourceAttribution.IsStructurallyValid())
	{
		return false;
	}

	return HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::
		AreImportedRuntimeSelectorsConsistent(Selectors, DefaultSelectorChoices);
}

bool FHyperTwistTrainingHigherDimensionalRuntimeViewContextCatalog::IsStructurallyValid() const
{
	if (CatalogId.IsEmpty() || CatalogVersion.IsEmpty() || ViewContextSurfaces.Num() == 0)
	{
		return false;
	}

	TSet<FString> SeenViewContextSurfaceIds;
	TSet<FString> SeenActivationProfileIds;
	TSet<FString> SeenLaunchSurfaceIds;
	for (const FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface& ViewContextSurface :
		ViewContextSurfaces)
	{
		if (!ViewContextSurface.IsStructurallyValid())
		{
			return false;
		}

		const FString NormalizedViewContextSurfaceId =
			ViewContextSurface.ViewContextSurfaceId.ToLower();
		if (SeenViewContextSurfaceIds.Contains(NormalizedViewContextSurfaceId))
		{
			return false;
		}

		const FString NormalizedActivationProfileId =
			ViewContextSurface.ActivationProfileId.ToLower();
		if (SeenActivationProfileIds.Contains(NormalizedActivationProfileId))
		{
			return false;
		}

		const FString NormalizedLaunchSurfaceId = ViewContextSurface.LaunchSurfaceId.ToLower();
		if (SeenLaunchSurfaceIds.Contains(NormalizedLaunchSurfaceId))
		{
			return false;
		}

		SeenViewContextSurfaceIds.Add(NormalizedViewContextSurfaceId);
		SeenActivationProfileIds.Add(NormalizedActivationProfileId);
		SeenLaunchSurfaceIds.Add(NormalizedLaunchSurfaceId);
	}

	return true;
}

bool FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface::IsStructurallyValid() const
{
	if (SessionSurfaceId.IsEmpty()
		|| ActivationProfileId.IsEmpty()
		|| HostSurfaceId.IsEmpty()
		|| LaunchSurfaceId.IsEmpty()
		|| ViewContextSurfaceId.IsEmpty()
		|| Title.IsEmpty()
		|| HostMapPath.IsEmpty()
		|| HostMapRouteId.IsEmpty()
		|| HostMapLabel.IsEmpty()
		|| RuntimeModeId.IsEmpty()
		|| PrimaryPersistenceBoundaryId.IsEmpty()
		|| PrimaryViewProfileContractId.IsEmpty()
		|| !SourceAttribution.IsStructurallyValid())
	{
		return false;
	}

	return HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::
		AreImportedRuntimeSelectorsConsistent(Selectors, DefaultSelectorChoices);
}

bool FHyperTwistTrainingHigherDimensionalRuntimeSessionCatalog::IsStructurallyValid() const
{
	if (CatalogId.IsEmpty() || CatalogVersion.IsEmpty() || SessionSurfaces.Num() == 0)
	{
		return false;
	}

	TSet<FString> SeenSessionSurfaceIds;
	TSet<FString> SeenActivationProfileIds;
	TSet<FString> SeenLaunchSurfaceIds;
	TSet<FString> SeenViewContextSurfaceIds;
	for (const FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& SessionSurface :
		SessionSurfaces)
	{
		if (!SessionSurface.IsStructurallyValid())
		{
			return false;
		}

		const FString NormalizedSessionSurfaceId = SessionSurface.SessionSurfaceId.ToLower();
		if (SeenSessionSurfaceIds.Contains(NormalizedSessionSurfaceId))
		{
			return false;
		}

		const FString NormalizedActivationProfileId =
			SessionSurface.ActivationProfileId.ToLower();
		if (SeenActivationProfileIds.Contains(NormalizedActivationProfileId))
		{
			return false;
		}

		const FString NormalizedLaunchSurfaceId = SessionSurface.LaunchSurfaceId.ToLower();
		if (SeenLaunchSurfaceIds.Contains(NormalizedLaunchSurfaceId))
		{
			return false;
		}

		const FString NormalizedViewContextSurfaceId =
			SessionSurface.ViewContextSurfaceId.ToLower();
		if (SeenViewContextSurfaceIds.Contains(NormalizedViewContextSurfaceId))
		{
			return false;
		}

		SeenSessionSurfaceIds.Add(NormalizedSessionSurfaceId);
		SeenActivationProfileIds.Add(NormalizedActivationProfileId);
		SeenLaunchSurfaceIds.Add(NormalizedLaunchSurfaceId);
		SeenViewContextSurfaceIds.Add(NormalizedViewContextSurfaceId);
	}

	return true;
}

bool FHyperTwistTrainingHigherDimensionalInteractiveSceneCatalog::IsStructurallyValid() const
{
	if (CatalogId.IsEmpty() || CatalogVersion.IsEmpty() || SceneSurfaces.Num() == 0)
	{
		return false;
	}

	TSet<FString> SeenSceneSurfaceIds;
	TSet<FString> SeenSessionSurfaceIds;
	TSet<FString> SeenActivationProfileIds;
	TSet<FString> SeenSceneContextIds;
	for (const FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface& SceneSurface :
		SceneSurfaces)
	{
		if (!SceneSurface.IsStructurallyValid())
		{
			return false;
		}

		const FString NormalizedSceneSurfaceId = SceneSurface.SceneSurfaceId.ToLower();
		if (SeenSceneSurfaceIds.Contains(NormalizedSceneSurfaceId))
		{
			return false;
		}

		const FString NormalizedSessionSurfaceId = SceneSurface.SessionSurfaceId.ToLower();
		if (SeenSessionSurfaceIds.Contains(NormalizedSessionSurfaceId))
		{
			return false;
		}

		const FString NormalizedActivationProfileId =
			SceneSurface.ActivationProfileId.ToLower();
		if (SeenActivationProfileIds.Contains(NormalizedActivationProfileId))
		{
			return false;
		}

		const FString NormalizedSceneContextId =
			SceneSurface.SceneContext.SceneContextId.ToLower();
		if (SeenSceneContextIds.Contains(NormalizedSceneContextId))
		{
			return false;
		}

		SeenSceneSurfaceIds.Add(NormalizedSceneSurfaceId);
		SeenSessionSurfaceIds.Add(NormalizedSessionSurfaceId);
		SeenActivationProfileIds.Add(NormalizedActivationProfileId);
		SeenSceneContextIds.Add(NormalizedSceneContextId);
	}

	return true;
}

FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog
UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeActivationCatalog()
{
	FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog Catalog;
	Catalog.Profiles =
	{
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagic120CellActivationProfile(),
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagicCube5DActivationProfile()
	};
	return Catalog;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileById(
	const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog& Catalog,
	const FString& ActivationProfileId,
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& OutProfile
)
{
	if (ActivationProfileId.IsEmpty())
	{
		OutProfile = FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile : Catalog.Profiles)
	{
		if (Profile.MatchesActivationProfileId(ActivationProfileId))
		{
			OutProfile = Profile;
			return true;
		}
	}

	OutProfile = FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileByPuzzleId(
	const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog& Catalog,
	const FString& PuzzleId,
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& OutProfile
)
{
	if (PuzzleId.IsEmpty())
	{
		OutProfile = FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile : Catalog.Profiles)
	{
		if (Profile.MatchesPuzzleId(PuzzleId))
		{
			OutProfile = Profile;
			return true;
		}
	}

	OutProfile = FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeActivationProfileByRuntimeModeId(
	const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog& Catalog,
	const FString& RuntimeModeId,
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& OutProfile
)
{
	if (RuntimeModeId.IsEmpty())
	{
		OutProfile = FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile& Profile : Catalog.Profiles)
	{
		if (Profile.MatchesRuntimeModeId(RuntimeModeId))
		{
			OutProfile = Profile;
			return true;
		}
	}

	OutProfile = FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryResolvePuzzleDefinition(
	const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog& Catalog,
	const FString& ActivationProfileIdOrPuzzleId,
	FHyperTwistPuzzleDefinitionRef& OutDefinition
)
{
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
	const bool bResolved =
		TryGetRuntimeActivationProfileById(Catalog, ActivationProfileIdOrPuzzleId, Profile)
		|| TryGetRuntimeActivationProfileByPuzzleId(Catalog, ActivationProfileIdOrPuzzleId, Profile)
		|| TryGetRuntimeActivationProfileByRuntimeModeId(
			Catalog,
			ActivationProfileIdOrPuzzleId,
			Profile
		);
	if (!bResolved)
	{
		OutDefinition = FHyperTwistPuzzleDefinitionRef();
		return false;
	}

	OutDefinition = Profile.ToDefinitionRef();
	return OutDefinition.IsStructurallyValid();
}

FHyperTwistTrainingHigherDimensionalRuntimeHostCatalog
UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeHostCatalog()
{
	FHyperTwistTrainingHigherDimensionalRuntimeHostCatalog Catalog;
	Catalog.HostSurfaces =
	{
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagic120CellHostSurface(),
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagicCube5DHostSurface()
	};
	return Catalog;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByActivationProfileId(
	const FHyperTwistTrainingHigherDimensionalRuntimeHostCatalog& Catalog,
	const FString& ActivationProfileId,
	FHyperTwistTrainingHigherDimensionalRuntimeHostSurface& OutHostSurface
)
{
	if (ActivationProfileId.IsEmpty())
	{
		OutHostSurface = FHyperTwistTrainingHigherDimensionalRuntimeHostSurface();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalRuntimeHostSurface& HostSurface :
		Catalog.HostSurfaces)
	{
		if (HostSurface.ActivationProfileId.Equals(ActivationProfileId, ESearchCase::IgnoreCase))
		{
			OutHostSurface = HostSurface;
			return true;
		}
	}

	OutHostSurface = FHyperTwistTrainingHigherDimensionalRuntimeHostSurface();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeHostSurfaceByPuzzleId(
	const FHyperTwistTrainingHigherDimensionalRuntimeHostCatalog& Catalog,
	const FString& PuzzleId,
	FHyperTwistTrainingHigherDimensionalRuntimeHostSurface& OutHostSurface
)
{
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
	if (PuzzleId.IsEmpty()
		|| !TryGetRuntimeActivationProfileByPuzzleId(
			BuildBundledHigherDimensionalRuntimeActivationCatalog(),
			PuzzleId,
			Profile))
	{
		OutHostSurface = FHyperTwistTrainingHigherDimensionalRuntimeHostSurface();
		return false;
	}

	return TryGetRuntimeHostSurfaceByActivationProfileId(
		Catalog,
		Profile.ActivationProfileId,
		OutHostSurface
	);
}

FHyperTwistTrainingHigherDimensionalRuntimeLaunchCatalog
UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeLaunchCatalog()
{
	FHyperTwistTrainingHigherDimensionalRuntimeLaunchCatalog Catalog;
	Catalog.LaunchSurfaces =
	{
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagic120CellLaunchSurface(),
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagicCube5DLaunchSurface()
	};
	return Catalog;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeLaunchSurfaceByActivationProfileId(
	const FHyperTwistTrainingHigherDimensionalRuntimeLaunchCatalog& Catalog,
	const FString& ActivationProfileId,
	FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface& OutLaunchSurface
)
{
	if (ActivationProfileId.IsEmpty())
	{
		OutLaunchSurface = FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface& LaunchSurface :
		Catalog.LaunchSurfaces)
	{
		if (LaunchSurface.ActivationProfileId.Equals(ActivationProfileId, ESearchCase::IgnoreCase))
		{
			OutLaunchSurface = LaunchSurface;
			return true;
		}
	}

	OutLaunchSurface = FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeLaunchSurfaceByPuzzleId(
	const FHyperTwistTrainingHigherDimensionalRuntimeLaunchCatalog& Catalog,
	const FString& PuzzleId,
	FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface& OutLaunchSurface
)
{
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
	if (PuzzleId.IsEmpty()
		|| !TryGetRuntimeActivationProfileByPuzzleId(
			BuildBundledHigherDimensionalRuntimeActivationCatalog(),
			PuzzleId,
			Profile))
	{
		OutLaunchSurface = FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface();
		return false;
	}

	return TryGetRuntimeLaunchSurfaceByActivationProfileId(
		Catalog,
		Profile.ActivationProfileId,
		OutLaunchSurface
	);
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryBuildTrainingDeckFromRuntimeLaunchSurface(
	const FHyperTwistTrainingHigherDimensionalRuntimeLaunchSurface& LaunchSurface,
	FHyperTwistTrainingDeck& OutDeck
)
{
	OutDeck = FHyperTwistTrainingDeck();
	if (!LaunchSurface.IsStructurallyValid())
	{
		return false;
	}

	const FHyperTwistTrainingHigherDimensionalRuntimeActivationCatalog ActivationCatalog =
		BuildBundledHigherDimensionalRuntimeActivationCatalog();
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
	if (!TryGetRuntimeActivationProfileById(
			ActivationCatalog,
			LaunchSurface.ActivationProfileId,
			Profile))
	{
		return false;
	}

	FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface SessionSurface;
	if (!TryGetRuntimeSessionSurfaceByActivationProfileId(
			BuildBundledHigherDimensionalRuntimeSessionCatalog(),
			LaunchSurface.ActivationProfileId,
			SessionSurface))
	{
		return false;
	}

	FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface InteractiveSceneSurface;
	if (!TryGetInteractiveSceneSurfaceByActivationProfileId(
			BuildBundledHigherDimensionalInteractiveSceneCatalog(),
			LaunchSurface.ActivationProfileId,
			InteractiveSceneSurface))
	{
		return false;
	}

	FHyperTwistTrainingImportedRuntimeSurface RuntimeSurface;
	RuntimeSurface.SurfaceKind = LaunchSurface.SurfaceKind;
	RuntimeSurface.SurfaceId = LaunchSurface.SurfaceId;
	RuntimeSurface.SurfaceLabel = LaunchSurface.SurfaceLabel;
	RuntimeSurface.RuntimeModeId = LaunchSurface.RuntimeModeId;
	RuntimeSurface.GeneratorType = LaunchSurface.GeneratorType;
	RuntimeSurface.Selectors = SessionSurface.Selectors;
	RuntimeSurface.OriginPaths =
	{
		InteractiveSceneSurface.SceneSurfaceId,
		InteractiveSceneSurface.SceneContext.SceneContextId,
		SessionSurface.SessionSurfaceId,
		SessionSurface.ViewContextSurfaceId,
		LaunchSurface.LaunchSurfaceId,
		LaunchSurface.HostSurfaceId,
		LaunchSurface.HostMapPath,
		LaunchSurface.HostMapRouteId
	};
	RuntimeSurface.Notes = SessionSurface.Summary;

	FHyperTwistTrainingCase SeedCase;
	SeedCase.CaseId = LaunchSurface.SeedCaseId;
	SeedCase.PuzzleId = Profile.PuzzleId;
	SeedCase.PromptKind = EHyperTwistTrainingPromptKind::State;
	SeedCase.PromptLabel = LaunchSurface.SeedPromptLabel;
	SeedCase.Tags =
	{
		TEXT("phase6c"),
		TEXT("higher-dimensional"),
		TEXT("runtime-surface:generated-mode"),
		TEXT("generated-mode:launch-seed"),
		FString::Printf(TEXT("activation-profile:%s"), *Profile.ActivationProfileId.ToLower()),
		FString::Printf(TEXT("launch-surface:%s"), *LaunchSurface.LaunchSurfaceId.ToLower()),
		FString::Printf(TEXT("host-surface:%s"), *LaunchSurface.HostSurfaceId.ToLower()),
		FString::Printf(TEXT("host-map-route:%s"), *LaunchSurface.HostMapRouteId.ToLower())
	};
	HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::AppendUniqueStrings(
		SeedCase.Tags,
		LaunchSurface.LaunchTags
	);
	HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::AppendUniqueStrings(
		SeedCase.Tags,
		SessionSurface.SessionTags
	);
	HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::AppendUniqueStrings(
		SeedCase.Tags,
		InteractiveSceneSurface.SceneTags
	);
	SeedCase.AllowedDeliveryModes = {EHyperTwistTrainingDeliveryMode::VirtualCube};
	SeedCase.SourceAttribution = InteractiveSceneSurface.SourceAttribution;
	SeedCase.SourceAttribution.SourceDeckId = LaunchSurface.DeckId;
	SeedCase.SourceAttribution.SourceCaseId = SeedCase.CaseId;

	OutDeck.DeckId = LaunchSurface.DeckId;
	OutDeck.Title = SessionSurface.Title;
	OutDeck.DeliveryModes = {EHyperTwistTrainingDeliveryMode::VirtualCube};
	OutDeck.SelectionPolicy = EHyperTwistTrainingSelectionPolicy::Scripted;
	OutDeck.bSupportsAlgorithmReveal = false;
	OutDeck.bSupportsVirtualCube = true;
	OutDeck.Cases = {SeedCase};
	OutDeck.Tags =
	{
		TEXT("phase6c"),
		TEXT("higher-dimensional"),
		TEXT("runtime-surface:generated-mode"),
		TEXT("generated-mode:dedicated-family-launch"),
		FString::Printf(TEXT("activation-profile:%s"), *Profile.ActivationProfileId.ToLower()),
		FString::Printf(TEXT("launch-surface:%s"), *LaunchSurface.LaunchSurfaceId.ToLower()),
		FString::Printf(TEXT("host-surface:%s"), *LaunchSurface.HostSurfaceId.ToLower()),
		FString::Printf(TEXT("host-map-route:%s"), *LaunchSurface.HostMapRouteId.ToLower())
	};
	HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::AppendUniqueStrings(
		OutDeck.Tags,
		LaunchSurface.LaunchTags
	);
	HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::AppendUniqueStrings(
		OutDeck.Tags,
		SessionSurface.SessionTags
	);
	HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::AppendUniqueStrings(
		OutDeck.Tags,
		InteractiveSceneSurface.SceneTags
	);
	OutDeck.SourceAttribution = InteractiveSceneSurface.SourceAttribution;
	OutDeck.SourceAttribution.SourceDeckId = LaunchSurface.DeckId;
	OutDeck.ImportedRuntimeSurface = RuntimeSurface;
	return OutDeck.IsStructurallyValid()
		&& OutDeck.ImportedRuntimeSurface.IsStructurallyValid()
		&& SeedCase.IsStructurallyValid();
}

FHyperTwistTrainingHigherDimensionalRuntimeViewContextCatalog
UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeViewContextCatalog()
{
	FHyperTwistTrainingHigherDimensionalRuntimeViewContextCatalog Catalog;
	Catalog.ViewContextSurfaces =
	{
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagic120CellViewContextSurface(),
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagicCube5DViewContextSurface()
	};
	return Catalog;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeViewContextSurfaceByActivationProfileId(
	const FHyperTwistTrainingHigherDimensionalRuntimeViewContextCatalog& Catalog,
	const FString& ActivationProfileId,
	FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface& OutViewContextSurface
)
{
	if (ActivationProfileId.IsEmpty())
	{
		OutViewContextSurface = FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface& ViewContextSurface :
		Catalog.ViewContextSurfaces)
	{
		if (ViewContextSurface.ActivationProfileId.Equals(
				ActivationProfileId,
				ESearchCase::IgnoreCase))
		{
			OutViewContextSurface = ViewContextSurface;
			return true;
		}
	}

	OutViewContextSurface = FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeViewContextSurfaceByPuzzleId(
	const FHyperTwistTrainingHigherDimensionalRuntimeViewContextCatalog& Catalog,
	const FString& PuzzleId,
	FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface& OutViewContextSurface
)
{
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
	if (PuzzleId.IsEmpty()
		|| !TryGetRuntimeActivationProfileByPuzzleId(
			BuildBundledHigherDimensionalRuntimeActivationCatalog(),
			PuzzleId,
			Profile))
	{
		OutViewContextSurface = FHyperTwistTrainingHigherDimensionalRuntimeViewContextSurface();
		return false;
	}

	return TryGetRuntimeViewContextSurfaceByActivationProfileId(
		Catalog,
		Profile.ActivationProfileId,
		OutViewContextSurface
	);
}

FHyperTwistTrainingHigherDimensionalRuntimeSessionCatalog
UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalRuntimeSessionCatalog()
{
	FHyperTwistTrainingHigherDimensionalRuntimeSessionCatalog Catalog;
	Catalog.SessionSurfaces =
	{
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagic120CellSessionSurface(),
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagicCube5DSessionSurface()
	};
	return Catalog;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeSessionSurfaceByActivationProfileId(
	const FHyperTwistTrainingHigherDimensionalRuntimeSessionCatalog& Catalog,
	const FString& ActivationProfileId,
	FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& OutSessionSurface
)
{
	if (ActivationProfileId.IsEmpty())
	{
		OutSessionSurface = FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& SessionSurface :
		Catalog.SessionSurfaces)
	{
		if (SessionSurface.ActivationProfileId.Equals(ActivationProfileId, ESearchCase::IgnoreCase))
		{
			OutSessionSurface = SessionSurface;
			return true;
		}
	}

	OutSessionSurface = FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetRuntimeSessionSurfaceByPuzzleId(
	const FHyperTwistTrainingHigherDimensionalRuntimeSessionCatalog& Catalog,
	const FString& PuzzleId,
	FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface& OutSessionSurface
)
{
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
	if (PuzzleId.IsEmpty()
		|| !TryGetRuntimeActivationProfileByPuzzleId(
			BuildBundledHigherDimensionalRuntimeActivationCatalog(),
			PuzzleId,
			Profile))
	{
		OutSessionSurface = FHyperTwistTrainingHigherDimensionalRuntimeSessionSurface();
		return false;
	}

	return TryGetRuntimeSessionSurfaceByActivationProfileId(
		Catalog,
		Profile.ActivationProfileId,
		OutSessionSurface
	);
}

FHyperTwistTrainingHigherDimensionalInteractiveSceneCatalog
UHyperTwistTrainingHigherDimensionalRuntimeLibrary::BuildBundledHigherDimensionalInteractiveSceneCatalog()
{
	FHyperTwistTrainingHigherDimensionalInteractiveSceneCatalog Catalog;
	Catalog.SceneSurfaces =
	{
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagic120CellInteractiveSceneSurface(),
		HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::BuildMagicCube5DInteractiveSceneSurface()
	};
	return Catalog;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetInteractiveSceneSurfaceBySessionSurfaceId(
	const FHyperTwistTrainingHigherDimensionalInteractiveSceneCatalog& Catalog,
	const FString& SessionSurfaceId,
	FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface& OutSceneSurface
)
{
	if (SessionSurfaceId.IsEmpty())
	{
		OutSceneSurface = FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface& SceneSurface :
		Catalog.SceneSurfaces)
	{
		if (SceneSurface.SessionSurfaceId.Equals(SessionSurfaceId, ESearchCase::IgnoreCase))
		{
			OutSceneSurface = SceneSurface;
			return true;
		}
	}

	OutSceneSurface = FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetInteractiveSceneSurfaceByActivationProfileId(
	const FHyperTwistTrainingHigherDimensionalInteractiveSceneCatalog& Catalog,
	const FString& ActivationProfileId,
	FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface& OutSceneSurface
)
{
	if (ActivationProfileId.IsEmpty())
	{
		OutSceneSurface = FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		return false;
	}

	for (const FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface& SceneSurface :
		Catalog.SceneSurfaces)
	{
		if (SceneSurface.ActivationProfileId.Equals(ActivationProfileId, ESearchCase::IgnoreCase))
		{
			OutSceneSurface = SceneSurface;
			return true;
		}
	}

	OutSceneSurface = FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
	return false;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryGetInteractiveSceneSurfaceByPuzzleId(
	const FHyperTwistTrainingHigherDimensionalInteractiveSceneCatalog& Catalog,
	const FString& PuzzleId,
	FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface& OutSceneSurface
)
{
	FHyperTwistTrainingHigherDimensionalRuntimeActivationProfile Profile;
	if (PuzzleId.IsEmpty()
		|| !TryGetRuntimeActivationProfileByPuzzleId(
			BuildBundledHigherDimensionalRuntimeActivationCatalog(),
			PuzzleId,
			Profile))
	{
		OutSceneSurface = FHyperTwistTrainingHigherDimensionalInteractiveSceneSurface();
		return false;
	}

	return TryGetInteractiveSceneSurfaceByActivationProfileId(
		Catalog,
		Profile.ActivationProfileId,
		OutSceneSurface
	);
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryDecodeMagic120CellInteractiveSceneStateEnvelope(
	const FHyperTwistSimulationSceneContext& SceneContext,
	FHyperTwistTrainingMagic120CellInteractiveSceneStateEnvelope& OutEnvelope
)
{
	OutEnvelope = FHyperTwistTrainingMagic120CellInteractiveSceneStateEnvelope();
	if (!SceneContext.IsStructurallyValid()
		|| SceneContext.PuzzleState.Definition.PuzzleId != TEXT("polychoron/magic120cell")
		|| SceneContext.PuzzleState.StateEncoding.EncodingProfile
			!= TEXT("magic120cell-family-owned-scene-state-v1")
		|| !HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::DeserializeJsonString(
			SceneContext.PuzzleState.StateEncoding.PayloadJson,
			OutEnvelope)
		|| !OutEnvelope.IsStructurallyValid())
	{
		OutEnvelope = FHyperTwistTrainingMagic120CellInteractiveSceneStateEnvelope();
		return false;
	}

	return true;
}

bool UHyperTwistTrainingHigherDimensionalRuntimeLibrary::TryDecodeMagicCube5DInteractiveSceneStateEnvelope(
	const FHyperTwistSimulationSceneContext& SceneContext,
	FHyperTwistTrainingMagicCube5DInteractiveSceneStateEnvelope& OutEnvelope
)
{
	OutEnvelope = FHyperTwistTrainingMagicCube5DInteractiveSceneStateEnvelope();
	if (!SceneContext.IsStructurallyValid()
		|| SceneContext.PuzzleState.Definition.PuzzleId != TEXT("hypercube/magiccube5d/order3")
		|| SceneContext.PuzzleState.StateEncoding.EncodingProfile
			!= TEXT("magiccube5d-family-owned-scene-state-v1")
		|| !HyperTwistTrainingHigherDimensionalRuntimeLibraryInternal::DeserializeJsonString(
			SceneContext.PuzzleState.StateEncoding.PayloadJson,
			OutEnvelope)
		|| !OutEnvelope.IsStructurallyValid())
	{
		OutEnvelope = FHyperTwistTrainingMagicCube5DInteractiveSceneStateEnvelope();
		return false;
	}

	return true;
}
