// Copyright HyperTwist, Inc. All Rights Reserved.

#pragma once

#include "CoreMinimal.h"

namespace HyperTwistTrainingControlSurfaceFormatting
{
	inline FString DescribeBool(const bool bValue)
	{
		return bValue ? TEXT("yes") : TEXT("no");
	}

	inline FString DescribeReadyState(const bool bValue)
	{
		return bValue ? TEXT("ready") : TEXT("not ready");
	}

	inline FString DescribeAggregateReadyState(
		const bool bPrimaryReady,
		const bool bSecondaryReady
	)
	{
		if (bPrimaryReady && bSecondaryReady)
		{
			return TEXT("ready");
		}

		if (bPrimaryReady || bSecondaryReady)
		{
			return TEXT("partial");
		}

		return TEXT("missing");
	}

	inline FString DescribeOwnedContinuityState(
		const bool bOwnershipReady,
		const bool bContinuityReady
	)
	{
		if (!bOwnershipReady)
		{
			return TEXT("missing");
		}

		return bContinuityReady ? TEXT("ready") : TEXT("partial");
	}

	inline FString DescribeIdOrFallback(const FString& Value)
	{
		return !Value.IsEmpty() ? Value : FString(TEXT("n/a"));
	}

	inline FString DescribeIdIfReady(
		const bool bReady,
		const FString& Value
	)
	{
		return DescribeIdOrFallback(bReady ? Value : FString());
	}

	inline int32 DescribeCountIfReady(
		const bool bReady,
		const int32 Count
	)
	{
		return bReady ? Count : 0;
	}

