"""Server connection configuration model.

Provides :class:`ServerConnectionConfig`, a validated Pydantic model for
server connection parameters.  In the current stub implementation the model
is used by the CLI ``connect`` command and ``info`` output but no actual
network calls are made.
"""

from __future__ import annotations

from pydantic import BaseModel, ConfigDict, field_validator


class ServerConnectionConfig(BaseModel):
    """Validated configuration for connecting to a CleverAgents server.

    Attributes:
        server_url: Base URL of the server (must start with ``http://`` or
            ``https://``).
        namespace: Namespace on the server (defaults to ``"default"``).
        auth_token_ref: Optional reference to an authentication token
            (e.g. environment variable name or secret store key).
        tls_verify: Whether to verify TLS certificates (defaults to
            ``True``).
    """

    model_config = ConfigDict(frozen=True, strict=False)

    server_url: str
    namespace: str = "default"
    auth_token_ref: str | None = None
    tls_verify: bool = True

    @field_validator("server_url")
    @classmethod
    def _validate_server_url(cls, value: str) -> str:
        if not value or not value.strip():
            raise ValueError("server_url must not be empty")
        stripped = value.strip()
        if not stripped.startswith(("http://", "https://")):
            raise ValueError("server_url must start with http:// or https://")
        return stripped

    @field_validator("namespace")
    @classmethod
    def _validate_namespace(cls, value: str) -> str:
        if not value or not value.strip():
            raise ValueError("namespace must not be empty")
        return value.strip()


__all__ = [
    "ServerConnectionConfig",
]
