#!/usr/bin/env bash
# ==============================================================================
# Pre-push Hook: Intercepts Git Tag pushes and validates CHANGELOG.md integrity
# ==============================================================================
set -euo pipefail

# Read standard input: <local_ref> <local_sha> <remote_ref> <remote_sha>
while read -r local_ref local_sha remote_ref remote_sha; do
    case "$remote_ref" in
        refs/tags/v*)
            TAG_NAME="${remote_ref#refs/tags/}"
            echo "🔍 Pre-push check: Validating release tag '$TAG_NAME' against CHANGELOG.md..."
            if ! python3 scripts/verify_changelog.py --tag "$TAG_NAME"; then
                echo "❌ Error: Tag '$TAG_NAME' failed CHANGELOG verification." >&2
                echo "   Update CHANGELOG.md before pushing this release tag." >&2
                exit 1
            fi
            ;;
        *)
            ;;
    esac
done

exit 0
