from pydantic_settings import BaseSettings, SettingsConfigDict


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

    db_url: str
    data_dir: str = "./data/govcrawler"
    user_agent: str = "GovCrawlerBot/1.0 (contact: xxx@example.com)"
    # Cookie pool (FETCH-04). Empty/unset → in-memory fallback (dev/tests).
    valkey_url: str = ""
    # Cookie TTL per design doc §4.2 (4 hours).
    cookie_ttl_s: int = 4 * 3600
    # Alerting (OBS-03). Empty URL → alerting disabled.
    alert_webhook_url: str = ""
    alert_provider: str = "feishu"   # "feishu" | "wechat"


def get_settings() -> Settings:
    return Settings()  # 每次读一次；本阶段量小不做 lru_cache
