"""全局配置 — 从环境变量读取"""
import os

# Telegram
TG_BOT_TOKEN = os.getenv("TG_BOT_TOKEN", "")
TG_CHAT_ID = int(os.getenv("TG_CHAT_ID", "0"))

# PostgreSQL
DATABASE_URL = os.getenv(
    "DATABASE_URL",
    "postgres://user:password@127.0.0.1:15432/tg-spam-guard",
)

# Ollama
OLLAMA_URL = os.getenv("OLLAMA_URL", "http://127.0.0.1:11434")
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen3:8b")

# Proxy
PROXY_URL = os.getenv("PROXY_URL", "http://192.168.123.10:11055")
TG_PROXY_URL = os.getenv("TG_PROXY_URL", PROXY_URL)
TG_PROXY_URLS = [x.strip() for x in os.getenv("TG_PROXY_URLS", TG_PROXY_URL).split(",") if x.strip()]

# Web
WEB_PORT = int(os.getenv("WEB_PORT", "8766"))
SITE_URL = os.getenv("SITE_URL", "https://ptools.fun")

# Harvest
HARVEST_SERVER_URL = os.getenv("HARVEST_SERVER_URL", "https://ptools.fun")

# Bot 行为
ADMIN_USER_IDS = {
    int(x.strip()) for x in os.getenv("ADMIN_USER_IDS", "5418812283").split(",") if x.strip().isdigit()
}
BAN_DURATION_MINUTES = int(os.getenv("BAN_DURATION_MINUTES", "2"))
AUTO_DELETE_SECONDS = int(os.getenv("AUTO_DELETE_SECONDS", "60"))

# 夜间模式
NIGHT_MODE_START = os.getenv("NIGHT_MODE_START", "23:00")
NIGHT_MODE_END = os.getenv("NIGHT_MODE_END", "08:00")

# 入群验证
VERIFY_TIMEOUT_SECONDS = int(os.getenv("VERIFY_TIMEOUT_SECONDS", "300"))
VERIFY_MAX_ATTEMPTS = int(os.getenv("VERIFY_MAX_ATTEMPTS", "3"))

# 新人限制
NEW_MEMBER_RESTRICT_MINUTES = int(os.getenv("NEW_MEMBER_RESTRICT_MINUTES", "10"))

# 防刷屏
RATE_LIMIT_MESSAGES = int(os.getenv("RATE_LIMIT_MESSAGES", "5"))
RATE_LIMIT_WINDOW = int(os.getenv("RATE_LIMIT_WINDOW", "30"))

# Web 管理认证
WEB_AUTH_ENABLED = os.getenv("WEB_AUTH_ENABLED", "true").lower() not in {"0", "false", "no"}
WEB_AUTH_USERNAME = os.getenv("WEB_AUTH_USERNAME", "admin")
WEB_AUTH_PASSWORD = os.getenv("WEB_AUTH_PASSWORD", "admin")
WEB_SESSION_SECRET = os.getenv("WEB_SESSION_SECRET", "tg-spam-guard-change-me")
WEB_TRUST_SAME_SUBNET = os.getenv("WEB_TRUST_SAME_SUBNET", "true").lower() not in {"0", "false", "no"}
