#!/bin/bash

echo "🚀 Deploying Backend Fixes to Production"
echo "========================================"
echo ""

# Check if we're in the right directory
if [ ! -d "backend" ]; then
    echo "❌ Error: Must run from project root directory"
    exit 1
fi

echo "📦 Step 1: Commit local changes"
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 ""
read -p "Commit these changes? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
    git commit -m "Fix: Auth middleware logging, singleton ApiService, UPI settings endpoint"
    echo "✅ Changes committed"
else
    echo "⚠️ Skipping commit"
fi

echo ""
echo "📤 Step 2: Push to repository"
read -p "Push to origin? (y/n) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]
then
    git push origin main
    echo "✅ Pushed to repository"
else
    echo "⚠️ Skipping push"
    exit 0
fi

echo ""
echo "🔧 Step 3: Deploy to production server"
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 "✅ Deployment instructions complete!"

