#!/usr/bin/env bash
#
# verify_snapshots.sh — verify every parity-gallery golden matches the
# current code. Use as a pre-commit / CI gate.
#
# Exits non-zero if either platform's gallery drifts from its committed
# baseline. Diff artifacts land under each platform's usual report dir:
#   Android:  composeApp/build/outputs/roborazzi/
#   iOS:      ~/Library/Developer/Xcode/DerivedData/.../HoneyDueTests/
#
# Usage
# -----
#   ./scripts/verify_snapshots.sh               # both platforms
#   ./scripts/verify_snapshots.sh --ios-only
#   ./scripts/verify_snapshots.sh --android-only
#
set -euo pipefail

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

platform="both"
for arg in "$@"; do
    case "$arg" in
        --ios-only)     platform="ios" ;;
        --android-only) platform="android" ;;
        -h|--help)
            sed -n '3,14p' "$0"
            exit 0
            ;;
        *)
            echo "usage: $0 [--ios-only|--android-only]" >&2
            exit 1
            ;;
    esac
done

# ---------- Android ----------
if [ "$platform" = "both" ] || [ "$platform" = "android" ]; then
    echo "==> Verifying Android goldens…"
    ./gradlew :composeApp:verifyRoborazziDebug
fi

# ---------- iOS ----------
if [ "$platform" = "both" ] || [ "$platform" = "ios" ]; then
    echo "==> Verifying iOS goldens…"
    (
        cd iosApp
        xcodebuild test \
            -project honeyDue.xcodeproj \
            -scheme HoneyDue \
            -destination "${IOS_SIM_DESTINATION:-platform=iOS Simulator,name=iPhone 17,OS=latest}" \
            -only-testing:HoneyDueTests/SnapshotGalleryTests \
            2>&1 | tail -30
    )
fi

echo "==> All snapshot checks passed."
