@echo off

REM ================================================================
REM PLANTPLAN - Umgebungsvariablen Setup
REM ================================================================

echo Setting up environment variables for PLANTPLAN ...

REM Basis-Projektpfad (aktueller Ordner)
set "PROJECT=%~dp0.."
if "%PROJECT:~-6%"=="bin\.." set "PROJECT=%PROJECT:~0,-6%"
if "%PROJECT:~-1%"=="\" set "PROJECT=%PROJECT:~0,-1%"

REM Pfade für verschiedene Komponenten
set "PV_BIN=%PROJECT%\bin"
set "PV_LIB=%PROJECT%\lib"
set "PV_DATA=%PROJECT%\data"
set "PV_CFG=%PROJECT%\cfg"
set "PV_LOG=%PROJECT%\log"
set "PV_TESTS=%PROJECT%\tests"
set "PV_RESULTS=%PROJECT%\results"
set "PV_EXAMPLES=%PROJECT%\examples"
set "PV_CLIENT=%PROJECT%\client"
set "PV_SERVER=%PROJECT%\server"

REM Netzwerk-Konfiguration
set "PV_SERVER_HOST=127.0.0.1"
set "PV_SERVER_PORT=8000"
set "PV_CLIENT_PORT=5173"
set "PV_SERVER_URL=http://%PV_SERVER_HOST%:%PV_SERVER_PORT%"
set "PV_CLIENT_URL=http://localhost:%PV_CLIENT_PORT%"

REM Python-Pfad erweitern (nur wenn noch nicht vorhanden)
echo %PYTHONPATH% | find /i "%PV_LIB%" >nul
if errorlevel 1 (
    set "PYTHONPATH=%PV_LIB%;%PYTHONPATH%"
)

REM Ordner erstellen falls sie nicht existieren
if not exist "%PV_BIN%" mkdir "%PV_BIN%"
if not exist "%PV_CFG%" mkdir "%PV_CFG%"
if not exist "%PV_LIB%" mkdir "%PV_LIB%"
if not exist "%PV_DATA%" mkdir "%PV_DATA%"
if not exist "%PV_LOG%" mkdir "%PV_LOG%"
if not exist "%PV_RESULTS%" mkdir "%PV_RESULTS%"
if not exist "%PV_EXAMPLES%" mkdir "%PV_EXAMPLES%"
if not exist "%PV_CLIENT%" mkdir "%PV_CLIENT%"
if not exist "%PV_SERVER%" mkdir "%PV_SERVER%"

REM Umgebungsvariablen anzeigen
REM echo.
REM echo ================================================================
REM echo PROJECT         = %PROJECT%
REM echo PV_BIN          = %PV_BIN%
REM echo PV_CFG          = %PV_CFG%
REM echo PV_LIB          = %PV_LIB%
REM echo PV_DATA         = %PV_DATA%
REM echo PV_RESULTS      = %PV_RESULTS%
REM echo PV_LOG          = %PV_LOG%
REM echo PV_EXAMPLES     = %PV_EXAMPLES%
REM echo PV_CLIENT       = %PV_CLIENT%
REM echo PV_SERVER       = %PV_SERVER%
REM echo PV_SERVER_URL   = %PV_SERVER_URL%
REM echo PV_CLIENT_URL   = %PV_CLIENT_URL%
REM echo PYTHONPATH      = %PYTHONPATH%
REM echo ================================================================
REM echo.

REM Optionally keep window open
if "%1"=="--keep-open" pause
