#!/bin/bash

set -e

echo "Running pre-commit checks..."

# Get list of staged Python files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$' || true)

if [ -n "$STAGED_FILES" ]; then
    echo "Formatting staged Python files..."

    # Run ruff formatter and linter with auto-fix on staged files
    uv run ruff format $STAGED_FILES
    uv run ruff check --fix $STAGED_FILES

    # Re-add formatted files to staging
    git add $STAGED_FILES
fi

echo "Running linters..."
make lint

echo "Running type checker..."
make type-check

echo "Running tests..."
make test

echo "All pre-commit checks passed!"
