#!/usr/bin/env bash
#
# Layer 2 build verification — typecheck + link the watch scheme.
#
# Regenerates ios/ from app.config.ts via `expo prebuild`, runs the
# bundler-pinned `pod install`, then `xcodebuild build` against the
# HalflightWatch scheme on a generic watchOS Simulator destination.
# Build only — no archive, no test runner, no simulator boot.
#
# Run from repo root: `npm run check:swift:build`.
#
# Cost: ~1-2 min on a warm machine (prebuild ~30 s, pod install ~30-60 s,
# xcodebuild ~30-60 s for an incremental rebuild).
#
set -euo pipefail

REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$REPO_ROOT"

echo "==> expo prebuild --platform ios --clean --no-install"
npx expo prebuild --platform ios --clean --no-install

echo "==> bundle exec pod install (in ios/)"
( cd ios && bundle exec pod install )

echo "==> xcodebuild build -scheme HalflightWatch"
xcodebuild build \
    -workspace ios/Halflight.xcworkspace \
    -scheme HalflightWatch \
    -destination 'generic/platform=watchOS Simulator' \
    -configuration Debug \
    -quiet

echo "==> watch build OK"
