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

SHUFFLE_WEBHOOK_URL="${SHUFFLE_WEBHOOK_URL:-}"
INTEGRATOR_URL="${INTEGRATOR_URL:-http://localhost:8088}"
INTERNAL_KEY="${INTERNAL_KEY:-}"

if [[ -z "${SHUFFLE_WEBHOOK_URL}" ]]; then
  echo "error: SHUFFLE_WEBHOOK_URL is required"
  echo "example:"
  echo "  SHUFFLE_WEBHOOK_URL='http://localhost:3001/api/v1/hooks/webhook_...' \\"
  echo "  bash soc-integrator/examples/send_to_shuffle_webhook.sh"
  exit 1
fi

curl -sS -X POST "${SHUFFLE_WEBHOOK_URL}" \
  -H "Content-Type: application/json" \
  -d "{
    \"event_id\": \"soc-integrator-test-$(date +%s)\",
    \"source\": \"soc-integrator\",
    \"severity\": \"high\",
    \"title\": \"Suspicious VPN login outside Thailand\",
    \"description\": \"Detected by soc-integrator test script\",
    \"integrator_url\": \"${INTEGRATOR_URL}\",
    \"internal_key\": \"${INTERNAL_KEY}\"
  }"

echo
echo "sent webhook payload to Shuffle"
