// Clean-room implementation for HyperTwist algorithm-language subsystem
// Implemented from governance docs only (Phase 0R-D, Phase 1R, Phase 5R-A)
// Date: 2026-05-15
// Model: Claude (Model B, Bound 1 contribution)

#include "HyperTwistAlgorithm/HyperTwistAlgorithmTypes.h"

bool FHyperTwistAlgorithmNode::operator==(const FHyperTwistAlgorithmNode& Other) const
{
	if (NodeType != Other.NodeType)
	{
		return false;
	}

	switch (NodeType)
	{
	case EHyperTwistAlgorithmNodeType::BlockMove:
		return BlockMove == Other.BlockMove;

	case EHyperTwistAlgorithmNodeType::Group:
		{
			if (Group.Amount != Other.Group.Amount || Group.Inner.Num() != Other.Group.Inner.Num())
			{
				return false;
			}
			for (int32 Index = 0; Index < Group.Inner.Num(); ++Index)
			{
				if (!(Group.Inner[Index] == Other.Group.Inner[Index]))
				{
					return false;
				}
			}
			return true;
		}

	case EHyperTwistAlgorithmNodeType::Commutator:
		{
			if (Commutator.Amount != Other.Commutator.Amount
				|| Commutator.A.Num() != Other.Commutator.A.Num()
				|| Commutator.B.Num() != Other.Commutator.B.Num())
			{
				return false;
			}
			for (int32 Index = 0; Index < Commutator.A.Num(); ++Index)
			{
				if (!(Commutator.A[Index] == Other.Commutator.A[Index]))
				{
					return false;
				}
			}
			for (int32 Index = 0; Index < Commutator.B.Num(); ++Index)
			{
				if (!(Commutator.B[Index] == Other.Commutator.B[Index]))
				{
					return false;
				}
			}
			return true;
		}

	case EHyperTwistAlgorithmNodeType::Conjugate:
		{
			if (Conjugate.Amount != Other.Conjugate.Amount
				|| Conjugate.A.Num() != Other.Conjugate.A.Num()
				|| Conjugate.B.Num() != Other.Conjugate.B.Num())
			{
				return false;
			}
			for (int32 Index = 0; Index < Conjugate.A.Num(); ++Index)
			{
				if (!(Conjugate.A[Index] == Other.Conjugate.A[Index]))
				{
					return false;
				}
			}
			for (int32 Index = 0; Index < Conjugate.B.Num(); ++Index)
			{
				if (!(Conjugate.B[Index] == Other.Conjugate.B[Index]))
				{
					return false;
				}
			}
			return true;
		}

	case EHyperTwistAlgorithmNodeType::Comment:
		return Comment.CommentType == Other.Comment.CommentType
			&& Comment.CommentText == Other.Comment.CommentText;

	case EHyperTwistAlgorithmNodeType::Pause:
	case EHyperTwistAlgorithmNodeType::Newline:
		return true;  // These have no payload

	case EHyperTwistAlgorithmNodeType::Sequence:
	default:
		return false;  // Sequence nodes should not be nested
	}
}
