import pytest

from inire.geometry.collision import CollisionEngine
from inire.geometry.primitives import Port
from inire.router.astar import AStarRouter
from inire.router.cost import CostEvaluator
from inire.router.danger_map import DangerMap
from inire.router.pathfinder import PathFinder


@pytest.fixture
def basic_evaluator() -> CostEvaluator:
    engine = CollisionEngine(clearance=2.0)
    danger_map = DangerMap(bounds=(0, 0, 100, 100))
    danger_map.precompute([])
    return CostEvaluator(engine, danger_map)


def test_pathfinder_parallel(basic_evaluator: CostEvaluator) -> None:
    router = AStarRouter(basic_evaluator)
    pf = PathFinder(router, basic_evaluator)

    netlist = {
        "net1": (Port(0, 0, 0), Port(50, 0, 0)),
        "net2": (Port(0, 10, 0), Port(50, 10, 0)),
    }
    net_widths = {"net1": 2.0, "net2": 2.0}

    results = pf.route_all(netlist, net_widths)

    assert len(results) == 2
    assert results["net1"].is_valid
    assert results["net2"].is_valid
    assert results["net1"].collisions == 0
    assert results["net2"].collisions == 0
