#!/bin/bash
# Rebuild and deploy Health Bridge APK
set -e

cd /home/ubuntu/health-bridge/android-app

echo "Building..."
if ./gradlew assembleDebug --no-daemon 2>&1 | grep -q "BUILD SUCCESSFUL"; then
    cp app/build/outputs/apk/debug/app-debug.apk ../static/health-bridge.apk
    SIZE=$(ls -lh ../static/health-bridge.apk | awk '{print $5}')
    echo "✅ APK updated ($SIZE) → http://100.87.116.90:3007/download"
    sudo systemctl restart health-bridge
else
    echo "❌ BUILD FAILED"
    exit 1
fi
