package layoutgraph

import (
	

	
	
)

const nodeGraphOwnershipSnapshotLocation = "NodeGraphOwnershipSnapshot"

// NodeGraphOwnershipSnapshot is a read-only capture of every pre-existing node
// owner reachable from a graph's runtime topology.
type NodeGraphOwnershipSnapshot struct {
	owners []nodeGraphOwner
}

type nodeGraphOwner struct {
	node  *Node
	graph *Graph
}

// Restore restores every graph pointer captured by the snapshot.
func ( NodeGraphOwnershipSnapshot) () {
	for ,  := range .owners {
		.node.Graph = .graph
	}
}

// SnapshotNodeGraphOwnership captures every node reachable through the graph's
// runtime topology, including nodes referenced only by grouping, tree,
// proximity, hub, or hierarchy state. It does not mutate the graph.
func ( context.Context,  *Graph) (NodeGraphOwnershipSnapshot, error) {
	if  == nil {
		return NodeGraphOwnershipSnapshot{}, invariant.New("node graph ownership snapshot requires a graph")
	}
	,  := limits.NewWorkGuard(, nodeGraphOwnershipSnapshotLocation, maxEngineWorkUnits)
	if  != nil {
		return NodeGraphOwnershipSnapshot{}, 
	}
	,  := collectRuntimeObjectsContext(, , "ownership runtime")
	if  != nil {
		return NodeGraphOwnershipSnapshot{}, 
	}
	 := make([]nodeGraphOwner, len(.nodeOrder))
	for ,  := range .nodeOrder {
		if  := .Step();  != nil {
			return NodeGraphOwnershipSnapshot{}, 
		}
		[] = nodeGraphOwner{node: , graph: .Graph}
	}
	if  := .Finish();  != nil {
		return NodeGraphOwnershipSnapshot{}, 
	}
	return NodeGraphOwnershipSnapshot{owners: }, nil
}