@echo off
REM ============================================================================
REM MHA Flow - Windows Setup Script
REM ============================================================================

echo ======================================================================
echo MHA Flow v3.0 - Quick Setup for Windows
echo ======================================================================
echo.

REM Check if Python is installed
python --version >nul 2>&1
if %errorlevel% neq 0 (
    echo [ERROR] Python is not installed or not in PATH
    echo Please install Python 3.8+ from https://www.python.org/
    pause
    exit /b 1
)

echo [1/5] Python found
python --version

echo.
echo [2/5] Creating .env configuration file...
if not exist .env (
    copy .env.example .env
    echo [OK] .env file created - Please edit it with your settings
    echo      Especially set DATABASE_URL for production
) else (
    echo [INFO] .env already exists - skipping
)

echo.
echo [3/5] Installing Python dependencies...
pip install -r requirements.txt
if %errorlevel% neq 0 (
    echo [ERROR] Failed to install dependencies
    pause
    exit /b 1
)
echo [OK] Dependencies installed

echo.
echo [4/5] Initializing database...
set /p init_db="Initialize database now? (y/n): "
if /i "%init_db%"=="y" (
    python init_db.py full
    if %errorlevel% neq 0 (
        echo [ERROR] Database initialization failed
        pause
        exit /b 1
    )
    echo [OK] Database initialized
) else (
    echo [SKIP] Database initialization skipped
    echo       Run later with: python init_db.py full
)

echo.
echo [5/5] Setup complete!
echo.
echo ======================================================================
echo Next Steps:
echo ======================================================================
echo.
echo 1. Edit .env file with your configuration:
echo    - Set DATABASE_URL for cloud database (PostgreSQL/MySQL)
echo    - Or keep SQLite for local development
echo    - Set SECRET_KEY for production
echo    - Optionally set GITHUB_TOKEN for custom algorithm submissions
echo.
echo 2. Start the server:
echo    python start_server.py
echo    OR
echo    python -m mha_toolbox ui
echo.
echo 3. Access the web interface:
echo    http://localhost:5000
echo.
echo 4. Read documentation:
echo    README.md           - Main documentation
echo    DEPLOYMENT.md       - Deployment guide
echo    .env.example        - Configuration options
echo.
echo ======================================================================
echo.
pause
