#include "HyperTwistXR/HyperTwistXrRuntimeLibrary.h"

namespace HyperTwistXrRuntimeLibraryInternal
{
	FHyperTwistTrainingSourceAttribution MakeFirstPartyAttribution(
		const FString& TrackId,
		const FString& Notes
	)
	{
		FHyperTwistTrainingSourceAttribution Attribution;
		Attribution.SourceMode = EHyperTwistTrainingSourceMode::FirstParty;
		Attribution.SourceTrackId = TrackId;
		Attribution.SourceNotes = Notes;
		return Attribution;
	}
}

FHyperTwistXrPreferenceProfile UHyperTwistXrRuntimeLibrary::GetDefaultXrPreferenceProfile()
{
	using namespace HyperTwistXrRuntimeLibraryInternal;

	FHyperTwistXrPreferenceProfile Profile;
	Profile.ProfileId = TEXT("xr-openxr-training-preferences/v1");
	Profile.Title = TEXT("OpenXR desktop-training preferences");
	Profile.Summary = TEXT("First-party desktop-hosted OpenXR preference bundle for locomotion, comfort, posture, world scale, and dominant-hand defaults beneath the still-bounded XR runtime lane.");
	Profile.PreferenceFieldTags =
	{
		TEXT("movement speed"),
		TEXT("vertical adjustment"),
		TEXT("snap turn"),
		TEXT("smooth turn fallback"),
		TEXT("pointer length"),
		TEXT("world scale"),
		TEXT("dominant hand"),
		TEXT("posture mode")
	};
	Profile.ComfortSurfaceTags =
	{
		TEXT("comfort vignette strength"),
		TEXT("seated height offset"),
		TEXT("snap-turn comfort"),
		TEXT("world-scale recenter")
	};
	Profile.ExplicitExclusions =
	{
		TEXT("platform-global guardian ownership"),
		TEXT("cross-title cloud remap storage"),
		TEXT("generic social VR avatar shell")
	};
	Profile.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/xr-openxr-training-preferences"),
		TEXT("Owns first-party XR training preferences for HyperTwist without promoting the remaining packaged-controller validation gate to finished product status.")
	);
	return Profile;
}

FHyperTwistXrControllerBindingProfile
UHyperTwistXrRuntimeLibrary::GetDefaultXrControllerBindingProfile()
{
	using namespace HyperTwistXrRuntimeLibraryInternal;

	FHyperTwistXrControllerBindingProfile Profile;
	Profile.ProfileId = TEXT("xr-openxr-motion-controllers/v1");
	Profile.Title = TEXT("OpenXR motion-controller binding profile");
	Profile.Summary = TEXT("First-party motion-controller axis profile for locomotion, turning, grip, and trigger ownership inside the bounded HyperTwist XR training lane.");
	Profile.RequiredAxisNames =
	{
		TEXT("HyperTwistXr_MoveForward"),
		TEXT("HyperTwistXr_MoveRight"),
		TEXT("HyperTwistXr_Turn"),
		TEXT("HyperTwistXr_LookPitch"),
		TEXT("HyperTwistXr_LeftGrip"),
		TEXT("HyperTwistXr_RightGrip"),
		TEXT("HyperTwistXr_LeftTrigger"),
		TEXT("HyperTwistXr_RightTrigger")
	};
	Profile.ControllerFamilyIds =
	{
		TEXT("controller/vive"),
		TEXT("controller/mixed-reality"),
		TEXT("controller/oculus-touch"),
		TEXT("controller/valve-index")
	};
	Profile.InteractionSurfaceTags =
	{
		TEXT("camera-aligned locomotion vector"),
		TEXT("snap-turn ownership"),
		TEXT("trigger and grip value capture"),
		TEXT("bounded desktop-hosted XR interaction")
	};
	Profile.ExplicitExclusions =
	{
		TEXT("platform-global controller remap UI"),
		TEXT("vendor-specific hand-tracking ownership"),
		TEXT("full room-scale locomotion sandbox")
	};
	Profile.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/xr-openxr-motion-controller-bindings"),
		TEXT("Owns the HyperTwist OpenXR motion-controller binding substrate for the desktop-hosted simulator without claiming finished cross-device rebinding polish.")
	);
	return Profile;
}

