"""Enterprise configuration — environment-based config with defaults.

Reads configuration from environment variables with sensible defaults.
Stdlib-only.
"""

from __future__ import annotations

import os
from dataclasses import dataclass


@dataclass(frozen=True)
class EnterpriseConfig:
    """Configuration for enterprise deployment."""

    # Server
    host: str = "0.0.0.0"
    port: int = 8741
    workers: int = 1

    # Security
    cors_origins: str = "*"
    auth_enabled: bool = False

    # Observability
    log_level: str = "INFO"
    metrics_enabled: bool = False
    health_path: str = "/health"
    readiness_path: str = "/ready"

    # Data
    data_dir: str = "data"
    plugin_dir: str = "plugins"

    @classmethod
    def from_env(cls) -> EnterpriseConfig:
        """Load configuration from environment variables."""
        return cls(
            host=os.environ.get("ORXAQ_HOST", "0.0.0.0"),
            port=int(os.environ.get("ORXAQ_PORT", "8741")),
            workers=int(os.environ.get("ORXAQ_WORKERS", "1")),
            cors_origins=os.environ.get("ORXAQ_CORS_ORIGINS", "*"),
            auth_enabled=os.environ.get("ORXAQ_AUTH_ENABLED", "").lower() == "true",
            log_level=os.environ.get("ORXAQ_LOG_LEVEL", "INFO"),
            metrics_enabled=os.environ.get("ORXAQ_METRICS_ENABLED", "").lower() == "true",
            health_path=os.environ.get("ORXAQ_HEALTH_PATH", "/health"),
            readiness_path=os.environ.get("ORXAQ_READINESS_PATH", "/ready"),
            data_dir=os.environ.get("ORXAQ_DATA_DIR", "data"),
            plugin_dir=os.environ.get("ORXAQ_PLUGIN_DIR", "plugins"),
        )

    def to_dict(self) -> dict:
        return {
            "host": self.host,
            "port": self.port,
            "workers": self.workers,
            "cors_origins": self.cors_origins,
            "auth_enabled": self.auth_enabled,
            "log_level": self.log_level,
            "metrics_enabled": self.metrics_enabled,
            "health_path": self.health_path,
            "readiness_path": self.readiness_path,
            "data_dir": self.data_dir,
            "plugin_dir": self.plugin_dir,
        }
