"""Pydantic schemas for MCP Client plugin."""

from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field


class McpServerConfigCreate(BaseModel):
    """Create a new MCP server configuration."""
    name: str = Field(..., min_length=1, max_length=200)
    url: str = Field(..., min_length=1, max_length=500)
    api_token: str | None = None
    enabled: bool = True
    description: str | None = None


class McpServerConfigUpdate(BaseModel):
    """Update an existing MCP server configuration."""
    name: str | None = Field(None, min_length=1, max_length=200)
    url: str | None = Field(None, min_length=1, max_length=500)
    api_token: str | None = None
    enabled: bool | None = None
    description: str | None = None


class McpServerConfigResponse(BaseModel):
    """Response model for MCP server configuration."""
    id: str
    name: str
    url: str
    api_token: str | None = None
    enabled: bool
    description: str | None = None
    last_connected_at: datetime | None = None
    created_by: str | None = None
    created_at: datetime | None = None
    updated_at: datetime | None = None


class McpServerToolInfo(BaseModel):
    """Tool info from an external MCP server."""
    name: str
    description: str = ""
    parameters: dict = Field(default_factory=dict)


class McpServerToolsResponse(BaseModel):
    """Response listing tools from an external MCP server."""
    server_name: str
    server_url: str
    tools: list[McpServerToolInfo]
    count: int


class McpServerExecuteRequest(BaseModel):
    """Request to execute a tool on an external MCP server."""
    tool_name: str
    arguments: dict = Field(default_factory=dict)


class McpServerExecuteResponse(BaseModel):
    """Response from executing a tool on an external MCP server."""
    server_name: str
    tool: str
    success: bool
    result: dict | str | None = None
    error: str | None = None
