"""
Bot configuration module.

Environment variables:
  BOT_MODE: "test" or "prod" (default: test)
  TEST_BOT_TOKEN: Token for test bot
  PROD_BOT_TOKEN: Token for prod bot
  LAOZHANG_KEY: LaoZhang.ai API key
  NFS_BASE: Base path for file storage (default: /mnt/video)
  PROXY_HOST: SOCKS5 proxy host (default: PROXY_HOST)
  PROXY_PORT: SOCKS5 proxy port (default: 1080)
"""
import os
from pathlib import Path

# Bot mode: test or prod
BOT_MODE = os.environ.get("BOT_MODE", "test")

# Select token based on mode
if BOT_MODE == "prod":
    BOT_TOKEN = os.environ.get("PROD_BOT_TOKEN", "")
    CODE_DIR = Path.home() / "prod"
else:
    BOT_TOKEN = os.environ.get("TEST_BOT_TOKEN", "")
    CODE_DIR = Path.home() / "dev"

# Storage
NFS_BASE = Path(os.environ.get("NFS_BASE", "/mnt/video"))

# API keys
LAOZHANG_KEY = os.environ.get("LAOZHANG_KEY", "")

# Proxy settings for LaoZhang API
PROXY_HOST = os.environ.get("PROXY_HOST", "PROXY_HOST")
PROXY_PORT = int(os.environ.get("PROXY_PORT", "1080"))


def validate_config():
    """Check required configuration."""
    errors = []

    if not BOT_TOKEN:
        token_var = "PROD_BOT_TOKEN" if BOT_MODE == "prod" else "TEST_BOT_TOKEN"
        errors.append(f"{token_var} not set")

    if not LAOZHANG_KEY:
        errors.append("LAOZHANG_KEY not set")

    if not NFS_BASE.exists():
        errors.append(f"NFS_BASE path does not exist: {NFS_BASE}")

    return errors


if __name__ == "__main__":
    print(f"Bot mode: {BOT_MODE}")
    print(f"Code dir: {CODE_DIR}")
    print(f"NFS base: {NFS_BASE}")
    print(f"Proxy: {PROXY_HOST}:{PROXY_PORT}")

    errors = validate_config()
    if errors:
        print("\nConfiguration errors:")
        for e in errors:
            print(f"  - {e}")
    else:
        print("\nConfiguration OK")
