#!/usr/bin/env bash
# setup.sh — one-shot install + build for first-time setup.
#
# After running this:
#   1. cp gateway/.env.example gateway/.env.local && fill UPSTREAM_API_KEY
#   2. cp service/.env.example service/.env.local
#   3. cp frontend/.env.example frontend/.env.local
#   4. bash scripts/dev-all.sh
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${ROOT}"

echo "[setup] installing shared…"
( cd shared && npm install --no-audit --no-fund && npm run build )

echo "[setup] installing gateway…"
( cd gateway && npm install --no-audit --no-fund )

echo "[setup] installing service…"
( cd service && npm install --no-audit --no-fund )

echo "[setup] installing frontend…"
( cd frontend && npm install --no-audit --no-fund )

echo ""
echo "[setup] ✅ done."
echo ""
echo "Next:"
echo "  1. Copy each .env.example → .env.local and fill in values"
echo "     - gateway/.env.local needs UPSTREAM_API_KEY"
echo "     - service/.env.local + frontend/.env.local need a matching GATEWAY_TOKEN"
echo "  2. bash scripts/dev-all.sh"
