@echo off
echo ===================================================
echo      MindShift APK Builder (One-Click)
echo ===================================================
echo.

:: Check for Java
where java >nul 2>nul
if %errorlevel% neq 0 (
    echo [ERROR] Java is not installed or not in PATH.
    echo Please install Java (JDK 17 recommended) and try again.
    pause
    exit /b
)

:: Check for Android Home
if "%ANDROID_HOME%"=="" (
    echo [ERROR] ANDROID_HOME environment variable is not set.
    echo Please install Android Studio and set ANDROID_HOME to your SDK location.
    pause
    exit /b
)

echo [1/3] Installing dependencies...
call npm install
if %errorlevel% neq 0 (
    echo Failed to install dependencies.
    pause
    exit /b
)

echo [2/3] Syncing Capacitor...
call npx cap sync
if %errorlevel% neq 0 (
    echo Failed to sync Capacitor.
    pause
    exit /b
)

echo [3/3] Building APK (Debug Mode)...
cd android
call gradlew.bat assembleDebug
cd ..

echo.
echo ===================================================
if exist "android\app\build\outputs\apk\debug\app-debug.apk" (
    echo [SUCCESS] APK created successfully!
    echo Location: android\app\build\outputs\apk\debug\app-debug.apk
    explorer "android\app\build\outputs\apk\debug\"
) else (
    echo [ERROR] Build failed. Please check the logs above.
)
echo ===================================================
pause
