#!/bin/bash

# LuckyChit - Production Rebuild Script
# Use this when you have compilation errors on production

echo "🔧 Rebuilding Flutter App (Production Server)"
echo "=============================================="
echo ""

# Clean everything
echo "🧹 Step 1/5: Cleaning build cache..."
flutter clean
rm -rf .dart_tool
rm -rf build

echo ""
echo "📦 Step 2/5: Getting dependencies..."
flutter pub get

echo ""
echo "🔍 Step 3/5: Checking Flutter doctor..."
flutter doctor

echo ""
echo "🔨 Step 4/5: Building for web (release mode)..."
flutter build web --release --verbose

if [ $? -eq 0 ]; then
    echo ""
    echo "✅ Step 5/5: Build successful!"
    echo ""
    echo "📁 Output: build/web/"
    echo ""
    echo "📤 Next steps:"
    echo "   1. Copy to web directory:"
    echo "      sudo cp -r build/web/* /var/www/luckychit/"
    echo ""
    echo "   2. Or restart PM2 if using PM2:"
    echo "      pm2 restart luckychit-web"
    echo ""
else
    echo ""
    echo "❌ Build failed!"
    echo ""
    echo "🔍 Troubleshooting:"
    echo "   1. Check Flutter version: flutter --version"
    echo "   2. Check Dart version: dart --version"
    echo "   3. Try upgrading Flutter: flutter upgrade"
    echo "   4. Check error messages above"
    echo ""
    exit 1
fi

