#pragma once

#include "CoreMinimal.h"
#include "HyperTwistMemoryTypes.generated.h"

UENUM(BlueprintType)
enum class EHyperTwistMemoryLane : uint8
{
	None UMETA(DisplayName = "None"),
	IdentityPolicy UMETA(DisplayName = "Identity And Policy"),
	WorkspaceRecall UMETA(DisplayName = "Workspace And Cockpit Recall"),
	ChronicleCapture UMETA(DisplayName = "Chronicle And Episodic Capture"),
	ContinuityResume UMETA(DisplayName = "Continuity And Resume"),
	SharedCoordination UMETA(DisplayName = "Shared Coordination"),
	RecallRetrieval UMETA(DisplayName = "Recall And Retrieval"),
	CognitiveConsolidated UMETA(DisplayName = "Cognitive And Consolidated"),
	KnowledgeWiki UMETA(DisplayName = "Knowledge And Wiki"),
	UserNotes UMETA(DisplayName = "User Notes"),
	ProvenanceLedger UMETA(DisplayName = "Provenance And Trust Ledger"),
	DerivedCompacted UMETA(DisplayName = "Derived And Compacted"),
	ProceduralWorkflow UMETA(DisplayName = "Procedural And Workflow")
};

UENUM(BlueprintType)
enum class EHyperTwistMemoryAuthorityKind : uint8
{
	None UMETA(DisplayName = "None"),
	Authoritative UMETA(DisplayName = "Authoritative"),
	SemiAuthoritative UMETA(DisplayName = "Semi-Authoritative"),
	DerivedOnly UMETA(DisplayName = "Derived Only")
};

UENUM(BlueprintType)
enum class EHyperTwistMemoryFeatureGateDefaultState : uint8
{
	None UMETA(DisplayName = "None"),
	RequiredEnabled UMETA(DisplayName = "Required Enabled"),
	EnabledByDefault UMETA(DisplayName = "Enabled By Default"),
	DisabledByDefault UMETA(DisplayName = "Disabled By Default")
};

UENUM(BlueprintType)
enum class EHyperTwistMemoryContextAssemblyProfile : uint8
{
	None UMETA(DisplayName = "None"),
	EconomicRetentionMode UMETA(DisplayName = "Economic-Retention Mode"),
	MaxRetentionMode UMETA(DisplayName = "Max-Retention Mode")
};

UENUM(BlueprintType)
enum class EHyperTwistMemoryKnowledgePromotionDecision : uint8
{
	None UMETA(DisplayName = "None"),
	Approved UMETA(DisplayName = "Approved"),
	Deferred UMETA(DisplayName = "Deferred"),
	Blocked UMETA(DisplayName = "Blocked")
};

UENUM(BlueprintType)
enum class EHyperTwistMemoryContinuityGuardSeverity : uint8
{
	None UMETA(DisplayName = "None"),
	Advisory UMETA(DisplayName = "Advisory"),
	Warning UMETA(DisplayName = "Warning"),
	Blocking UMETA(DisplayName = "Blocking")
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryProvenanceLink
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ParentEntityId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane ParentLane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ParentRecordKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ParentReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ParentSourceLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bParentAuthoritative = false;

