#!/bin/bash
# Bootstrap script to install pre-commit and set up git hooks
set -e

if ! command -v pre-commit >/dev/null 2>&1; then
    if ! command -v pip3 >/dev/null 2>&1; then
        echo "pre-commit not found and pip3 is unavailable."
        echo "Install pre-commit with your package manager first."
        echo "On Ubuntu/Debian: sudo apt-get install -y pre-commit"
        exit 1
    fi

    echo "pre-commit not found, installing via pip..."
    if ! pip3 install pre-commit; then
        echo "pip3 could not install pre-commit."
        echo "If this system uses an externally managed Python environment,"
        echo "install the distro package instead."
        echo "On Ubuntu/Debian: sudo apt-get install -y pre-commit"
        exit 1
    fi
else
    echo "pre-commit already installed."
fi

pre-commit install

echo "pre-commit hooks installed!"
