#!/usr/bin/env bash
# Regenerate src/generated/ from spec/openapi.json, then format it.
# Run from packages/rust. Requires python3 and a Rust toolchain (for cargo fmt).
set -euo pipefail

cd "$(dirname "$0")/.."

SPEC="../../spec/openapi.json"
OUT="src/generated"

if [[ ! -f "$SPEC" ]]; then
  echo "spec not found: $SPEC" >&2
  exit 1
fi

PY=python3
command -v "$PY" >/dev/null 2>&1 || PY=python

mkdir -p "$OUT"
"$PY" scripts/codegen.py "$SPEC" "$OUT"
cargo fmt
echo "Generated $OUT"
