"""
Agent manifest base model.

Defines the top-level AgentManifestV1 that combines all manifest components.
"""

from pydantic import BaseModel, Field

from typing import Literal, Optional

from aphub_sdk.schemas.manifest.a2a import A2AConfig
from aphub_sdk.schemas.manifest.dependencies import DependenciesConfig
from aphub_sdk.schemas.manifest.execution import ExecutionConfig
from aphub_sdk.schemas.manifest.mcp import MCPConfig
from aphub_sdk.schemas.manifest.metadata import AgentMetadata
from aphub_sdk.schemas.manifest.runtime import RuntimeConfig
from aphub_sdk.schemas.manifest.spec import AgentSpec


class AgentManifestV1(BaseModel):
    """
    Agent Manifest v1.0

    The standardized declarative format for describing AI Agents.
    Inspired by Docker's container specification patterns.

    Example:
        ```yaml
        apiVersion: aipartnerup.com/v1
        kind: Agent

        metadata:
          name: customer-support-agent
          version: 1.0.0

        spec:
          framework: crewai
          role: "Customer Support Specialist"
          goal: "Provide helpful responses to customer inquiries"
        ```
    """

    # Schema version (required)
    api_version: Literal["aipartnerup.com/v1"] = Field(
        "aipartnerup.com/v1",
        alias="apiVersion",
        description="Schema version",
    )

    # Resource type (required)
    kind: Literal["Agent"] = Field("Agent", description="Resource type")

    # Identity (required)
    metadata: AgentMetadata = Field(..., description="Agent identity and versioning")

    # Specification (required)
    spec: AgentSpec = Field(..., description="Agent behavior specification")

    # Runtime configuration (optional)
    runtime: Optional[RuntimeConfig] = Field(None, description="Runtime environment configuration")

    # Execution configuration (optional)
    execution: Optional[ExecutionConfig] = Field(None, description="Execution configuration")

    # Dependencies (optional)
    dependencies: Optional[DependenciesConfig] = Field(None, description="External dependencies")

    # MCP configuration (optional)
    mcp: Optional[MCPConfig] = Field(None, description="MCP server/client configuration")

    # A2A configuration (optional)
    a2a: Optional[A2AConfig] = Field(None, description="A2A protocol configuration")

    # Labels for filtering (optional)
    labels: dict[str, str] = Field(
        default_factory=dict,
        description="Filterable key-value labels",
    )

    # Annotations for metadata (optional)
    annotations: dict[str, str] = Field(
        default_factory=dict,
        description="Non-filterable metadata annotations",
    )

    model_config = {"populate_by_name": True}
