#!/usr/bin/env bash
# Download Swiss Ephemeris data files into ./ephe (one-time, ~30 MB).
# Source: https://www.astro.com/ftp/swisseph/ephe/

set -euo pipefail

EPHE_DIR="$(dirname "$0")/../ephe"
mkdir -p "$EPHE_DIR"
cd "$EPHE_DIR"

BASE="https://github.com/aloistr/swisseph/raw/master/ephe"

# Cover modern + recent past range (1800–2399).
files=(
  "sepl_18.se1"   # planets 1800-2399
  "semo_18.se1"   # moon 1800-2399
  "seas_18.se1"   # asteroids 1800-2399
  "seplm54.se1"   # planets BCE
  "semom54.se1"   # moon BCE
  "fixstars.cat"
  "seasnam.txt"
  "seleapsec.txt"
)

for f in "${files[@]}"; do
  if [[ -f "$f" ]]; then
    echo "[skip] $f exists"
    continue
  fi
  echo "[get]  $f"
  if ! curl -fsSL "$BASE/$f" -o "$f"; then
    echo "[warn] $f not available — skipping (optional)"
    rm -f "$f"
  fi
done

echo "Done. Files in: $EPHE_DIR"
