"""Configuration settings loaded from environment variables."""

import os
from dataclasses import dataclass, field
from pathlib import Path


def _package_data_dir() -> Path:
    """Path to bundled data directory (works installed or in dev)."""
    return Path(__file__).resolve().parent.parent / "data"


@dataclass
class Settings:
    db_path: str = field(default_factory=lambda: os.environ.get(
        "ARS25_DB_PATH", str(_package_data_dir() / "lancedb")
    ))
    csv_path: str = field(default_factory=lambda: os.environ.get(
        "ARS25_CSV_PATH", str(_package_data_dir() / "ars_25.csv")
    ))
    embedding_model: str = field(default_factory=lambda: os.environ.get(
        "ARS25_EMBEDDING_MODEL", "all-MiniLM-L6-v2"
    ))
    embedding_dim: int = 384
    table_name: str = "ars25_chunks"
    scrape_concurrency: int = field(default_factory=lambda: int(os.environ.get(
        "ARS25_SCRAPE_CONCURRENCY", "5"
    )))


_settings: Settings | None = None


def get_settings() -> Settings:
    global _settings
    if _settings is None:
        _settings = Settings()
    return _settings
