from app.config import BOT_TOKEN, ENGINE_BIN
from database.db import init_db, stats
import subprocess, shutil
init_db()
if not BOT_TOKEN:
    raise SystemExit("BOT_TOKEN is missing")
bin_path = shutil.which(ENGINE_BIN) if "/" not in ENGINE_BIN else ENGINE_BIN
if not bin_path:
    raise SystemExit("Manga Downloader binary not found: " + ENGINE_BIN)
p = subprocess.run([bin_path, "--help"], capture_output=True, text=True, timeout=15)
if p.returncode != 0:
    raise SystemExit("Manga Downloader --help failed: " + (p.stderr or p.stdout)[-1000:])
print("OK: configuration, database and Manga Downloader CLI")
print(stats())
