#!/usr/bin/env bash
# Pre-commit hook dispatcher.
# Installed via: git config core.hooksPath .config/hooks
set -euo pipefail

REPO_ROOT="$(git rev-parse --show-toplevel)"
ERRORS=0

run_check() {
    local script="$1"
    local label="$2"
    if [ -x "$REPO_ROOT/$script" ]; then
        if ! "$REPO_ROOT/$script"; then
            ERRORS=$((ERRORS + 1))
        fi
    else
        echo "pre-commit: WARNING — $label skipped ($script not found)"
    fi
}

# --- Add project-specific checks here ---
# run_check "tooling/check-something" "something validation"

if [ "$ERRORS" -gt 0 ]; then
    echo ""
    echo "pre-commit: $ERRORS check(s) failed. Commit aborted."
    exit 1
fi
