"""
Agent manifest dependencies models.

Defines agent, service, and MCP server dependencies.
Inspired by Docker Compose depends_on pattern.
"""

from pydantic import BaseModel, Field

from typing import Literal, Optional


class AgentDependency(BaseModel):
    """
    Agent dependency configuration.

    Defines dependencies on other agents.
    """

    name: str = Field(..., description="Dependent agent name")
    version: Optional[str] = Field(
        None,
        description="Version constraint (e.g., >=1.0.0, 1.2.x)",
    )
    condition: Literal["service_started", "service_healthy"] = Field(
        "service_started",
        description="Condition for dependency to be ready",
    )
    required: bool = Field(True, description="Whether this dependency is required")


class ServiceConnection(BaseModel):
    """Service connection configuration."""

    host: Optional[str] = Field(None, description="Service host")
    port: Optional[int] = Field(None, description="Service port")
    url: Optional[str] = Field(None, description="Full connection URL")


class ServiceDependency(BaseModel):
    """
    Service dependency configuration.

    Defines dependencies on external services (databases, caches, etc.).
    """

    name: str = Field(..., description="Service name")
    type: str = Field(..., description="Service type (e.g., cache, database, queue)")
    connection: ServiceConnection = Field(..., description="Connection configuration")
    required: bool = Field(True, description="Whether this service is required")


class MCPServerDependency(BaseModel):
    """
    MCP server dependency configuration.

    Defines dependencies on MCP tool servers.
    """

    name: str = Field(..., description="MCP server name")
    url: str = Field(..., description="MCP server URL (e.g., mcp://tools.company.com)")
    required: bool = Field(True, description="Whether this MCP server is required")


class DependenciesConfig(BaseModel):
    """
    Dependencies configuration block.

    Defines all external dependencies for the agent.
    """

    # Agent dependencies
    agents: list[AgentDependency] = Field(
        default_factory=list,
        description="Dependent agents",
    )

    # Service dependencies
    services: list[ServiceDependency] = Field(
        default_factory=list,
        description="Dependent services",
    )

    # MCP server dependencies
    mcp_servers: list[MCPServerDependency] = Field(
        default_factory=list,
        description="Dependent MCP servers",
    )
