from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
    model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")

    ollama_host: str = "http://localhost:11434"
    ollama_default_model: str = "gemma4:e2b-it-q8_0"
    ollama_num_ctx: int = 8192
    ollama_think: bool = True

    openai_api_key: str = ""
    anthropic_api_key: str = ""

    # Filesystem tool: comma-separated allowed root paths
    fs_allowed_paths: str = "*"

    # Terminal tool: "*" = allow all commands (recommended for local use)
    # or comma-separated list of allowed executables, e.g. "ls,cat,git"
    terminal_allowed_commands: str = "*"

    # SSH tool: path to JSON file with named connections
    ssh_hosts_file: str = "ssh_hosts.json"

    # Database
    db_path: str = "navi.db"

    log_level: str = "INFO"

    # Directory for user-defined tools (auto-discovered at startup)
    tools_dir: str = "tools"

    # Global personality prompt prepended to every agent's system prompt.
    # Override via NAVI_PERSONA env var or .env file.
    navi_persona: str = ""

    @property
    def fs_allowed_paths_list(self) -> list[str]:
        return [p.strip() for p in self.fs_allowed_paths.split(",") if p.strip()]

    @property
    def terminal_allowed_commands_list(self) -> list[str]:
        return [c.strip() for c in self.terminal_allowed_commands.split(",") if c.strip()]


settings = Settings()
