@echo off
echo ========================================
echo Deploying Backend Fixes to Production
echo ========================================
echo.

REM Check if we're in the right directory
if not exist backend (
    echo Error: Must run from project root directory
    exit /b 1
)

echo Step 1: Commit local changes
echo ================================
git add backend\src\middleware\auth.js
git add backend\src\controllers\phonePeController.js
git add backend\src\routes\phonepe.js
git add backend\src\server.js
git add luckychit\lib\core\services\api_service.dart

git status

echo.
set /p COMMIT="Commit these changes? (y/n): "
if /i "%COMMIT%"=="y" (
    git commit -m "Fix: Auth middleware logging, singleton ApiService, UPI settings endpoint"
    echo.
    echo SUCCESS: Changes committed
) else (
    echo.
    echo Skipping commit
    exit /b 0
)

echo.
echo Step 2: Push to repository
echo ================================
set /p PUSH="Push to origin? (y/n): "
if /i "%PUSH%"=="y" (
    git push origin main
    echo.
    echo SUCCESS: Pushed to repository
) else (
    echo.
    echo Skipping push
    exit /b 0
)

echo.
echo ========================================
echo Deploy to Production Server
echo ========================================
echo.
echo Now SSH into your server and run:
echo.
echo cd /home/luckychit/apps/chitfund
echo git pull origin main
echo pm2 restart all
echo pm2 logs luckychit --lines 50
echo.
echo ========================================
echo.
pause

