#!/usr/bin/env bash
# Ensure gradle/wrapper/* exists (often missing when .gitignore hid gradle/ or after git clean).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
JAR="$ROOT/gradle/wrapper/gradle-wrapper.jar"
PROPS="$ROOT/gradle/wrapper/gradle-wrapper.properties"

if [[ -f "$JAR" && -f "$PROPS" ]]; then
  exit 0
fi

echo "ERROR: Gradle wrapper missing at gradle/wrapper/" >&2
echo "  expected: gradle-wrapper.jar + gradle-wrapper.properties" >&2
echo "  fix: cd \"$ROOT\" && gradle wrapper --gradle-version 8.9" >&2
echo "  note: .gitignore must NOT ignore gradle/wrapper/ (see repo .gitignore)" >&2
exit 1
