"""Configuration management for Crustdata MCP Server."""

import os
from dataclasses import dataclass
from typing import Literal

TransportType = Literal["stdio", "http"]


def get_token() -> str:
    """Get the Crustdata API token from environment.

    Returns:
        The API token, or empty string if not set.
    """
    return os.environ.get("CRUSTDATA_TOKEN", "")


@dataclass
class Config:
    """Configuration settings for the Crustdata MCP Server."""

    api_url: str = "https://api.crustdata.com"
    request_timeout: float = 30.0
    log_level: str = "INFO"

    # HTTP transport settings
    http_host: str = "127.0.0.1"
    http_port: int = 8000
    http_path: str = "/mcp"

    @classmethod
    def from_env(cls) -> "Config":
        """Create configuration from environment variables."""
        return cls(
            api_url=os.environ.get("CRUSTDATA_API_URL", cls.api_url),
            request_timeout=float(os.environ.get("CRUSTDATA_REQUEST_TIMEOUT", cls.request_timeout)),
            log_level=os.environ.get("CRUSTDATA_LOG_LEVEL", cls.log_level),
            http_host=os.environ.get("CRUSTDATA_HTTP_HOST", cls.http_host),
            http_port=int(os.environ.get("CRUSTDATA_HTTP_PORT", cls.http_port)),
            http_path=os.environ.get("CRUSTDATA_HTTP_PATH", cls.http_path),
        )


# Global configuration instance
config = Config.from_env()
