#!/bin/bash
# Deploy APK to connected Android device

set -e

echo "📱 Deploying to Android device..."
echo ""

# Check if device is connected
if ! adb devices | grep -q "device$"; then
    echo "❌ No Android device connected!"
    echo "Please connect a device or start an emulator."
    exit 1
fi

# Build type: debug or release (default: debug)
BUILD_TYPE="${1:-debug}"

if [ "$BUILD_TYPE" = "release" ]; then
    APK_PATH="src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk"
else
    APK_PATH="src-tauri/gen/android/app/build/outputs/apk/universal/debug/app-universal-debug.apk"
fi

# Check if APK exists
if [ ! -f "$APK_PATH" ]; then
    echo "❌ APK not found at: $APK_PATH"
    echo "Run './scripts/build-android.sh $BUILD_TYPE' first"
    exit 1
fi

echo "📦 Installing APK: $APK_PATH"
adb install -r "$APK_PATH"

echo ""
echo "✅ Deployment complete!"
echo "🚀 Launch the app on your device"
