#!/usr/bin/env bash
# Sync the OpenAPI contract from the alqove-api repo into this repo.
#
# Run this whenever the contract changes upstream, then commit the result
# alongside any code that depends on the new shape.
#
# Override the source location with ALQOVE_API_DIR if alqove-api lives somewhere else.
set -euo pipefail

src="${ALQOVE_API_DIR:-$HOME/projects/alqove-api}/api/contracts/openapi.yaml"
dest="$(cd "$(dirname "$0")/.." && pwd)/contracts/openapi.yaml"

if [[ ! -f "$src" ]]; then
  echo "error: source not found at $src" >&2
  echo "       set ALQOVE_API_DIR to the alqove-api checkout if it lives elsewhere" >&2
  exit 1
fi

cp "$src" "$dest"
echo "synced $src → $dest"
echo "regenerate types: npm run build:types"