FHyperTwistXrControllerSettingsOwnershipSurface
UHyperTwistXrRuntimeLibrary::BuildBundledXrControllerSettingsOwnershipSurface()
{
	using namespace HyperTwistXrRuntimeLibraryInternal;

	const FHyperTwistXrControllerBindingProfile BindingProfile =
		GetDefaultXrControllerBindingProfile();

	FHyperTwistXrControllerSettingsOwnershipSurface Surface;
	Surface.SettingsOwnerId = TEXT("xr-openxr-controller-settings-owner/v1");
	Surface.RebindingSurfaceId = TEXT("xr-openxr-controller-rebinding-surface/v1");
	Surface.Title = TEXT("OpenXR controller settings and rebinding owner");
	Surface.Summary = TEXT("First-party user-visible controller settings and rebinding ownership for the bounded desktop-hosted HyperTwist OpenXR lane, covering the exact shipped XR input ids, layout presets, and per-session comfort tuning without claiming packaged controller certification.");
	Surface.DefaultLayoutPresetId = TEXT("xr-openxr-controller-layout-default/v1");
	Surface.UserVisibleSettingFieldTags =
	{
		TEXT("locomotion hand preference"),
		TEXT("turn hand preference"),
		TEXT("look pitch inversion"),
		TEXT("vertical adjust shoulder polarity"),
		TEXT("grip analog dead zone"),
		TEXT("trigger analog dead zone"),
		TEXT("snap-turn mode toggle"),
		TEXT("haptic intensity")
	};
	Surface.RebindableInputNames =
	{
		TEXT("HyperTwistXr_MoveForward"),
		TEXT("HyperTwistXr_MoveRight"),
		TEXT("HyperTwistXr_VerticalAdjust"),
		TEXT("HyperTwistXr_Turn"),
		TEXT("HyperTwistXr_LookPitch"),
		TEXT("HyperTwistXr_LeftGrip"),
		TEXT("HyperTwistXr_RightGrip"),
		TEXT("HyperTwistXr_LeftTrigger"),
		TEXT("HyperTwistXr_RightTrigger"),
		TEXT("HyperTwistXr_Recenter"),
		TEXT("HyperTwistXr_ToggleSnapTurn"),
		TEXT("HyperTwistXr_TogglePostureMode")
	};
	Surface.LayoutPresetIds =
	{
		TEXT("xr-openxr-controller-layout-default/v1"),
		TEXT("xr-openxr-controller-layout-southpaw/v1"),
		TEXT("xr-openxr-controller-layout-seated-comfort/v1")
	};
	Surface.SupportedControllerFamilies = BindingProfile.ControllerFamilyIds;
	Surface.ExplicitExclusions =
	{
		TEXT("platform-global controller remap UI"),
		TEXT("vendor-specific hand-tracking ownership"),
		TEXT("launch-tier packaged controller certification ownership")
	};
	Surface.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/xr-openxr-controller-settings-rebinding"),
		TEXT("Owns first-party user-visible XR controller settings and rebinding inside the bounded HyperTwist desktop simulator while keeping packaged controller proof and cross-device certification outside the current packet.")
	);
	return Surface;
}

FHyperTwistXrRuntimeOwnershipSurface
UHyperTwistXrRuntimeLibrary::BuildBundledXrRuntimeOwnershipSurface()
{
	using namespace HyperTwistXrRuntimeLibraryInternal;

	const FHyperTwistXrPreferenceProfile PreferenceProfile = GetDefaultXrPreferenceProfile();
	const FHyperTwistXrControllerBindingProfile BindingProfile =
		GetDefaultXrControllerBindingProfile();

	FHyperTwistXrRuntimeOwnershipSurface Surface;
	Surface.RuntimeOwnerId = TEXT("xr/openxr-desktop-training-runtime-owner");
	Surface.Title = TEXT("Desktop-hosted OpenXR training runtime owner");
	Surface.Summary = TEXT("Bounded first-party OpenXR runtime owner for motion-controller anchors, camera-aligned locomotion, comfort-aware turning, and preference-driven desktop XR training posture beneath the still-open packaged-controller proof gate.");
	Surface.PreferenceProfileId = PreferenceProfile.ProfileId;
	Surface.ControllerBindingProfileId = BindingProfile.ProfileId;
	Surface.WorldAnchorContractId = TEXT("immersive-training-world-anchor-contract");
	Surface.LeftMotionSourceId = TEXT("Left");
	Surface.RightMotionSourceId = TEXT("Right");
	Surface.RequiredPackageIds =
	{
		TEXT("package/hypertwist-immersive-environment-shell"),
		TEXT("package/hypertwist-immersive-world-anchors"),
		TEXT("package/hypertwist-immersive-focus-presence-controls")
	};
	Surface.RequiredSurfaceTags =
	{
		TEXT("motion-controller pose anchors"),
		TEXT("camera-aligned locomotion vector"),
		TEXT("training-world recenter"),
		TEXT("bounded trigger and grip interaction")
	};
	Surface.SupportedControllerFamilies = BindingProfile.ControllerFamilyIds;
	Surface.ExplicitExclusions =
	{
		TEXT("platform-global guardian ownership"),
		TEXT("generic social VR hub ownership"),
		TEXT("launch-tier packaged controller certification ownership")
	};
	Surface.SourceAttribution = MakeFirstPartyAttribution(
		TEXT("first-party/xr-openxr-runtime-owner"),
		TEXT("Owns the bounded OpenXR runtime-owner seam for HyperTwist desktop XR training while keeping finished controller validation and cross-device launch certification outside the current packet.")
	);
	return Surface;
}
