# Tapir mobile app — Flutter (the app lives in tapir_app/).
#
#   just mobile apk      # build the release APK
#   just mobile run      # hot-reload on the connected Android device
#   just mobile install  # build + install the APK on the device
#   just mobile ci       # analyze + format-check + test
#
# Device is auto-detected via `adb` (first connected Android device); the run/
# install recipes fail with a clear message if none is attached.

set shell := ["bash", "-uc"]
# All recipes run inside the Flutter project.
set working-directory := 'tapir_app'

# Default: list recipes.
default:
    @just --list --unsorted

# Fetch Dart/Flutter dependencies.
deps:
    flutter pub get

# Build the release APK (build/app/outputs/flutter-apk/app-release.apk).
apk:
    flutter build apk --release

# Build the Android App Bundle (.aab) for the Play Store.
bundle:
    flutter build appbundle --release

# Static analysis.
analyze:
    flutter analyze

# Format Dart code in place.
fmt:
    dart format lib test integration_test

# Fail if any Dart code is unformatted (CI).
fmt-check:
    dart format --output=none --set-exit-if-changed lib test integration_test

# Unit and widget tests.
test:
    flutter test

# CI gate: analyze + format-check + test.
ci: analyze fmt-check test

# Regenerate launcher icons / native splash.
gen-icons: deps
    flutter pub run flutter_launcher_icons
gen-splash: deps
    flutter pub run flutter_native_splash:create

# List devices known to adb and flutter.
devices:
    #!/usr/bin/env bash
    adb devices -l
    echo "---"
    flutter devices

# Hot-reload on the first connected Android device (Ctrl-C to stop).
run:
    #!/usr/bin/env bash
    set -euo pipefail
    dev=$(adb devices | awk 'NR>1 && $2=="device"{print $1; exit}')
    [ -n "$dev" ] || { echo "No Android device connected (adb devices empty)."; exit 1; }
    echo "Using device: $dev"
    flutter run -d "$dev"

# Build the release APK and install it on the connected device.
install: apk
    #!/usr/bin/env bash
    set -euo pipefail
    dev=$(adb devices | awk 'NR>1 && $2=="device"{print $1; exit}')
    [ -n "$dev" ] || { echo "No Android device connected (adb devices empty)."; exit 1; }
    adb -s "$dev" install -r build/app/outputs/flutter-apk/app-release.apk

# Remove Flutter build artifacts.
clean:
    flutter clean
