// Copyright (c) 2026 The elk-go Authors.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0.
//
// SPDX-License-Identifier: EPL-2.0

package networksimplex

// Adapter lets a caller retain its own node and edge arena IDs while using
// the common network-simplex implementation. Nodes and outgoing edges must be
// supplied in their Java iteration order.
type Adapter[ comparable,  comparable] struct {
	Nodes     []
	Outgoing  func() []
	Source    func() 
	Target    func() 
	Weight    func() float64
	MinLength func() int
}

// Options configures the callback-based Layer entry point.
type Options struct {
	Balance                    bool
	PreviousLayeringNodeCounts []int
	IterationLimit             int
}

// Layer maps a caller-owned acyclic graph into ELK's common graph, executes
// network simplex, and returns layers keyed by the original node IDs.
func [ comparable,  comparable]( Adapter[, ],  Options) map[]int {
	 := NewGraph()
	 := make(map[]NodeID, len(.Nodes))
	for ,  := range .Nodes {
		 := .AddNode()
		.Node().Origin = 
		[] = 
	}
	for ,  := range .Nodes {
		for ,  := range .Outgoing() {
			 := .AddEdge(
				[.Source()],
				[.Target()],
				.Weight(),
				.MinLength(),
			)
			.Edge().Origin = 
		}
	}
	 := ForGraph().WithBalancing(.Balance)
	if .PreviousLayeringNodeCounts != nil {
		.WithPreviousLayering(.PreviousLayeringNodeCounts)
	}
	if .IterationLimit != 0 {
		.WithIterationLimit(.IterationLimit)
	}
	.Execute()
	 := make(map[]int, len(.Nodes))
	for ,  := range .Nodes {
		[] = .Node([]).Layer
	}
	return 
}