#!/usr/bin/env bash
set -euo pipefail

cd "$(dirname "$0")"

if ! command -v java >/dev/null 2>&1; then
  echo "Floro Uploader requires Java 17 or newer, but java was not found on PATH." >&2
  echo "Install Java 17+ or use a bundled-runtime download." >&2
  exit 1
fi

java_version="$(java -version 2>&1 | awk -F '"' '/version/ { print $2; exit }')"
java_major="$(printf '%s\n' "$java_version" | awk -F '[._]' '{ if ($1 == "1") print $2; else print $1 }')"

if [[ -z "$java_major" || "$java_major" -lt 17 ]]; then
  echo "Floro Uploader requires Java 17 or newer, but PATH is using Java ${java_version:-unknown}." >&2
  echo "Older Java versions are missing java.net.http and will crash during startup." >&2
  echo "Install Java 17+ or use a bundled-runtime download." >&2
  exit 1
fi

java -jar floro-uploader.jar "$@"
