"""Agent abstraction for CLI coding agents."""

from __future__ import annotations

from paude.agents.base import Agent, AgentConfig
from paude.agents.claude import ClaudeAgent
from paude.agents.cursor import CursorAgent
from paude.agents.gemini import GeminiAgent
from paude.agents.openclaw import OpenClawAgent

__all__ = [
    "Agent",
    "AgentConfig",
    "ClaudeAgent",
    "CursorAgent",
    "GeminiAgent",
    "OpenClawAgent",
    "get_agent",
    "list_agents",
]

_REGISTRY: dict[str, type] = {
    "claude": ClaudeAgent,
    "cursor": CursorAgent,
    "gemini": GeminiAgent,
    "openclaw": OpenClawAgent,
}


def get_agent(name: str, provider: str | None = None) -> Agent:
    """Get an agent instance by name.

    Args:
        name: Agent name (e.g., "claude").
        provider: Inference provider name (e.g., "vertex", "openai"),
            or None for the agent's default provider.

    Returns:
        Agent instance.

    Raises:
        ValueError: If agent name is not registered or provider is invalid.
    """
    cls = _REGISTRY.get(name)
    if cls is None:
        available = ", ".join(sorted(_REGISTRY.keys()))
        raise ValueError(f"Unknown agent '{name}'. Available: {available}")
    return cls(provider=provider)  # type: ignore[no-any-return]


def list_agents() -> list[str]:
    """List all registered agent names.

    Returns:
        Sorted list of agent names.
    """
    return sorted(_REGISTRY.keys())
