#!/usr/bin/env bash
# Pre-push hook: check formatting and hlint before pushing.
# Installed by: scripts/install-hooks
set -euo pipefail

PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"

echo "--- Checking formatting with fourmolu..."
if ! "$PROJECT_DIR/hs" fourmolu --mode check app/ src/ test/; then
    echo ""
    echo "ERROR: Formatting check failed. Run './scripts/build' to auto-format."
    echo "       (fourmolu --mode inplace app/ src/ test/)"
    exit 1
fi
echo "OK"

echo "--- Linting with hlint..."
if ! "$PROJECT_DIR/hs" hlint app/ src/ test/; then
    echo ""
    echo "ERROR: Hlint found warnings. Fix them before pushing."
    exit 1
fi
echo "OK"
