"""Smoke test: verify all modules import correctly."""

def main():
    # Core
    from nexus.core.agent import Agent, AgentTool, tool
    from nexus.core.task import Task, TaskGraph, TaskStatus
    from nexus.core.handoff import Handoff, HandoffMode, delegate_to, transfer_to, broadcast_to
    from nexus.core.state import SharedState
    from nexus.core.message import Message, Conversation, Role
    print("✅ Core primitives OK")

    # Types
    from nexus.types import AgentCapability, TaskConstraints, AgentCard, TokenUsage, ContentPart
    print("✅ Types OK")

    # Protocol
    from nexus.protocol.bus import MessageBus
    from nexus.protocol.discovery import DiscoveryService
    from nexus.protocol.a2a import A2AClient, A2AServer
    from nexus.protocol.mcp import MCPToolProvider
    print("✅ Protocol layer OK")

    # Runtime
    from nexus.runtime.checkpoint import CheckpointStore, InMemoryCheckpointStore, FileCheckpointStore
    from nexus.runtime.policies import RetryPolicy, FallbackPolicy, EscalationPolicy, PolicyChain
    from nexus.runtime.budget import TokenBudgetManager, BudgetConfig, BudgetStatus
    print("✅ Runtime layer OK")

    # Runtime engine
    from nexus.runtime.engine import ExecutionEngine
    print("✅ Execution engine OK")

    # Orchestration
    from nexus.orchestration.topology import TopologyEngine, TopologyMode
    from nexus.orchestration.graph import GraphOrchestrator, Node, Edge
    from nexus.orchestration.router import RouterOrchestrator
    from nexus.orchestration.adaptive import AdaptiveOrchestrator
    print("✅ Orchestration layer OK")

    # Observability
    from nexus.observability.tracing import Tracer, Span
    from nexus.observability.metrics import MetricsCollector
    print("✅ Observability layer OK")

    # Models
    from nexus.models.base import ModelProvider
    from nexus.models.openai import OpenAIProvider
    from nexus.models.anthropic import AnthropicProvider
    from nexus.models.ollama import OllamaProvider
    from nexus.models.litellm import LiteLLMProvider, LITELLM_PROVIDER_PREFIXES
    print("✅ Models layer OK")

    # High-Level API
    from nexus.api import Team, run
    print("✅ High-Level API OK")

    # CLI
    from nexus.cli import main as cli_main
    print("✅ CLI OK")

    print()
    print("🎉 All modules imported successfully!")

    # Quick functionality test
    cap_a = AgentCapability(coding=0.9, reasoning=0.8)
    cap_b = AgentCapability(coding=0.3, writing=0.9)
    sim = cap_a.cosine_similarity(cap_b)
    print(f"   Capability similarity test: {sim:.3f}")

    agent = Agent(name="TestAgent", instructions="You are a test agent")
    card = agent.to_agent_card()
    print(f"   Agent card: {card.name} (id={card.agent_id})")

    task = Task(name="test", description="A test task")
    print(f"   Task status: {task.status.value}")

    bus = MessageBus()
    print(f"   MessageBus topics: {bus.topics}")

    budget = TokenBudgetManager(BudgetConfig(max_total_cost_usd=1.0))
    print(f"   Budget status: {budget.status.value}")

    # LiteLLM auto-detection test
    from nexus.api import _create_provider
    p = _create_provider("groq/llama-3.1-70b-versatile")
    assert isinstance(p, LiteLLMProvider), f"Expected LiteLLMProvider, got {type(p)}"
    p2 = _create_provider("deepseek/deepseek-chat")
    assert isinstance(p2, LiteLLMProvider)
    p3 = _create_provider("gpt-4o")
    assert isinstance(p3, OpenAIProvider)
    p4 = _create_provider("some-local-model")
    assert isinstance(p4, OllamaProvider)
    p5 = _create_provider("any-model", provider="litellm")
    assert isinstance(p5, LiteLLMProvider)
    print("   LiteLLM auto-detection: all 5 cases passed")

    print()
    print("✅ All smoke tests passed!")


if __name__ == "__main__":
    main()
