package com.correx.core.transitions.analysis

import com.correx.core.events.types.StageId
import com.correx.core.transitions.graph.TransitionEdge
import com.correx.core.transitions.graph.WorkflowGraph

internal class DeterministicAdjacencyBuilder {
    fun build(graph: WorkflowGraph): Map<StageId, List<TransitionEdge>> {

        val grouped = graph.transitions
            .groupBy { it.from }

        return grouped.mapValues { (_, edges) ->
            edges.sortedWith(
                compareBy<TransitionEdge> { it.from.value }
                    .thenBy { it.id.value }
                    .thenBy { it.to.value }
            )
        }
    }
}
