@echo off
cd /d "%~dp0"

set PROJECT=dbx-main
set COMPOSE=docker compose -p %PROJECT% -f docker-compose.local.yml

if "%1"=="stop"    goto STOP
if "%1"=="logs"    goto LOGS
if "%1"=="ps"      goto PS
if "%1"=="restart" goto RESTART

:START
if not exist ".env.local" (
    echo.
    echo  [ERROR] .env.local not found.
    echo  Copy .env.local.example and fill in the values:
    echo.
    echo    copy .env.local.example .env.local
    echo.
    pause
    exit /b 1
)
echo.
echo  Starting DBX Main Page (local)...
echo.
%COMPOSE% up --build -d
if %errorlevel%==0 (
    echo.
    echo  [OK] Running at http://localhost:8080
    echo.
    echo  Logs   : run-local.bat logs
    echo  Stop   : run-local.bat stop
    echo.
)
pause
exit /b

:STOP
echo.
echo  Stopping container...
%COMPOSE% down
echo.
pause
exit /b

:LOGS
%COMPOSE% logs -f
exit /b

:PS
echo.
%COMPOSE% ps
echo.
pause
exit /b

:RESTART
echo.
echo  Restarting...
%COMPOSE% restart
echo.
pause
exit /b