#!/usr/bin/env bash
# Convenience script for running Android UI tests locally via the Gradle
# Managed Device (pixel7Api34). Mirrors the iOS scripts/run_ui_tests.sh
# pattern but drives the Android instrumentation runner with one of the
# three test-filter profiles under:
#   composeApp/src/androidInstrumentedTest/testplans/
#
# Usage: ./scripts/run_ui_tests.sh [ci|parallel|full]
#   ci       - fast PR gating subset (seed + registration + tasks + cleanup)
#   parallel - all non-E2E suites (safe to run in parallel shards)
#   full     - every suite (default)
set -euo pipefail

profile="${1:-full}"
filter_file="composeApp/src/androidInstrumentedTest/testplans/${profile}.testfilter"

if [[ ! -f "$filter_file" ]]; then
    echo "Error: no test filter found at $filter_file" >&2
    echo "Valid profiles: ci | parallel | full" >&2
    exit 1
fi

# Flatten the file: strip comments/blank lines, comma-join the class names.
filter_arg="$(grep -v '^#' "$filter_file" | grep -v '^[[:space:]]*$' | tr '\n' ',' | sed 's/,$//')"

echo "Running Android UI tests (profile: $profile)"
echo "Filter: $filter_arg"

./gradlew :composeApp:pixel7Api34DebugAndroidTest \
    -Pandroid.testInstrumentationRunnerArguments.class="$filter_arg"
