#!/usr/bin/env bash
# Fast gate run by agents and humans before every review.
# Prints the toolchain, runs the package tests, then builds the app for the simulator without signing.
set -euo pipefail
cd "$(dirname "$0")/.."

echo "== Toolchain"
swift --version
xcodebuild -version

echo "== Resolve packages"
swift package resolve

echo "== Package tests (macOS host)"
swift test

if command -v xcodegen >/dev/null 2>&1; then
  echo "== Generate Xcode project"
  xcodegen generate
  echo "== Unsigned simulator build"
  xcodebuild build \
    -project Trailhead.xcodeproj \
    -scheme Trailhead \
    -destination 'generic/platform=iOS Simulator' \
    -derivedDataPath .build/DerivedData \
    CODE_SIGNING_ALLOWED=NO
else
  echo "xcodegen is not installed; skipping the app build. Install it with: brew install xcodegen" >&2
  exit 1
fi

echo "== Whitespace check"
git diff --check

echo "verify-fast: OK"
