@echo off
chcp 65001 >nul
setlocal

cd /d "%~dp0..\madar_flutter"

if not exist "android\key.properties" (
    echo [خطأ] ملف android\key.properties غير موجود.
    echo انسخ key.properties.example واملأ كلمات المرور بعد create-android-keystore.bat
    exit /b 1
)

echo.
echo بناء MadarX للإنتاج — API: https://app.madarx.org/api
echo.

flutter pub get
flutter build appbundle --release --dart-define=API_BASE_URL=https://app.madarx.org/api

if errorlevel 1 exit /b 1

echo.
echo ============================================
echo   تم البناء بنجاح
echo ============================================
echo   ملف Play Store:
echo   build\app\outputs\bundle\release\app-release.aab
echo.
echo   لاختبار APK محلي:
echo   flutter build apk --release --dart-define=API_BASE_URL=https://app.madarx.org/api
echo.
pause
