"""Pydantic settings for the terminal client."""

from __future__ import annotations

from pathlib import Path

from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    """Configuration loaded from environment / .env file."""

    model_config = SettingsConfigDict(
        env_prefix="NAVI_CODE_",
        env_file=".env",
        env_file_encoding="utf-8",
        extra="ignore",
    )

    base_url: str = "http://localhost:8000"
    ws_url: str | None = None
    state_dir: Path = Path.home() / ".navi_code"
    default_profile_id: str = "navi_code"
    show_thinking: bool = False
    show_events: bool = True

    def websocket_url(self, session_id: str) -> str:
        """Build WebSocket URL for a session."""
        base = (self.ws_url or self.base_url).rstrip("/")
        if base.startswith("http://"):
            base = base.replace("http://", "ws://", 1)
        elif base.startswith("https://"):
            base = base.replace("https://", "wss://", 1)
        return f"{base}/ws/sessions/{session_id}"


settings = Settings()
