@echo off
cd /d "%~dp0"

echo ========================================
echo Shopping App - Local Start
echo ========================================
echo.

set "USE_SSH_TUNNEL=1"
set "SSH_USER=opsadmin"
set "SSH_HOST=vertexf.top"
set "LOCAL_DB_PORT=1433"
set "REMOTE_DB_HOST=127.0.0.1"
set "REMOTE_DB_PORT=1433"

set "SHOPPING_FIREBASE_SERVICE_ACCOUNT=%~dp0firebase-service-account.json"

if not exist "venv\Scripts\python.exe" (
    echo venv was not found.
    echo Please double click setup_once.bat first.
    pause
    exit /b 1
)

if "%USE_SSH_TUNNEL%"=="1" (
    echo Starting database SSH tunnel...
    echo If it asks for password, enter your SSH password in the new window.
    start "Shopping DB Tunnel - Keep This Window Open" cmd /k ssh -N -L %LOCAL_DB_PORT%:%REMOTE_DB_HOST%:%REMOTE_DB_PORT% %SSH_USER%@%SSH_HOST%
    timeout /t 3 >nul
)

echo.
echo Starting website...
echo Open this URL:
echo http://127.0.0.1:5000
echo.

"venv\Scripts\python.exe" run_windows.py

pause