	bool IsStructurallyValid() const
	{
		return !ParentEntityId.IsEmpty()
			&& ParentLane != EHyperTwistMemoryLane::None
			&& !ParentRecordKind.IsEmpty();
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryFeatureGate
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString GateId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SettingsKey;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DisplayLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryFeatureGateDefaultState DefaultState =
		EHyperTwistMemoryFeatureGateDefaultState::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bUserControllable = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bDisableAllowed = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Summary;

	bool IsStructurallyValid() const
	{
		return !GateId.IsEmpty()
			&& !SettingsKey.IsEmpty()
			&& Lane != EHyperTwistMemoryLane::None
			&& DefaultState != EHyperTwistMemoryFeatureGateDefaultState::None;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryLaneContract
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString LaneId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DisplayLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind = EHyperTwistMemoryAuthorityKind::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DefaultSettingsKey;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DefaultFeatureGateId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bFirstPartyOwned = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bCurrentEvidencePresent = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Summary;

	bool IsStructurallyValid() const
	{
		return Lane != EHyperTwistMemoryLane::None
			&& !LaneId.IsEmpty()
			&& !DisplayLabel.IsEmpty()
			&& AuthorityKind != EHyperTwistMemoryAuthorityKind::None
			&& !DefaultSettingsKey.IsEmpty()
			&& !DefaultFeatureGateId.IsEmpty();
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryEntityDescriptor
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString EntityId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RecordKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DisplayLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DeckId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind = EHyperTwistMemoryAuthorityKind::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bDerived = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (EntityId.IsEmpty()
			|| RecordKind.IsEmpty()
			|| DisplayLabel.IsEmpty()
			|| UserId.IsEmpty()
			|| Lane == EHyperTwistMemoryLane::None
			|| AuthorityKind == EHyperTwistMemoryAuthorityKind::None)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return !bDerived || ProvenanceLinks.Num() > 0;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemorySettingsProfile
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ProfileId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DisplayLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryContextAssemblyProfile ContextAssemblyProfile =
		EHyperTwistMemoryContextAssemblyProfile::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> EnabledFeatureGateIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> DisabledFeatureGateIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Summary;

	bool IsStructurallyValid() const
	{
		return !ProfileId.IsEmpty()
			&& !DisplayLabel.IsEmpty()
			&& ContextAssemblyProfile != EHyperTwistMemoryContextAssemblyProfile::None;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryLedgerState
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryLaneContract> LaneContracts;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryFeatureGate> FeatureGates;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryEntityDescriptor> Entities;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FHyperTwistMemorySettingsProfile EconomicRetentionProfile;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FHyperTwistMemorySettingsProfile MaxRetentionProfile;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 AuthoritativeEntityCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 SemiAuthoritativeEntityCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 DerivedEntityCount = 0;

	bool IsStructurallyValid() const
	{
		if (UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| LaneContracts.Num() == 0
			|| FeatureGates.Num() == 0
			|| !EconomicRetentionProfile.IsStructurallyValid()
			|| !MaxRetentionProfile.IsStructurallyValid())
		{
			return false;
		}

		for (const FHyperTwistMemoryLaneContract& LaneContract : LaneContracts)
		{
			if (!LaneContract.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryFeatureGate& FeatureGate : FeatureGates)
		{
			if (!FeatureGate.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryEntityDescriptor& Entity : Entities)
		{
			if (!Entity.IsStructurallyValid())
			{
				return false;
			}
		}

		const int32 TotalEntityCount =
			AuthoritativeEntityCount + SemiAuthoritativeEntityCount + DerivedEntityCount;
		return TotalEntityCount == Entities.Num();
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryChronicleEventEntry
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString EventId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString EventKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DisplayLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DeckId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RootRecordId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RelatedTrainingSessionId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RelatedReviewPlanId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RelatedQueueId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RecordedAtUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bOpenContinuity = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (EventId.IsEmpty()
			|| EventKind.IsEmpty()
			|| DisplayLabel.IsEmpty()
			|| UserId.IsEmpty()
			|| RecordedAtUtc.IsEmpty()
			|| Lane == EHyperTwistMemoryLane::None)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemorySessionGroup
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString GroupId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString GroupKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DeckId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RootRecordId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RootTrainingSessionId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RootReviewPlanId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RootQueueId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> ChronicleEventIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> FocusCaseIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 EventCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bCompleted = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bHasResumeCandidate = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRequiresContinuityGuard = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (GroupId.IsEmpty()
			|| GroupKind.IsEmpty()
			|| Headline.IsEmpty()
			|| UserId.IsEmpty()
			|| RootRecordId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| ChronicleEventIds.Num() == 0
			|| EventCount != ChronicleEventIds.Num())
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryResumePack
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PackId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PackKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DeckId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ResumeTargetId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ResumeActionId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::ContinuityResume;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> ChronicleGroupIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> FocusCaseIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 PendingItemCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bNeedsContinuityGuard = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bTimeSensitive = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (PackId.IsEmpty()
			|| PackKind.IsEmpty()
			|| Headline.IsEmpty()
			|| UserId.IsEmpty()
			|| ResumeTargetId.IsEmpty()
			|| ResumeActionId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane == EHyperTwistMemoryLane::None
			|| ChronicleGroupIds.Num() == 0
			|| PendingItemCount < 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryContinuityGuard
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString GuardId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString GuardKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::ContinuityResume;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryContinuityGuardSeverity Severity =
		EHyperTwistMemoryContinuityGuardSeverity::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> RelatedRecordIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> RepairActions;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bBlocksResume = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRequiresManualReview = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (GuardId.IsEmpty()
			|| GuardKind.IsEmpty()
			|| Headline.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane == EHyperTwistMemoryLane::None
			|| Severity == EHyperTwistMemoryContinuityGuardSeverity::None)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryChronicleContinuityState
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryChronicleEventEntry> ChronicleEvents;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemorySessionGroup> SessionGroups;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryResumePack> ResumePacks;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryContinuityGuard> ContinuityGuards;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ChronicleCaptureEventCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ContinuityResumeEventCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 OpenSessionGroupCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ResumeRequiredCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 BlockingGuardCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bHasRepositoryContinuityIssues = false;

	bool IsStructurallyValid() const
	{
		if (UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| (ChronicleEvents.Num() == 0
				&& SessionGroups.Num() == 0
				&& ResumePacks.Num() == 0
				&& ContinuityGuards.Num() == 0))
		{
			return false;
		}

		for (const FHyperTwistMemoryChronicleEventEntry& ChronicleEvent : ChronicleEvents)
		{
			if (!ChronicleEvent.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemorySessionGroup& SessionGroup : SessionGroups)
		{
			if (!SessionGroup.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryResumePack& ResumePack : ResumePacks)
		{
			if (!ResumePack.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryContinuityGuard& ContinuityGuard : ContinuityGuards)
		{
			if (!ContinuityGuard.IsStructurallyValid())
			{
				return false;
			}
		}

		int32 ComputedChronicleCaptureEventCount = 0;
		int32 ComputedContinuityResumeEventCount = 0;
		for (const FHyperTwistMemoryChronicleEventEntry& ChronicleEvent : ChronicleEvents)
		{
			if (ChronicleEvent.Lane == EHyperTwistMemoryLane::ChronicleCapture)
			{
				++ComputedChronicleCaptureEventCount;
			}
			else if (ChronicleEvent.Lane == EHyperTwistMemoryLane::ContinuityResume)
			{
				++ComputedContinuityResumeEventCount;
			}
		}

		int32 ComputedOpenSessionGroupCount = 0;
		for (const FHyperTwistMemorySessionGroup& SessionGroup : SessionGroups)
		{
			if (!SessionGroup.bCompleted)
			{
				++ComputedOpenSessionGroupCount;
			}
		}

		int32 ComputedBlockingGuardCount = 0;
		for (const FHyperTwistMemoryContinuityGuard& ContinuityGuard : ContinuityGuards)
		{
			if (ContinuityGuard.Severity == EHyperTwistMemoryContinuityGuardSeverity::Blocking)
			{
				++ComputedBlockingGuardCount;
			}
		}

		return ChronicleCaptureEventCount == ComputedChronicleCaptureEventCount
			&& ContinuityResumeEventCount == ComputedContinuityResumeEventCount
			&& OpenSessionGroupCount == ComputedOpenSessionGroupCount
			&& ResumeRequiredCount == ResumePacks.Num()
			&& BlockingGuardCount == ComputedBlockingGuardCount;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryRecallMatch
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString MatchId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString MatchKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DeckId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SourceEntityId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SourceRecordKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SourceRecordId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind = EHyperTwistMemoryAuthorityKind::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 MatchScore = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> MatchReasonLines;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (MatchId.IsEmpty()
			|| MatchKind.IsEmpty()
			|| Headline.IsEmpty()
			|| UserId.IsEmpty()
			|| SourceEntityId.IsEmpty()
			|| SourceRecordKind.IsEmpty()
			|| SourceRecordId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane == EHyperTwistMemoryLane::None
			|| AuthorityKind == EHyperTwistMemoryAuthorityKind::None
			|| MatchScore <= 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryProvenanceDrillDownEntry
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DrillDownId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RootEntityId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RootRecordKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind = EHyperTwistMemoryAuthorityKind::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> LineageEntityIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> SourceLabels;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ProvenanceDepth = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bHasAuthoritativeLineage = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (DrillDownId.IsEmpty()
			|| RootEntityId.IsEmpty()
			|| RootRecordKind.IsEmpty()
			|| Headline.IsEmpty()
			|| Lane == EHyperTwistMemoryLane::None
			|| AuthorityKind == EHyperTwistMemoryAuthorityKind::None
			|| ProvenanceDepth < 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemorySharedContextRule
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RuleId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ContextId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DisplayLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane SourceLane = EHyperTwistMemoryLane::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> AllowedRecordKinds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> AllowedTargetSurfaces;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bSessionLocalOnly = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRevocable = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRequiresAuthoritativeProvenance = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Summary;

	bool IsStructurallyValid() const
	{
		return !RuleId.IsEmpty()
			&& !ContextId.IsEmpty()
			&& !DisplayLabel.IsEmpty()
			&& SourceLane != EHyperTwistMemoryLane::None
			&& AllowedRecordKinds.Num() > 0
			&& AllowedTargetSurfaces.Num() > 0;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemorySharedContextProjection
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ProjectionId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ContextId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RuleId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> RelatedMatchIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> RelatedEntityIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRevocable = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bSessionLocalOnly = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRequiresAuthoritativeProvenance = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (ProjectionId.IsEmpty()
			|| ContextId.IsEmpty()
			|| Headline.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| RuleId.IsEmpty()
			|| RelatedMatchIds.Num() == 0
			|| RelatedEntityIds.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryRecallSharedContextState
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString QueryText;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> QueryTokens;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryRecallMatch> RecallMatches;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceDrillDownEntry> ProvenanceDrillDownEntries;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemorySharedContextRule> SharedContextRules;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemorySharedContextProjection> SharedContextProjections;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 RecallResultCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 AuthoritativeRecallCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 SemiAuthoritativeRecallCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 SharedContextProjectionCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bHasScopedSharedContext = false;

	bool IsStructurallyValid() const
	{
		if (UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| QueryText.IsEmpty()
			|| QueryTokens.Num() == 0
			|| SharedContextRules.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryRecallMatch& RecallMatch : RecallMatches)
		{
			if (!RecallMatch.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryProvenanceDrillDownEntry& DrillDownEntry :
			ProvenanceDrillDownEntries)
		{
			if (!DrillDownEntry.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemorySharedContextRule& SharedContextRule : SharedContextRules)
		{
			if (!SharedContextRule.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemorySharedContextProjection& SharedContextProjection :
			SharedContextProjections)
		{
			if (!SharedContextProjection.IsStructurallyValid())
			{
				return false;
			}
		}

		int32 ComputedAuthoritativeRecallCount = 0;
		int32 ComputedSemiAuthoritativeRecallCount = 0;
		for (const FHyperTwistMemoryRecallMatch& RecallMatch : RecallMatches)
		{
			if (RecallMatch.AuthorityKind == EHyperTwistMemoryAuthorityKind::Authoritative)
			{
				++ComputedAuthoritativeRecallCount;
			}
			else if (RecallMatch.AuthorityKind ==
				EHyperTwistMemoryAuthorityKind::SemiAuthoritative)
			{
				++ComputedSemiAuthoritativeRecallCount;
			}
		}

		return RecallResultCount == RecallMatches.Num()
			&& AuthoritativeRecallCount == ComputedAuthoritativeRecallCount
			&& SemiAuthoritativeRecallCount == ComputedSemiAuthoritativeRecallCount
			&& SharedContextProjectionCount == SharedContextProjections.Num()
			&& bHasScopedSharedContext == (SharedContextProjections.Num() > 0);
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryCognitiveFact
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString FactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString FactFamily;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString FactKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DeckId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::CognitiveConsolidated;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind =
		EHyperTwistMemoryAuthorityKind::SemiAuthoritative;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> SourceEntityIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SummaryLine;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ConfidenceScore = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 EvidenceCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bActive = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRequiresReview = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SupersededByFactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> ContradictionIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (FactId.IsEmpty()
			|| FactFamily.IsEmpty()
			|| FactKind.IsEmpty()
			|| Headline.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane != EHyperTwistMemoryLane::CognitiveConsolidated
			|| AuthorityKind == EHyperTwistMemoryAuthorityKind::None
			|| SourceEntityIds.Num() == 0
			|| SummaryLine.IsEmpty()
			|| ConfidenceScore < 0
			|| ConfidenceScore > 100
			|| EvidenceCount <= 0
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryCognitiveContradiction
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ContradictionId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString FactFamily;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString LeftFactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString RightFactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ResolutionLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bBlocksPromotion = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bNeedsManualReview = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (ContradictionId.IsEmpty()
			|| FactFamily.IsEmpty()
			|| Headline.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| LeftFactId.IsEmpty()
			|| RightFactId.IsEmpty()
			|| ResolutionLabel.IsEmpty()
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryCognitiveSupersession
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SupersessionId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString FactFamily;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PriorFactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString CurrentFactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReasonLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bResolvedByHigherConfidence = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (SupersessionId.IsEmpty()
			|| FactFamily.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| PriorFactId.IsEmpty()
			|| CurrentFactId.IsEmpty()
			|| ReasonLabel.IsEmpty()
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryConfidenceDecayEntry
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DecayId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString FactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString TriggerLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 PreviousConfidenceScore = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 CurrentConfidenceScore = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bBelowPromotionThreshold = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (DecayId.IsEmpty()
			|| FactId.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| TriggerLabel.IsEmpty()
			|| PreviousConfidenceScore < 0
			|| PreviousConfidenceScore > 100
			|| CurrentConfidenceScore < 0
			|| CurrentConfidenceScore > 100
			|| CurrentConfidenceScore >= PreviousConfidenceScore
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryCognitiveConsolidationState
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryCognitiveFact> Facts;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryCognitiveContradiction> Contradictions;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryCognitiveSupersession> Supersessions;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryConfidenceDecayEntry> ConfidenceDecays;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ActiveFactCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 SupersededFactCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ContradictionCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 LowConfidenceFactCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bHasOpenCognitiveReview = false;

	bool IsStructurallyValid() const
	{
		if (UserId.IsEmpty() || ReferenceUtc.IsEmpty() || Facts.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryCognitiveFact& Fact : Facts)
		{
			if (!Fact.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryCognitiveContradiction& Contradiction : Contradictions)
		{
			if (!Contradiction.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryCognitiveSupersession& Supersession : Supersessions)
		{
			if (!Supersession.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryConfidenceDecayEntry& ConfidenceDecay :
			ConfidenceDecays)
		{
			if (!ConfidenceDecay.IsStructurallyValid())
			{
				return false;
			}
		}

		int32 ComputedActiveFactCount = 0;
		int32 ComputedSupersededFactCount = 0;
		int32 ComputedLowConfidenceFactCount = 0;
		bool bComputedOpenCognitiveReview = false;

		for (const FHyperTwistMemoryCognitiveFact& Fact : Facts)
		{
			if (Fact.bActive)
			{
				++ComputedActiveFactCount;
			}
			if (!Fact.SupersededByFactId.IsEmpty())
			{
				++ComputedSupersededFactCount;
			}
			if (Fact.ConfidenceScore < 50)
			{
				++ComputedLowConfidenceFactCount;
			}
			if (Fact.bRequiresReview)
			{
				bComputedOpenCognitiveReview = true;
			}
		}

		for (const FHyperTwistMemoryCognitiveContradiction& Contradiction : Contradictions)
		{
			if (Contradiction.bNeedsManualReview)
			{
				bComputedOpenCognitiveReview = true;
			}
		}

		return ActiveFactCount == ComputedActiveFactCount
			&& SupersededFactCount == ComputedSupersededFactCount
			&& ContradictionCount == Contradictions.Num()
			&& LowConfidenceFactCount == ComputedLowConfidenceFactCount
			&& bHasOpenCognitiveReview == bComputedOpenCognitiveReview;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryKnowledgeObject
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ObjectId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ObjectKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Title;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Summary;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::KnowledgeWiki;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind =
		EHyperTwistMemoryAuthorityKind::Authoritative;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ScopeLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> SourceRecordIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> Tags;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (ObjectId.IsEmpty()
			|| ObjectKind.IsEmpty()
			|| Title.IsEmpty()
			|| Summary.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane != EHyperTwistMemoryLane::KnowledgeWiki
			|| AuthorityKind != EHyperTwistMemoryAuthorityKind::Authoritative
			|| ScopeLabel.IsEmpty()
			|| SourceRecordIds.Num() == 0
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryKnowledgePromotionReview
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReviewId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString CandidateFactId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ProposedKnowledgeObjectId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryKnowledgePromotionDecision Decision =
		EHyperTwistMemoryKnowledgePromotionDecision::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReasonLabel;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bNeedsManualReview = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> BlockingContradictionIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (ReviewId.IsEmpty()
			|| CandidateFactId.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Headline.IsEmpty()
			|| Decision == EHyperTwistMemoryKnowledgePromotionDecision::None
			|| ReasonLabel.IsEmpty()
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryUserNotesPosture
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::UserNotes;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString GateId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SettingsKey;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SummaryLine;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bOwnershipJustified = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bLaneEnabled = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bAcceptsUserAuthoredContent = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRequiresSeparateOwnerActivation = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane != EHyperTwistMemoryLane::UserNotes
			|| GateId.IsEmpty()
			|| SettingsKey.IsEmpty()
			|| Headline.IsEmpty()
			|| SummaryLine.IsEmpty()
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return bAcceptsUserAuthoredContent
			? (bOwnershipJustified && bLaneEnabled)
			: true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryKnowledgeNotesState
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryKnowledgeObject> KnowledgeObjects;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryKnowledgePromotionReview> PromotionReviews;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FHyperTwistMemoryUserNotesPosture UserNotesPosture;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 CuratedReferenceObjectCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ApprovedPromotionCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 DeferredPromotionCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 BlockedPromotionCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bKnowledgeWikiEnabled = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bUserNotesLaneAvailable = false;

	bool IsStructurallyValid() const
	{
		if (UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| KnowledgeObjects.Num() == 0
			|| !UserNotesPosture.IsStructurallyValid())
		{
			return false;
		}

		for (const FHyperTwistMemoryKnowledgeObject& KnowledgeObject : KnowledgeObjects)
		{
			if (!KnowledgeObject.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryKnowledgePromotionReview& PromotionReview :
			PromotionReviews)
		{
			if (!PromotionReview.IsStructurallyValid())
			{
				return false;
			}
		}

		const int32 ComputedPromotionCount =
			ApprovedPromotionCount + DeferredPromotionCount + BlockedPromotionCount;
		const bool bComputedUserNotesLaneAvailable =
			UserNotesPosture.bOwnershipJustified
			&& UserNotesPosture.bLaneEnabled
			&& UserNotesPosture.bAcceptsUserAuthoredContent;

		return CuratedReferenceObjectCount >= 0
			&& CuratedReferenceObjectCount <= KnowledgeObjects.Num()
			&& ComputedPromotionCount == PromotionReviews.Num()
			&& bKnowledgeWikiEnabled
			&& bUserNotesLaneAvailable == bComputedUserNotesLaneAvailable;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryCompactSummary
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SummaryId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SummaryKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SummaryText;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::DerivedCompacted;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind =
		EHyperTwistMemoryAuthorityKind::DerivedOnly;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> SourceEntityIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (SummaryId.IsEmpty()
			|| SummaryKind.IsEmpty()
			|| Headline.IsEmpty()
			|| SummaryText.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane != EHyperTwistMemoryLane::DerivedCompacted
			|| AuthorityKind != EHyperTwistMemoryAuthorityKind::DerivedOnly
			|| SourceEntityIds.Num() == 0
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryReducedContextPacket
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PacketId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PacketKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Headline;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString PacketBody;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::DerivedCompacted;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind =
		EHyperTwistMemoryAuthorityKind::DerivedOnly;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 MaxTokenHint = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> SourceEntityIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (PacketId.IsEmpty()
			|| PacketKind.IsEmpty()
			|| Headline.IsEmpty()
			|| PacketBody.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane != EHyperTwistMemoryLane::DerivedCompacted
			|| AuthorityKind != EHyperTwistMemoryAuthorityKind::DerivedOnly
			|| MaxTokenHint <= 0
			|| SourceEntityIds.Num() == 0
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryDigestView
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DigestId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString DigestKind;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString Title;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SummaryLine;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryLane Lane = EHyperTwistMemoryLane::DerivedCompacted;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryAuthorityKind AuthorityKind =
		EHyperTwistMemoryAuthorityKind::DerivedOnly;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bUserVisible = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRemovable = true;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FString> SourceEntityIds;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryProvenanceLink> ProvenanceLinks;

	bool IsStructurallyValid() const
	{
		if (DigestId.IsEmpty()
			|| DigestKind.IsEmpty()
			|| Title.IsEmpty()
			|| SummaryLine.IsEmpty()
			|| UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| Lane != EHyperTwistMemoryLane::DerivedCompacted
			|| AuthorityKind != EHyperTwistMemoryAuthorityKind::DerivedOnly
			|| !bUserVisible
			|| !bRemovable
			|| SourceEntityIds.Num() == 0
			|| ProvenanceLinks.Num() == 0)
		{
			return false;
		}

		for (const FHyperTwistMemoryProvenanceLink& ProvenanceLink : ProvenanceLinks)
		{
			if (!ProvenanceLink.IsStructurallyValid())
			{
				return false;
			}
		}

		return true;
	}
};

USTRUCT(BlueprintType)
struct FHyperTwistMemoryDerivedAdjunctState
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString UserId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString ReferenceUtc;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	EHyperTwistMemoryContextAssemblyProfile ContextAssemblyProfile =
		EHyperTwistMemoryContextAssemblyProfile::None;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString FeatureGateId;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	FString SettingsKey;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryCompactSummary> CompactSummaries;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryReducedContextPacket> ReducedContextPackets;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	TArray<FHyperTwistMemoryDigestView> DigestViews;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 CompactSummaryCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 ReducedContextPacketCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	int32 DigestViewCount = 0;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bDerivedGateActive = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bDerivedOnlyStorageConfirmed = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bRemovableWithoutLineageLoss = false;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "HyperTwist")
	bool bAllFeaturesOffSafe = false;

	bool IsStructurallyValid() const
	{
		if (UserId.IsEmpty()
			|| ReferenceUtc.IsEmpty()
			|| ContextAssemblyProfile == EHyperTwistMemoryContextAssemblyProfile::None
			|| FeatureGateId.IsEmpty()
			|| SettingsKey.IsEmpty()
			|| !bDerivedOnlyStorageConfirmed
			|| !bRemovableWithoutLineageLoss
			|| !bAllFeaturesOffSafe)
		{
			return false;
		}

		for (const FHyperTwistMemoryCompactSummary& CompactSummary : CompactSummaries)
		{
			if (!CompactSummary.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryReducedContextPacket& ReducedContextPacket :
			ReducedContextPackets)
		{
			if (!ReducedContextPacket.IsStructurallyValid())
			{
				return false;
			}
		}

		for (const FHyperTwistMemoryDigestView& DigestView : DigestViews)
		{
			if (!DigestView.IsStructurallyValid())
			{
				return false;
			}
		}

		const bool bCountsMatch =
			CompactSummaryCount == CompactSummaries.Num()
			&& ReducedContextPacketCount == ReducedContextPackets.Num()
			&& DigestViewCount == DigestViews.Num();
		if (!bCountsMatch)
		{
			return false;
		}

		if (bDerivedGateActive)
		{
			return CompactSummaryCount > 0
				&& ReducedContextPacketCount > 0
				&& DigestViewCount > 0;
		}

		return CompactSummaryCount == 0
			&& ReducedContextPacketCount == 0
			&& DigestViewCount == 0;
	}
};
