#!/usr/bin/env bash
set -euo pipefail
BASE_URL="${BASE_URL:-http://localhost:3000}"
API_KEY="${APP_API_KEY:-change-me}"
BOOKING_NUMBER="${BOOKING_NUMBER:-SD-2026-002}"

echo "[1/4] Health"
curl --fail --silent --show-error "$BASE_URL/api/v1/health"
echo

echo "[2/4] Unauthorized request must fail"
if curl --fail --silent --show-error "$BASE_URL/api/v1/bookings?from=2026-06-08&to=2026-06-28" >/dev/null 2>&1; then
  echo "Expected HTTP 401 but request succeeded" >&2
  exit 1
fi

echo "[3/4] Authenticated grouped list"
curl --fail --silent --show-error \
  -H "Authorization: Bearer $API_KEY" \
  "$BASE_URL/api/v1/bookings?from=2026-06-08&to=2026-06-28"
echo

echo "[4/4] Authenticated booking details"
curl --fail --silent --show-error \
  -H "Authorization: Bearer $API_KEY" \
  "$BASE_URL/api/v1/bookings/$BOOKING_NUMBER"
echo
