# Copyright 2025 WhoMeta Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Agent model for UAP

Generated by WhoMeta Unified Agent Protocol SDK
"""
from __future__ import annotations

from typing import Dict, List, Optional

from pydantic import BaseModel, Field

from .tool import Tool


class Agent(BaseModel):
    """Represents an AI agent composed of tools and metadata."""

    name: str
    description: str
    version: str = "0.1.0"
    tools: List[Tool] = Field(default_factory=list)
    metadata: Dict[str, str] = Field(default_factory=dict)

    # ---------------------------------------------------------------------
    # Serialisation helpers
    # ---------------------------------------------------------------------
    def to_a2a(self) -> Dict:  # noqa: ANN401
        """Return A2A JSON spec representation."""

        from unifiedagentprotocol.export.to_a2a import agent_to_a2a  # local import to avoid cycle

        return agent_to_a2a(self)

    def to_mcp(self) -> Dict:  # noqa: ANN401
        """Return MCP template representation."""

        from unifiedagentprotocol.export.to_mcp import agent_to_mcp

        return agent_to_mcp(self)

    def to_openapi(self) -> Dict:  # noqa: ANN401
        """Return OpenAPI v3 spec for the agent's tools."""

        from unifiedagentprotocol.export.to_openapi import agent_to_openapi

        return agent_to_openapi(self)

    class Config:
        extra = "allow"
        schema_extra = {
            "example": {
                "name": "WeatherBot",
                "description": "Provides weather information and forecasts",
                "version": "1.0.0",
            }
        }
