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

DASHBOARD_FILE="${1:-scripts/events/wazuh-fortigate-sim-dashboard.ndjson}"
WAZUH_DASHBOARD_URL="${WAZUH_DASHBOARD_URL:-https://localhost}"
WAZUH_DASHBOARD_USER="${WAZUH_DASHBOARD_USER:-admin}"
WAZUH_DASHBOARD_PASS="${WAZUH_DASHBOARD_PASS:-SecretPassword}"
OVERWRITE="${OVERWRITE:-true}"

if [[ ! -f "${DASHBOARD_FILE}" ]]; then
  echo "error: dashboard file not found: ${DASHBOARD_FILE}" >&2
  exit 1
fi

endpoint="${WAZUH_DASHBOARD_URL%/}/api/saved_objects/_import?overwrite=${OVERWRITE}"

echo "Importing dashboard from ${DASHBOARD_FILE}"
echo "Target: ${endpoint}"

curl -sS -k -u "${WAZUH_DASHBOARD_USER}:${WAZUH_DASHBOARD_PASS}" \
  -H 'osd-xsrf: true' \
  -F "file=@${DASHBOARD_FILE}" \
  "${endpoint}"

echo

echo "Done. Open Wazuh Dashboard and search for: SOC FortiGate Simulation Overview"
