# direnv configuration for this project
# This file contains project defaults and is version-controlled
# For personal overrides, create .envrc.local (git-ignored)

# Activate virtual environment (if it exists)
# Run 'uv sync --all-extras --dev' to create the virtual environment
if [ -d .venv ]; then
  source .venv/bin/activate
else
  echo "⚠️  Virtual environment not found. Run: uv sync --all-extras --dev"
fi

# Tool caches point to tmp/. uv keeps its own default cache (~/.cache/uv), which
# every checkout, worktree and project shares through hard links; to move it, set
# an absolute UV_CACHE_DIR in .envrc.local on the same filesystem as the checkouts.
export RUFF_CACHE_DIR=${RUFF_CACHE_DIR:-"$(pwd)/tmp/.ruff_cache"}
export MYPY_CACHE_DIR=${MYPY_CACHE_DIR:-"$(pwd)/tmp/.mypy_cache"}
export COVERAGE_FILE=${COVERAGE_FILE:-"$(pwd)/tmp/.coverage"}
export PRE_COMMIT_HOME=${PRE_COMMIT_HOME:-"$(pwd)/tmp/.pre-commit"}

# Add local bin to PATH
export PATH="$PWD/.venv/bin:$PATH"

# Project-specific environment variables
# Uncomment and customize as needed:
# export DEBUG=${DEBUG:-false}
# export LOG_LEVEL=${LOG_LEVEL:-INFO}

# Load user-specific settings from .envrc.local (git-ignored)
# This is where you put personal overrides and credentials
if [ -f .envrc.local ]; then
  source_env .envrc.local
fi
watch_file .envrc.local

# Show loaded configuration
echo "🔧 Project environment loaded"
echo "   Python: $(python --version 2>&1)"
echo "   Caches: tmp/ (Ruff, Mypy, Coverage, Pre-commit); uv: ${UV_CACHE_DIR:-default ~/.cache/uv}"

# Helpful warnings
if [ ! -f .envrc.local ]; then
  echo "💡 Tip: Create .envrc.local for personal settings (API keys, debug flags, etc.)"
fi
