#!/bin/bash

echo "🔄 Watching for changes and auto-rebuilding..."
echo "📱 Device: $(adb devices | grep device | head -1)"
echo ""

# Function to build and install
build_and_install() {
    echo "🔨 Building and installing..."
    cd /Users/ruslanmakhmatov/Desktop/Work/rosette-app/rosetta-android
    ./gradlew installDebug --quiet
    if [ $? -eq 0 ]; then
        echo "✅ Successfully installed at $(date '+%H:%M:%S')"
    else
        echo "❌ Build failed at $(date '+%H:%M:%S')"
    fi
    echo ""
}

# Watch for changes in Kotlin files
fswatch -o app/src/main/java/com/rosetta/messenger/**/*.kt | while read; do
    build_and_install
done
