#include "HyperTwistTraining/HyperTwistTrainingSpatialLibrary.h"

namespace HyperTwistTrainingSpatialLibraryInternal
{
	FHyperTwistTrainingSourceAttribution MakeAttribution(
		const FString& SourceRepo,
		const FString& TrackId,
		const FString& Notes,
		const FString& SourceLicense = TEXT("MIT")
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::DirectDonor;
		Attribution.SourceRepo = SourceRepo;
		Attribution.SourceLicense = SourceLicense;
		Attribution.SourceTrackId = TrackId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}

	FHyperTwistTrainingSpatialPackageReference MakePackageReference(
		const FString& PackageId,
		const FString& Label,
		const FString& OwnershipRole,
		const FString& Summary,
		const TArray<FString>& RetainedSurfaceTags,
		const TArray<FString>& ExplicitExclusions,
		const FHyperTwistTrainingSourceAttribution& SourceAttribution
	)
	{
		FHyperTwistTrainingSpatialPackageReference Reference;
		Reference.PackageId = PackageId;
		Reference.Label = Label;
		Reference.OwnershipRole = OwnershipRole;
		Reference.Summary = Summary;
		Reference.RetainedSurfaceTags = RetainedSurfaceTags;
		Reference.ExplicitExclusions = ExplicitExclusions;
		Reference.SourceAttribution = SourceAttribution;
		return Reference;
	}

	void AppendJoined(FString& OutText, const TArray<FString>& Values)
	{
		for (int32 Index = 0; Index < Values.Num(); ++Index)
		{
			if (Index > 0)
			{
				OutText.Append(TEXT(", "));
			}

			OutText.Append(Values[Index]);
		}
	}
}

