@echo off
title Ghost Node — Setup
color 0B
echo.
echo  ==========================================
echo   GHOST NODE ^| Auction Sniper Setup
echo  ==========================================
echo.

:: ── Check Python ──────────────────────────────────────────────────────────────
echo [1/7] Checking Python installation...
python --version >nul 2>&1
if errorlevel 1 (
    echo.
    echo  ERROR: Python not found.
    echo  Download Python 3.10+ from https://python.org/downloads
    echo  Make sure to tick "Add Python to PATH" during install.
    echo.
    pause
    exit /b 1
)
python --version
echo  OK.
echo.

:: ── Create virtual environment ────────────────────────────────────────────────
echo [2/7] Creating virtual environment (.venv)...
if exist .venv (
    echo  Already exists — skipping.
) else (
    python -m venv .venv
    echo  Created.
)
echo.

:: ── Activate venv ─────────────────────────────────────────────────────────────
echo [3/7] Activating virtual environment...
call .venv\Scripts\activate.bat
if errorlevel 1 (
    echo  ERROR: Could not activate .venv. Try running as Administrator.
    pause
    exit /b 1
)
echo  Active.
echo.

:: ── Install Python dependencies ───────────────────────────────────────────────
echo [4/7] Installing Python packages (fastapi, playwright, sqlalchemy, httpx)...
pip install -r requirements.txt --quiet --disable-pip-version-check
if errorlevel 1 (
    echo  ERROR: pip install failed. Check your internet connection.
    pause
    exit /b 1
)
echo  Done.
echo.

:: ── Install Playwright browser ────────────────────────────────────────────────
echo [5/7] Installing Playwright Chromium browser...
python -m playwright install chromium
if errorlevel 1 (
    echo  WARNING: Playwright browser install failed.
    echo  Run manually: python -m playwright install chromium
)
echo.

:: ── Create required folders ───────────────────────────────────────────────────
echo [6/7] Creating required folders...
if not exist .browser_profiles mkdir .browser_profiles
if not exist backups mkdir backups
echo  .browser_profiles\  — for persistent login sessions
echo  backups\            — for database backups
echo.

:: ── Done ──────────────────────────────────────────────────────────────────────
echo [7/7] Setup complete.
echo.
echo  ==========================================
echo   READY TO LAUNCH
echo  ==========================================
echo.
echo  Start Ghost Node:
echo.
echo    python worker.py
echo.
echo  Then open your browser at:
echo.
echo    http://localhost:8000
echo.
echo  ── First-time setup steps ──────────────────
echo  1. Go to Settings tab
echo  2. Enter your Telegram Bot Token + Chat ID
echo  3. Click "Test Telegram" to verify
echo  4. Add target sites in the Sites tab
echo  5. The engine starts automatically
echo.
echo  ── Upgrading from another machine? ─────────
echo  1. Copy your sniper.db file to this folder
echo  2. Run python worker.py — data restored
echo.
pause
