#!/usr/bin/env bash
# ================================================================
# PLANTPLAN - Umgebungsvariablen Setup
# ================================================================
# Dieses Skript muss gesourct werden: source bin/setenv.sh
# ================================================================

echo "Setting up environment variables for PLANTPLAN ..."

# Basis-Projektpfad (übergeordnetes Verzeichnis von bin/)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export PROJECT="$(cd "$SCRIPT_DIR/.." && pwd)"

# Pfade für verschiedene Komponenten
export PV_BIN="$PROJECT/bin"
export PV_LIB="$PROJECT/lib"
export PV_DATA="$PROJECT/data"
export PV_CFG="$PROJECT/cfg"
export PV_LOG="$PROJECT/log"
export PV_TESTS="$PROJECT/tests"
export PV_RESULTS="$PROJECT/results"
export PV_CLIENT="$PROJECT/client"
export PV_SERVER="$PROJECT/server"
export PV_EXAMPLES="$PROJECT/examples"

# Netzwerk-Konfiguration
export PV_SERVER_HOST="127.0.0.1"
export PV_SERVER_PORT="8000"
export PV_CLIENT_PORT="5173"
export PV_SERVER_URL="http://$PV_SERVER_HOST:$PV_SERVER_PORT"
export PV_CLIENT_URL="http://localhost:$PV_CLIENT_PORT"

# Python-Pfad erweitern (nur wenn noch nicht vorhanden)
if [[ ":$PYTHONPATH:" != *":$PV_LIB:"* ]]; then
    export PYTHONPATH="$PV_LIB:$PYTHONPATH"
fi

# Ordner erstellen falls sie nicht existieren
mkdir -p "$PV_BIN" "$PV_CFG" "$PV_LIB" "$PV_DATA" "$PV_LOG" "$PV_RESULTS" "$PV_EXAMPLES"

echo ""
echo "================================================================"
echo "PLANTPLAN ENVIRONMENT SETUP COMPLETE"
echo "================================================================"
echo "PROJECT         = $PROJECT"
echo "PV_BIN          = $PV_BIN"
echo "PV_CFG          = $PV_CFG"
echo "PV_LIB          = $PV_LIB"
echo "PV_DATA         = $PV_DATA"
echo "PV_RESULTS      = $PV_RESULTS"
echo "PV_LOG          = $PV_LOG"
echo "PV_CLIENT       = $PV_CLIENT"
echo "PV_SERVER       = $PV_SERVER"
echo "PV_EXAMPLES     = $PV_EXAMPLES"
echo "PV_SERVER_URL   = $PV_SERVER_URL"
echo "PV_CLIENT_URL   = $PV_CLIENT_URL"
echo "PYTHONPATH      = $PYTHONPATH"
echo "================================================================"
echo ""