FHyperTwistTrainingSpatialReferenceBundle
UHyperTwistTrainingSpatialLibrary::BuildBundledBrowserSpatialReferenceBundle()
{
	using namespace HyperTwistTrainingSpatialLibraryInternal;

	FHyperTwistTrainingSpatialReferenceBundle Bundle;
	Bundle.ReferenceUtc = TEXT("2026-05-13T00:00:00Z");
	Bundle.PrimarySceneContractId = TEXT("browser-spatial-scene-stack");
	Bundle.PrimaryXrSessionContractId = TEXT("browser-spatial-xr-session-stack");
	Bundle.PrimarySpatialUiContractId = TEXT("browser-spatial-ui-stack");
	Bundle.PrimaryEffectBoundaryId = TEXT("browser-spatial-effect-boundary");
	Bundle.PrimaryStateMotionContractId = TEXT("browser-spatial-state-motion-stack");

	Bundle.PackageReferences =
	{
		MakePackageReference(
			TEXT("package/three-js"),
			TEXT("three.js"),
			TEXT("scene-substrate-anchor"),
			TEXT("Commodity browser scene, renderer, camera, and WebXR substrate for the retained browser spatial lane."),
			{
				TEXT("scene graph"),
				TEXT("camera and renderer lifecycle"),
				TEXT("WebXR manager"),
				TEXT("controller spaces")
			},
			{
				TEXT("editor shell ownership"),
				TEXT("product runtime ownership"),
				TEXT("browser-first app shell")
			},
			MakeAttribution(
				TEXT("mrdoob/three.js"),
				TEXT("browser-spatial/three-js"),
				TEXT("Preserves browser scene, renderer, and WebXR device-management seams from Three.Core.js and WebXRManager.js.")
			)
		),
		MakePackageReference(
			TEXT("package/react-three-fiber"),
			TEXT("react-three-fiber"),
			TEXT("react-renderer-anchor"),
			TEXT("React-side renderer substrate over three.js for canvas roots, frameloop control, and event-manager bridging."),
			{
				TEXT("createRoot"),
				TEXT("frameloop invalidation"),
				TEXT("raycaster/event bridge"),
				TEXT("camera/store lifecycle")
			},
			{
				TEXT("product shell ownership"),
				TEXT("generic app-state ownership"),
				TEXT("browser-only architecture control")
			},
			MakeAttribution(
				TEXT("pmndrs/react-three-fiber"),
				TEXT("browser-spatial/react-three-fiber"),
				TEXT("Preserves canvas-root configuration, renderer/store lifecycle, and pointer-event bridging from the retained fiber renderer.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-xr"),
			TEXT("pmndrs/xr"),
			TEXT("xr-session-anchor"),
			TEXT("Browser XR session, controller, hand, gaze, pointer, and session-store anchor for immersive support-plane work."),
			{
				TEXT("XR store"),
				TEXT("controller and hand state"),
				TEXT("gaze and screen input"),
				TEXT("pointer routing"),
				TEXT("session visibility")
			},
			{
				TEXT("gameplay ownership"),
				TEXT("simulation ownership"),
				TEXT("generic VR showroom shell")
			},
			MakeAttribution(
				TEXT("pmndrs/xr"),
				TEXT("browser-spatial/pmndrs-xr"),
				TEXT("Preserves XR store, session lifecycle, pointer-routing, and immersive interaction seams from the retained XR lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-uikit"),
			TEXT("pmndrs/uikit"),
			TEXT("spatial-ui-support"),
			TEXT("World-anchored panel, text, and control-kit substrate for browser-side spatial UI surfaces."),
			{
				TEXT("instanced panels"),
				TEXT("text/input components"),
				TEXT("theme kits"),
				TEXT("world-anchored controls")
			},
			{
				TEXT("visual-brand ownership"),
				TEXT("demo dashboard shell"),
				TEXT("global design-system ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/uikit"),
				TEXT("browser-spatial/pmndrs-uikit"),
				TEXT("Preserves instanced-panel, text-input, and world-anchored spatial UI seams from the retained uikit lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-postprocessing"),
			TEXT("pmndrs/postprocessing"),
			TEXT("effect-substrate-support"),
			TEXT("Effect-composer substrate for render passes, depth copies, multisampling, and bounded post effects."),
			{
				TEXT("effect composer"),
				TEXT("double-buffer render targets"),
				TEXT("depth/normal pass orchestration"),
				TEXT("pass ordering")
			},
			{
				TEXT("scene ownership"),
				TEXT("browser viewer ownership"),
				TEXT("demo effect gallery ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/postprocessing"),
				TEXT("browser-spatial/postprocessing"),
				TEXT("Preserves effect-composer lifecycle, pass ordering, and buffer-management seams from the retained postprocessing lane."),
				TEXT("Zlib")
			)
		),
		MakePackageReference(
			TEXT("package/react-postprocessing"),
			TEXT("react-postprocessing"),
			TEXT("react-effect-wrapper-support"),
			TEXT("React wrapper layer above postprocessing for declarative pass grouping and render-priority control."),
			{
				TEXT("composer context"),
				TEXT("render priority"),
				TEXT("declarative pass grouping"),
				TEXT("normal-pass gating")
			},
			{
				TEXT("scene ownership"),
				TEXT("browser shell ownership"),
				TEXT("effect showcase ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/react-postprocessing"),
				TEXT("browser-spatial/react-postprocessing"),
				TEXT("Preserves React-side effect-composer orchestration, pass grouping, and render-priority seams above postprocessing.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-drei"),
			TEXT("pmndrs/drei"),
			TEXT("helper-abstraction-support"),
			TEXT("High-leverage helper and abstraction layer above react-three-fiber for overlays, views, and spatial helper primitives."),
			{
				TEXT("View scissoring"),
				TEXT("Html overlay bridge"),
				TEXT("text and helper primitives"),
				TEXT("pivot/view helpers")
			},
			{
				TEXT("scene-substrate ownership"),
				TEXT("runtime ownership"),
				TEXT("product shell ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/drei"),
				TEXT("browser-spatial/drei"),
				TEXT("Preserves view scissoring, HTML overlay, and helper abstraction seams from the retained drei lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-three-stdlib"),
			TEXT("pmndrs/three-stdlib"),
			TEXT("shared-utility-support"),
			TEXT("Shared browser-side utility substrate for WebXR helpers, controller models, exporters, loaders, and geometry utilities."),
			{
				TEXT("XR controller models"),
				TEXT("hand models"),
				TEXT("geometry utilities"),
				TEXT("loader/exporter helpers")
			},
			{
				TEXT("scene ownership"),
				TEXT("gameplay ownership"),
				TEXT("app-shell ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/three-stdlib"),
				TEXT("browser-spatial/three-stdlib"),
				TEXT("Preserves WebXR helper, controller-model, and geometry-utility seams from the retained three-stdlib lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-maath"),
			TEXT("pmndrs/maath"),
			TEXT("math-helper-support"),
			TEXT("Math and easing helper substrate for damping, interpolation, geometry utilities, and motion-friendly spatial helpers."),
			{
				TEXT("damping"),
				TEXT("easing"),
				TEXT("geometry helpers"),
				TEXT("motion-friendly math")
			},
			{
				TEXT("animation-system ownership"),
				TEXT("scene ownership"),
				TEXT("app-shell ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/maath"),
				TEXT("browser-spatial/maath"),
				TEXT("Preserves damping, easing, and geometry-helper seams from the retained maath lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-zustand"),
			TEXT("pmndrs/zustand"),
			TEXT("state-substrate-support"),
			TEXT("Lightweight store, subscription, selector, and middleware substrate beneath browser-side spatial tools."),
			{
				TEXT("vanilla store"),
				TEXT("subscriptions"),
				TEXT("selector equality"),
				TEXT("persist/devtools middleware")
			},
			{
				TEXT("global product-state ownership"),
				TEXT("server-state ownership"),
				TEXT("runtime-foundation ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/zustand"),
				TEXT("browser-spatial/zustand"),
				TEXT("Preserves lightweight store creation, selector subscription, and middleware seams from the retained zustand lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-leva"),
			TEXT("pmndrs/leva"),
			TEXT("parameter-ui-support"),
			TEXT("Schema-driven control-panel and parameter-UI sidecar for browser-side spatial tools and debug surfaces."),
			{
				TEXT("schema-driven controls"),
				TEXT("headless store bridge"),
				TEXT("plugin inputs"),
				TEXT("parameter panels")
			},
			{
				TEXT("primary product UI ownership"),
				TEXT("theme ownership"),
				TEXT("persistent dashboard shell")
			},
			MakeAttribution(
				TEXT("pmndrs/leva"),
				TEXT("browser-spatial/leva"),
				TEXT("Preserves schema-driven controls, store-backed parameter panels, and plugin-extensible input seams from the retained leva lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-use-gesture"),
			TEXT("pmndrs/use-gesture"),
			TEXT("gesture-router-support"),
			TEXT("Browser-side gesture-routing substrate for drag, pinch, hover, move, scroll, and wheel interaction."),
			{
				TEXT("drag"),
				TEXT("pinch"),
				TEXT("hover"),
				TEXT("move"),
				TEXT("scroll/wheel")
			},
			{
				TEXT("product input-policy ownership"),
				TEXT("XR session ownership"),
				TEXT("scene ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/use-gesture"),
				TEXT("browser-spatial/use-gesture"),
				TEXT("Preserves drag, pinch, hover, move, scroll, and multi-gesture routing seams from the retained use-gesture lane.")
			)
		),
		MakePackageReference(
			TEXT("package/pmndrs-react-spring"),
			TEXT("pmndrs/react-spring"),
			TEXT("motion-substrate-support"),
			TEXT("Motion and interpolation substrate for browser-side spatial transitions, springs, and frame-synchronized movement."),
			{
				TEXT("useSpring hooks"),
				TEXT("controllers and spring values"),
				TEXT("interpolation"),
				TEXT("frame-scheduled motion")
			},
			{
				TEXT("scene ownership"),
				TEXT("app-shell ownership"),
				TEXT("global animation branding")
			},
			MakeAttribution(
				TEXT("pmndrs/react-spring"),
				TEXT("browser-spatial/react-spring"),
				TEXT("Preserves spring-hook, interpolation, and frame-scheduled motion seams from the retained react-spring lane.")
			)
		),
		MakePackageReference(
			TEXT("package/react-spring-core"),
			TEXT("@react-spring/core"),
			TEXT("folded-motion-package"),
			TEXT("Core controller, animation-config, interpolation, and scheduling logic folded beneath the retained react-spring lane."),
			{
				TEXT("Controller"),
				TEXT("AnimationConfig"),
				TEXT("Interpolation"),
				TEXT("hook implementations")
			},
			{
				TEXT("standalone product ownership"),
				TEXT("scene ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/react-spring"),
				TEXT("browser-spatial/react-spring-core"),
				TEXT("Preserves controller, spring-value, interpolation, and hook-core seams from @react-spring/core.")
			)
		),
		MakePackageReference(
			TEXT("package/react-spring-animated"),
			TEXT("@react-spring/animated"),
			TEXT("folded-motion-package"),
			TEXT("Animated host, animated value, and withAnimated helper package folded beneath the retained react-spring lane."),
			{
				TEXT("animated values"),
				TEXT("animated strings"),
				TEXT("animated host"),
				TEXT("withAnimated")
			},
			{
				TEXT("standalone product ownership"),
				TEXT("scene ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/react-spring"),
				TEXT("browser-spatial/react-spring-animated"),
				TEXT("Preserves animated host and animated-value seams from @react-spring/animated.")
			)
		),
		MakePackageReference(
			TEXT("package/react-spring-shared"),
			TEXT("@react-spring/shared"),
			TEXT("folded-motion-package"),
			TEXT("Shared interpolation, easing, reduced-motion, and global utility package folded beneath the retained react-spring lane."),
			{
				TEXT("interpolators"),
				TEXT("easings"),
				TEXT("reduced motion"),
				TEXT("globals and helpers")
			},
			{
				TEXT("standalone product ownership"),
				TEXT("scene ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/react-spring"),
				TEXT("browser-spatial/react-spring-shared"),
				TEXT("Preserves interpolator, easing, and reduced-motion seams from @react-spring/shared.")
			)
		),
		MakePackageReference(
			TEXT("package/react-spring-types"),
			TEXT("@react-spring/types"),
			TEXT("folded-motion-package"),
			TEXT("Type and interpolation contract package folded beneath the retained react-spring lane."),
			{
				TEXT("animated typing"),
				TEXT("interpolation typing"),
				TEXT("utility typing")
			},
			{
				TEXT("standalone product ownership"),
				TEXT("runtime ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/react-spring"),
				TEXT("browser-spatial/react-spring-types"),
				TEXT("Preserves animated and interpolation type-contract seams from @react-spring/types.")
			)
		),
		MakePackageReference(
			TEXT("package/react-spring-rafz"),
			TEXT("@react-spring/rafz"),
			TEXT("folded-motion-package"),
			TEXT("Frame-loop scheduler package folded beneath the retained react-spring lane."),
			{
				TEXT("frame scheduling"),
				TEXT("batched updates"),
				TEXT("raf lifecycle")
			},
			{
				TEXT("standalone product ownership"),
				TEXT("scene ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/react-spring"),
				TEXT("browser-spatial/react-spring-rafz"),
				TEXT("Preserves frame-scheduler seams from @react-spring/rafz.")
			)
		),
		MakePackageReference(
			TEXT("package/react-spring-parallax"),
			TEXT("@react-spring/parallax"),
			TEXT("folded-motion-package"),
			TEXT("Layered motion and panel-transition package folded beneath the retained react-spring lane."),
			{
				TEXT("parallax layers"),
				TEXT("scroll-linked transitions"),
				TEXT("panel motion")
			},
			{
				TEXT("standalone product ownership"),
				TEXT("scene ownership")
			},
			MakeAttribution(
				TEXT("pmndrs/react-spring"),
				TEXT("browser-spatial/react-spring-parallax"),
				TEXT("Preserves layered motion and panel-transition seams from @react-spring/parallax.")
			)
		)
	};

	FHyperTwistTrainingSpatialSceneContract SceneContract;
	SceneContract.ContractId = TEXT("browser-spatial-scene-stack");
	SceneContract.Title = TEXT("Browser spatial scene and renderer contract");
	SceneContract.Summary = TEXT("First-party browser spatial contract for scene roots, renderer lifecycle, frameloop invalidation, camera binding, event routing, and helper-portal seams without promoting donor editors or demo shells.");
	SceneContract.RequiredPackageIds =
	{
		TEXT("package/three-js"),
		TEXT("package/react-three-fiber"),
		TEXT("package/pmndrs-drei"),
		TEXT("package/pmndrs-three-stdlib"),
		TEXT("package/pmndrs-maath")
	};
	SceneContract.LifecycleStages =
	{
		TEXT("create canvas root"),
		TEXT("configure WebGL renderer"),
		TEXT("bind camera and raycaster"),
		TEXT("drive frameloop invalidation"),
		TEXT("host scissored views and overlays"),
		TEXT("dispose helper primitives")
	};
	SceneContract.EventSurfaceTags =
	{
		TEXT("canvas-root"),
		TEXT("pointer-event bridge"),
		TEXT("raycaster camera binding"),
		TEXT("scissored view embedding"),
		TEXT("HTML overlay bridge")
	};
	SceneContract.ExplicitExclusions =
	{
		TEXT("donor editor shell"),
		TEXT("demo documentation shell"),
		TEXT("browser-first runtime ownership")
	};
	SceneContract.SourceAttribution = MakeAttribution(
		TEXT("mrdoob/three.js"),
		TEXT("browser-spatial/scene-contract"),
		TEXT("Preserves three.js renderer and WebXR camera-management seams, paired with react-three-fiber root, frameloop, and event-bridge surfaces.")
	);
	Bundle.SceneContracts = {SceneContract};

	FHyperTwistTrainingSpatialXrSessionContract XrContract;
	XrContract.ContractId = TEXT("browser-spatial-xr-session-stack");
	XrContract.Title = TEXT("Browser XR session and immersive interaction contract");
	XrContract.Summary = TEXT("First-party browser XR contract for session modes, controller and hand state, gaze and screen input, pointer routing, dom overlays, and immersive interaction guards without promoting a donor showroom or gameplay shell.");
	XrContract.RequiredPackageIds =
	{
		TEXT("package/three-js"),
		TEXT("package/react-three-fiber"),
		TEXT("package/pmndrs-xr"),
		TEXT("package/pmndrs-three-stdlib")
	};
	XrContract.SessionModes =
	{
		TEXT("inline"),
		TEXT("immersive-vr"),
		TEXT("immersive-ar")
	};
	XrContract.InputSurfaceTags =
	{
		TEXT("controller target ray"),
		TEXT("controller grip"),
		TEXT("hand tracking"),
		TEXT("gaze input"),
		TEXT("screen input"),
		TEXT("pointer routing")
	};
	XrContract.InteractionSurfaceTags =
	{
		TEXT("session visibility"),
		TEXT("origin and space management"),
		TEXT("pointer combine"),
		TEXT("dom overlay"),
		TEXT("hit test and anchors"),
		TEXT("teleport and locomotion")
	};
	XrContract.ExplicitExclusions =
	{
		TEXT("gameplay ownership"),
		TEXT("simulation ownership"),
		TEXT("generic XR showroom shell")
	};
	XrContract.SourceAttribution = MakeAttribution(
		TEXT("pmndrs/xr"),
		TEXT("browser-spatial/xr-contract"),
		TEXT("Preserves XR store, session-mode, controller-input, and pointer-routing seams from the retained pmndrs/xr lane.")
	);
	Bundle.XrSessionContracts = {XrContract};

	FHyperTwistTrainingSpatialUiContract UiContract;
	UiContract.ContractId = TEXT("browser-spatial-ui-stack");
	UiContract.Title = TEXT("Browser spatial UI and world-anchored controls contract");
	UiContract.Summary = TEXT("First-party spatial UI contract for world-anchored panels, parameter controls, text/input components, view overlays, and state-backed spatial control surfaces without inheriting donor dashboards or generic design-system ownership.");
	UiContract.RequiredPackageIds =
	{
		TEXT("package/pmndrs-uikit"),
		TEXT("package/pmndrs-drei"),
		TEXT("package/pmndrs-zustand"),
		TEXT("package/pmndrs-leva"),
		TEXT("package/pmndrs-use-gesture")
	};
	UiContract.ComponentFamilies =
	{
		TEXT("instanced panels"),
		TEXT("buttons and toggles"),
		TEXT("sliders and tabs"),
		TEXT("text and input fields"),
		TEXT("tooltips and dialogs"),
		TEXT("parameter monitors")
	};
	UiContract.StateSurfaceTags =
	{
		TEXT("world-anchored control panel"),
		TEXT("schema-driven parameter state"),
		TEXT("gesture-routed interactions"),
		TEXT("HTML/spatial overlay bridge"),
		TEXT("headless control-store bridge")
	};
	UiContract.ExplicitExclusions =
	{
		TEXT("donor dashboard shells"),
		TEXT("generic design-system ownership"),
		TEXT("global product UI ownership")
	};
	UiContract.SourceAttribution = MakeAttribution(
		TEXT("pmndrs/uikit"),
		TEXT("browser-spatial/ui-contract"),
		TEXT("Preserves instanced panels, world-anchored controls, and state-backed parameter UI seams from uikit, leva, zustand, and use-gesture.")
	);
	Bundle.SpatialUiContracts = {UiContract};

	FHyperTwistTrainingSpatialEffectBoundary EffectBoundary;
	EffectBoundary.BoundaryId = TEXT("browser-spatial-effect-boundary");
	EffectBoundary.Title = TEXT("Browser post-processing and effect boundary");
	EffectBoundary.Summary = TEXT("First-party effect boundary for effect-composer setup, pass grouping, depth or normal helpers, render-priority control, and HyperTwist-owned effect policy without promoting donor preset galleries.");
	EffectBoundary.RequiredPackageIds =
	{
		TEXT("package/three-js"),
		TEXT("package/react-three-fiber"),
		TEXT("package/pmndrs-postprocessing"),
		TEXT("package/react-postprocessing")
	};
	EffectBoundary.EffectFamilies =
	{
		TEXT("render pass"),
		TEXT("effect pass"),
		TEXT("normal pass"),
		TEXT("depth downsampling"),
		TEXT("composer multisampling"),
		TEXT("tone mapping and highlight effects")
	};
	EffectBoundary.FirstPartyOwnedFields =
	{
		TEXT("effect enablement policy"),
		TEXT("training-specific highlight semantics"),
		TEXT("performance budgets"),
		TEXT("export and replay parity rules")
	};
	EffectBoundary.ExplicitExclusions =
	{
		TEXT("donor effect gallery ownership"),
		TEXT("browser shell ownership"),
		TEXT("scene ownership")
	};
	EffectBoundary.SourceAttribution = MakeAttribution(
		TEXT("pmndrs/postprocessing"),
		TEXT("browser-spatial/effect-boundary"),
		TEXT("Preserves effect-composer and pass-orchestration seams from postprocessing and react-postprocessing while keeping HyperTwist-specific effect policy first-party."),
		TEXT("Zlib")
	);
	Bundle.EffectBoundaries = {EffectBoundary};

	FHyperTwistTrainingSpatialStateMotionContract StateMotionContract;
	StateMotionContract.ContractId = TEXT("browser-spatial-state-motion-stack");
	StateMotionContract.Title = TEXT("Browser spatial state, gesture, and motion contract");
	StateMotionContract.Summary = TEXT("First-party state and motion contract for lightweight stores, selector subscriptions, gesture routing, spring-based motion, parameter panels, and helper interpolation beneath browser-side spatial tooling.");
	StateMotionContract.RequiredPackageIds =
	{
		TEXT("package/pmndrs-zustand"),
		TEXT("package/pmndrs-use-gesture"),
		TEXT("package/pmndrs-react-spring"),
		TEXT("package/react-spring-core"),
		TEXT("package/react-spring-animated"),
		TEXT("package/react-spring-shared"),
		TEXT("package/react-spring-types"),
		TEXT("package/react-spring-rafz"),
		TEXT("package/react-spring-parallax"),
		TEXT("package/pmndrs-leva")
	};
	StateMotionContract.StateKinds =
	{
		TEXT("lightweight browser store"),
		TEXT("selector subscriptions"),
		TEXT("persist/devtools middleware"),
		TEXT("schema-driven parameter state")
	};
	StateMotionContract.GestureKinds =
	{
		TEXT("drag"),
		TEXT("pinch"),
		TEXT("hover"),
		TEXT("wheel"),
		TEXT("move"),
		TEXT("multi-gesture composition")
	};
	StateMotionContract.MotionKinds =
	{
		TEXT("spring hooks"),
		TEXT("controller and spring values"),
		TEXT("interpolation"),
		TEXT("frame scheduling"),
		TEXT("reduced-motion support"),
		TEXT("layered transitions")
	};
	StateMotionContract.ExplicitExclusions =
	{
		TEXT("global product-state ownership"),
		TEXT("server-state ownership"),
		TEXT("donor playground UI ownership")
	};
	StateMotionContract.SourceAttribution = MakeAttribution(
		TEXT("pmndrs/react-spring"),
		TEXT("browser-spatial/state-motion-contract"),
		TEXT("Preserves state-store, gesture-routing, spring-motion, frame-scheduling, and parameter-panel seams from zustand, use-gesture, react-spring, and leva.")
	);
	Bundle.StateMotionContracts = {StateMotionContract};

	return Bundle;
}

bool UHyperTwistTrainingSpatialLibrary::TryGetSceneContractById(
	const FHyperTwistTrainingSpatialReferenceBundle& Bundle,
	const FString& ContractId,
	FHyperTwistTrainingSpatialSceneContract& OutContract
)
{
	for (const FHyperTwistTrainingSpatialSceneContract& Contract : Bundle.SceneContracts)
	{
		if (Contract.ContractId == ContractId)
		{
			OutContract = Contract;
			return true;
		}
	}

	OutContract = FHyperTwistTrainingSpatialSceneContract();
	return false;
}

bool UHyperTwistTrainingSpatialLibrary::TryGetXrSessionContractById(
	const FHyperTwistTrainingSpatialReferenceBundle& Bundle,
	const FString& ContractId,
	FHyperTwistTrainingSpatialXrSessionContract& OutContract
)
{
	for (const FHyperTwistTrainingSpatialXrSessionContract& Contract : Bundle.XrSessionContracts)
	{
		if (Contract.ContractId == ContractId)
		{
			OutContract = Contract;
			return true;
		}
	}

	OutContract = FHyperTwistTrainingSpatialXrSessionContract();
	return false;
}

bool UHyperTwistTrainingSpatialLibrary::TryGetSpatialUiContractById(
	const FHyperTwistTrainingSpatialReferenceBundle& Bundle,
	const FString& ContractId,
	FHyperTwistTrainingSpatialUiContract& OutContract
)
{
	for (const FHyperTwistTrainingSpatialUiContract& Contract : Bundle.SpatialUiContracts)
	{
		if (Contract.ContractId == ContractId)
		{
			OutContract = Contract;
			return true;
		}
	}

	OutContract = FHyperTwistTrainingSpatialUiContract();
	return false;
}

bool UHyperTwistTrainingSpatialLibrary::TryGetEffectBoundaryById(
	const FHyperTwistTrainingSpatialReferenceBundle& Bundle,
	const FString& BoundaryId,
	FHyperTwistTrainingSpatialEffectBoundary& OutBoundary
)
{
	for (const FHyperTwistTrainingSpatialEffectBoundary& Boundary : Bundle.EffectBoundaries)
	{
		if (Boundary.BoundaryId == BoundaryId)
		{
			OutBoundary = Boundary;
			return true;
		}
	}

	OutBoundary = FHyperTwistTrainingSpatialEffectBoundary();
	return false;
}

bool UHyperTwistTrainingSpatialLibrary::TryGetStateMotionContractById(
	const FHyperTwistTrainingSpatialReferenceBundle& Bundle,
	const FString& ContractId,
	FHyperTwistTrainingSpatialStateMotionContract& OutContract
)
{
	for (const FHyperTwistTrainingSpatialStateMotionContract& Contract : Bundle.StateMotionContracts)
	{
		if (Contract.ContractId == ContractId)
		{
			OutContract = Contract;
			return true;
		}
	}

	OutContract = FHyperTwistTrainingSpatialStateMotionContract();
	return false;
}

FString UHyperTwistTrainingSpatialLibrary::BuildPackageChecklistTsv(
	const FHyperTwistTrainingSpatialReferenceBundle& Bundle
)
{
	using namespace HyperTwistTrainingSpatialLibraryInternal;

	FString Output = TEXT("package_id\tlabel\townership_role\tretained_surfaces\tsummary\n");
	for (const FHyperTwistTrainingSpatialPackageReference& Reference : Bundle.PackageReferences)
	{
		if (!Reference.IsStructurallyValid())
		{
			continue;
		}

		Output.Append(Reference.PackageId);
		Output.Append(TEXT("\t"));
		Output.Append(Reference.Label);
		Output.Append(TEXT("\t"));
		Output.Append(Reference.OwnershipRole);
		Output.Append(TEXT("\t"));

		FString SurfaceTags;
		AppendJoined(SurfaceTags, Reference.RetainedSurfaceTags);
		Output.Append(SurfaceTags);
		Output.Append(TEXT("\t"));
		Output.Append(Reference.Summary.Replace(TEXT("\t"), TEXT(" ")));
		Output.Append(TEXT("\n"));
	}

	return Output;
}