	inline FString BuildControlInputPreferencesStatusLine(
		const bool bCameraSettingsContinuityReady,
		const FString& CameraExportArtifactId,
		const bool bImmersiveSessionRecallReady,
		const FString& ImmersiveSessionRecallBoundaryId,
		const int32 ImmersiveSessionRecallScopeCount,
		const int32 ImmersiveSessionRecallPreferenceFieldTagCount
	)
	{
		return FString::Printf(
			TEXT("Preferences continuity: %s | camera export %s | immersive recall %s | recall scopes %d | preference fields %d | controller settings/rebinding are now first-party-owned, while packaged controller proof is not yet shipped."),
			*DescribeAggregateReadyState(
				bCameraSettingsContinuityReady,
				bImmersiveSessionRecallReady),
			*DescribeIdIfReady(
				bCameraSettingsContinuityReady,
				CameraExportArtifactId),
			*DescribeIdIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallBoundaryId),
			DescribeCountIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallScopeCount),
			DescribeCountIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallPreferenceFieldTagCount)
		);
	}

	inline FString BuildControlSettingsCameraSettingsLine(
		const bool bCameraSettingsReady,
		const bool bCameraSettingsContinuityReady,
		const FString& CameraSettingsToolId,
		const FString& CameraSettingsExportArtifactId,
		const int32 CameraSettingsWorkflowTagCount,
		const int32 CameraSettingsPreviewStateTagCount,
		const int32 CameraSettingsExportArtifactCount
	)
	{
		return FString::Printf(
			TEXT("Viewer camera settings: %s | tool %s | camera export %s | workflow tags %d | preview states %d | export artifacts %d | orbit/framing/export surface is owned."),
			*DescribeOwnedContinuityState(
				bCameraSettingsReady,
				bCameraSettingsContinuityReady),
			*DescribeIdIfReady(
				bCameraSettingsReady,
				CameraSettingsToolId),
			*DescribeIdIfReady(
				bCameraSettingsContinuityReady,
				CameraSettingsExportArtifactId),
			DescribeCountIfReady(
				bCameraSettingsReady,
				CameraSettingsWorkflowTagCount),
			DescribeCountIfReady(
				bCameraSettingsReady,
				CameraSettingsPreviewStateTagCount),
			DescribeCountIfReady(
				bCameraSettingsReady,
				CameraSettingsExportArtifactCount)
		);
	}

	inline FString BuildControlSettingsImmersiveSettingsLine(
		const bool bImmersivePresenceSettingsReady,
		const bool bImmersiveSessionRecallReady,
		const FString& ImmersivePresenceContractId,
		const FString& ImmersiveSessionRecallBoundaryId,
		const int32 ImmersionIntensityPresetCount,
		const int32 ReducedDistractionPresetCount,
		const int32 ImmersivePresenceSurfaceTagCount,
		const int32 ImmersiveSessionRecallScopeCount,
		const int32 ImmersiveSessionRecallPreferenceFieldTagCount,
		const int32 ImmersiveSessionRecallResetSurfaceTagCount
	)
	{
		return FString::Printf(
			TEXT("Immersive presence settings: %s | contract %s | session recall %s | intensity presets %d | reduced-distraction presets %d | presence tags %d | recall scopes %d | preference fields %d | reset surfaces %d."),
			*DescribeOwnedContinuityState(
				bImmersivePresenceSettingsReady,
				bImmersiveSessionRecallReady),
			*DescribeIdIfReady(
				bImmersivePresenceSettingsReady,
				ImmersivePresenceContractId),
			*DescribeIdIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallBoundaryId),
			DescribeCountIfReady(
				bImmersivePresenceSettingsReady,
				ImmersionIntensityPresetCount),
			DescribeCountIfReady(
				bImmersivePresenceSettingsReady,
				ReducedDistractionPresetCount),
			DescribeCountIfReady(
				bImmersivePresenceSettingsReady,
				ImmersivePresenceSurfaceTagCount),
			DescribeCountIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallScopeCount),
			DescribeCountIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallPreferenceFieldTagCount),
			DescribeCountIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallResetSurfaceTagCount)
		);
	}

	inline FString BuildControlSettingsStatusLine(
		const bool bCameraSettingsReady,
		const bool bCameraSettingsContinuityReady,
		const bool bImmersivePresenceSettingsReady,
		const bool bImmersiveSessionRecallReady,
		const bool bMagic120CellViewSettingsReady,
		const bool bMagic120CellPersistenceSettingsReady,
		const bool bMagicCube5DViewSettingsReady,
		const bool bMagicCube5DPersistenceSettingsReady,
		const bool bMagic120CellSelectorSettingsReady,
		const bool bMagicCube5DSelectorSettingsReady,
		const bool bRepositoryBackedSelectorRecallReady,
		const bool bControllerRebindingOwnershipReady,
		const bool bWindowsPackagedControllerProofReady
	)
	{
		return FString::Printf(
			TEXT("camera %s | immersive %s | 120-cell owned settings %s | 5D owned settings %s | selectors %s | selector recall %s | XR rebinding %s | packaged proof %s"),
			*DescribeOwnedContinuityState(
				bCameraSettingsReady,
				bCameraSettingsContinuityReady),
			*DescribeOwnedContinuityState(
				bImmersivePresenceSettingsReady,
				bImmersiveSessionRecallReady),
			*DescribeAggregateReadyState(
				bMagic120CellViewSettingsReady,
				bMagic120CellPersistenceSettingsReady),
			*DescribeAggregateReadyState(
				bMagicCube5DViewSettingsReady,
				bMagicCube5DPersistenceSettingsReady),
			*DescribeAggregateReadyState(
				bMagic120CellSelectorSettingsReady,
				bMagicCube5DSelectorSettingsReady),
			bRepositoryBackedSelectorRecallReady ? TEXT("ready") : TEXT("unavailable"),
			bControllerRebindingOwnershipReady ? TEXT("owned") : TEXT("missing"),
			bWindowsPackagedControllerProofReady ? TEXT("ready") : TEXT("not yet shipped")
		);
	}

	inline FString BuildControlSettingsFamilyOwnedLine(
		const TCHAR* FamilyLabel,
		const bool bViewSettingsReady,
		const bool bPersistenceSettingsReady,
		const FString& ViewProfileContractId,
		const FString& SessionSurfaceId,
		const FString& SceneSurfaceId,
		const FString& PersistenceBoundaryId,
		const FString& StateSemanticsId,
		const int32 SelectorCount,
		const TCHAR* SecondMetricLabel,
		const int32 ProjectionSurfaceTagCount,
		const int32 SecondMetricCount,
		const TCHAR* ThirdMetricLabel,
		const int32 ThirdMetricCount,
		const TCHAR* FourthMetricLabel,
		const int32 FourthMetricCount
	)
	{
		return FString::Printf(
			TEXT("%s owned settings: %s | profile %s | session %s | scene %s | persistence %s | semantics %s | selectors %d | projection tags %d | %s %d | %s %d | %s %d."),
			FamilyLabel,
			*DescribeAggregateReadyState(
				bViewSettingsReady,
				bPersistenceSettingsReady),
			*DescribeIdIfReady(
				bViewSettingsReady,
				ViewProfileContractId),
			*DescribeIdIfReady(
				bPersistenceSettingsReady,
				SessionSurfaceId),
			*DescribeIdIfReady(
				bPersistenceSettingsReady,
				SceneSurfaceId),
			*DescribeIdIfReady(
				bPersistenceSettingsReady,
				PersistenceBoundaryId),
			*DescribeIdIfReady(
				bPersistenceSettingsReady,
				StateSemanticsId),
			DescribeCountIfReady(
				bViewSettingsReady,
				SelectorCount),
			DescribeCountIfReady(
				bViewSettingsReady,
				ProjectionSurfaceTagCount),
			SecondMetricLabel,
			DescribeCountIfReady(
				bViewSettingsReady,
				SecondMetricCount),
			ThirdMetricLabel,
			DescribeCountIfReady(
				bViewSettingsReady,
				ThirdMetricCount),
			FourthMetricLabel,
			DescribeCountIfReady(
				bViewSettingsReady,
				FourthMetricCount)
		);
	}

	inline FString BuildControlSettingsSelectorOwnershipLine(
		const bool bMagic120CellSelectorSettingsReady,
		const bool bMagicCube5DSelectorSettingsReady,
		const bool bActiveHigherDimensionalSettingsVisible,
		const FString& ActiveHigherDimensionalViewContextId,
		const FString& ActiveHigherDimensionalSessionSurfaceId,
		const FString& ActiveHigherDimensionalInteractiveSceneSurfaceId,
		const int32 ActiveHigherDimensionalSelectorCount
	)
	{
		return FString::Printf(
			TEXT("Higher-dimensional selector ownership: %s | active context %s | active session %s | active scene %s | active selectors %d."),
			*DescribeAggregateReadyState(
				bMagic120CellSelectorSettingsReady,
				bMagicCube5DSelectorSettingsReady),
			*DescribeIdIfReady(
				bActiveHigherDimensionalSettingsVisible,
				ActiveHigherDimensionalViewContextId),
			*DescribeIdIfReady(
				bActiveHigherDimensionalSettingsVisible,
				ActiveHigherDimensionalSessionSurfaceId),
			*DescribeIdIfReady(
				bActiveHigherDimensionalSettingsVisible,
				ActiveHigherDimensionalInteractiveSceneSurfaceId),
			DescribeCountIfReady(
				bActiveHigherDimensionalSettingsVisible,
				ActiveHigherDimensionalSelectorCount)
		);
	}

	inline FString BuildControlProfilePreferencesContinuityLine(
		const bool bCameraSettingsContinuityReady,
		const FString& CameraSettingsExportArtifactId,
		const bool bImmersiveSessionRecallReady,
		const FString& ImmersiveSessionRecallBoundaryId,
		const int32 ImmersiveSessionRecallScopeCount,
		const int32 ImmersiveSessionRecallPreferenceFieldTagCount
	)
	{
		return FString::Printf(
			TEXT("Profile continuity: %s | camera export %s | immersive recall %s | recall scopes %d | preference fields %d."),
			*DescribeAggregateReadyState(
				bCameraSettingsContinuityReady,
				bImmersiveSessionRecallReady),
			*DescribeIdIfReady(
				bCameraSettingsContinuityReady,
				CameraSettingsExportArtifactId),
			*DescribeIdIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallBoundaryId),
			DescribeCountIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallScopeCount),
			DescribeCountIfReady(
				bImmersiveSessionRecallReady,
				ImmersiveSessionRecallPreferenceFieldTagCount)
		);
	}

	inline FString BuildControlProfileStatusLine(
		const bool bClassicKeyboardProfileReady,
		const bool bImmersivePresenceProfileReady,
		const bool bMagic120CellProfileReady,
		const bool bMagicCube5DProfileReady,
		const bool bActiveHigherDimensionalProfileVisible,
		const bool bRepositoryBackedSelectorRecallReady,
		const bool bCameraSettingsContinuityReady,
		const bool bImmersiveSessionRecallReady,
		const bool bControllerRebindingOwnershipReady,
		const bool bWindowsPackagedControllerProofReady
	)
	{
		return FString::Printf(
			TEXT("classic keyboard %s | immersive presets %s | 120-cell family %s | 5D family %s | active selection %s | selector recall %s | profile continuity %s | controller rebinding %s | packaged proof %s"),
			bClassicKeyboardProfileReady ? TEXT("ready") : TEXT("missing"),
			bImmersivePresenceProfileReady ? TEXT("ready") : TEXT("missing"),
			bMagic120CellProfileReady ? TEXT("ready") : TEXT("missing"),
			bMagicCube5DProfileReady ? TEXT("ready") : TEXT("missing"),
			bActiveHigherDimensionalProfileVisible ? TEXT("visible") : TEXT("not loaded"),
			bRepositoryBackedSelectorRecallReady ? TEXT("ready") : TEXT("unavailable"),
			*DescribeAggregateReadyState(
				bCameraSettingsContinuityReady,
				bImmersiveSessionRecallReady),
			bControllerRebindingOwnershipReady ? TEXT("owned") : TEXT("missing"),
			bWindowsPackagedControllerProofReady ? TEXT("ready") : TEXT("not yet shipped")
		);
	}
}
