"""Dynamic routing utilities for LangGraph (minimal actor-first stub)."""

from __future__ import annotations

from collections.abc import Callable
from typing import Any

from cleveragents.langgraph.nodes import Edge


class DynamicRouter:
    """Minimal dynamic router that selects edges by predicate."""

    def __init__(self, rules: list[dict[str, Any]] | None = None):
        self.rules = rules or []

    def route(self, message: Any) -> list[Edge]:
        edges: list[Edge] = []
        for rule in self.rules:
            cond: Callable[[Any], bool] | None = rule.get("condition")
            target = rule.get("target")
            if target and (cond is None or cond(message)):
                edges.append(Edge(source="start", target=target))
        if not edges:
            edges.append(Edge(source="start", target="end"))
        return edges
