@echo off
REM ================================================================
REM HundM_Fortna - Umgebungsvariablen Setup
REM ================================================================

echo Setting up environment variables for HundM_Fortna ...

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

REM Pfade fuer die Komponenten
set "PV_BIN=%PROJECT%\bin"
set "PV_LIB=%PROJECT%\lib"
set "PV_CFG=%PROJECT%\cfg"
set "PV_DATA=%PROJECT%\data"
set "PV_DOC=%PROJECT%\doc"
set "PV_TESTS=%PROJECT%\tests"

REM PYTHONPATH um PV_LIB erweitern (nur wenn noch nicht enthalten)
if not defined PYTHONPATH (
    set "PYTHONPATH=%PV_LIB%"
) else (
    echo.%PYTHONPATH% | find /i "%PV_LIB%" >nul || set "PYTHONPATH=%PYTHONPATH%;%PV_LIB%"
)

REM Ueberladen von Umgebungsvariablen durch _setenv.bat
REM (z.B. PV_DATA auf einen Netzlaufwerk-Pfad umbiegen)
if exist "%~dp0_setenv.bat" (
    echo Lade lokale Umgebungseinstellungen aus _setenv.bat...
    call "%~dp0_setenv.bat"
)

REM Ordner erstellen falls sie nicht existieren
if not exist "%PV_BIN%" mkdir "%PV_BIN%"
if not exist "%PV_LIB%" mkdir "%PV_LIB%"
if not exist "%PV_CFG%" mkdir "%PV_CFG%"
if not exist "%PV_DATA%" mkdir "%PV_DATA%"
if not exist "%PV_TESTS%" mkdir "%PV_TESTS%"

REM Umgebungsvariablen anzeigen
echo.
echo ================================================================
echo PROJECT      = %PROJECT%
echo PV_BIN       = %PV_BIN%
echo PV_LIB       = %PV_LIB%
echo PV_CFG       = %PV_CFG%
echo PV_DATA      = %PV_DATA%
echo PV_LOG       = %PV_LOG%
echo PV_RESULTS   = %PV_RESULTS%
echo PV_EXAMPLES  = %PV_EXAMPLES%
echo PV_TESTS     = %PV_TESTS%
echo PYTHONPATH   = %PYTHONPATH%
echo ================================================================
echo.
