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

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

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

# Pfade fuer 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_EXAMPLES="$PROJECT/examples"

# Base-Repo spezifische Pfade
export PV_EXT="$PROJECT/_ext"
export PV_TEMPLATES="$PROJECT/_templates"
export PV_ASSETS="$PROJECT/assets"
export PV_MODULES="$PROJECT/modules"
export PV_CHAPTERS="$PROJECT/chapters"
export PV_GLOSSARY="$PROJECT/glossary"
export PV_STYLES="$PROJECT/styles"
export PV_SCRIPTS="$PROJECT/scripts"

# 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"
mkdir -p "$PV_EXT" "$PV_TEMPLATES/latex" "$PV_TEMPLATES/common"
mkdir -p "$PV_ASSETS/shared/photos" "$PV_ASSETS/shared/drawings" "$PV_ASSETS/shared/symbols" "$PV_ASSETS/shared/diagrams"
mkdir -p "$PV_ASSETS/localized/de" "$PV_ASSETS/localized/en"
mkdir -p "$PV_MODULES" "$PV_CHAPTERS" "$PV_GLOSSARY" "$PV_STYLES" "$PV_SCRIPTS"

echo ""
echo "================================================================"
echo "DOCU_BUILD 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_EXAMPLES     = $PV_EXAMPLES"
echo "PV_EXT          = $PV_EXT"
echo "PV_TEMPLATES    = $PV_TEMPLATES"
echo "PV_ASSETS       = $PV_ASSETS"
echo "PV_MODULES      = $PV_MODULES"
echo "PV_CHAPTERS     = $PV_CHAPTERS"
echo "PV_GLOSSARY     = $PV_GLOSSARY"
echo "PV_STYLES       = $PV_STYLES"
echo "PV_SCRIPTS      = $PV_SCRIPTS"
echo "PYTHONPATH      = $PYTHONPATH"
echo "================================================================"
echo ""
