#!/bin/sh

echo "🔍 Running pre-commit checks..."

# Get staged files (added, copied, modified)
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)

if [ -n "$STAGED_FILES" ]; then
  echo "📏 Checking file sizes..."
  node .husky/scripts/check-file-size.js $STAGED_FILES
  if [ $? -ne 0 ]; then
    exit 1
  fi
fi

# Run tests — only failing tests are printed to keep output focused
echo "🧪 Running tests..."
bash .husky/scripts/run-tests.sh
if [ $? -ne 0 ]; then
  exit 1
fi

# Generate project structure
echo "🗺️ Updating project structure..."
node .husky/scripts/generate-project-tree.js
node .husky/scripts/generate-dependency-graph.js
if [ $? -ne 0 ]; then
  exit 1
fi

# Auto-add the generated project structure to the commit
git add docs/project-structure.txt

echo "✅ All pre-commit checks passed!"
