#!/bin/bash

# Force Cache Bust - Emergency cache clearing
# Run this on production server when cache is stubborn

echo "💥 FORCE CACHE BUST - LuckyChit"
echo "================================"
echo ""

cd /home/luckychit/apps/chitfund/luckychit

echo "🛑 Stopping frontend..."
pm2 stop luckychit-frontend
pm2 delete luckychit-frontend

echo ""
echo "🗑️  Removing build directory..."
rm -rf build

echo ""
echo "🔨 Building with new timestamp..."
BUILD_NUMBER=$(date +%Y%m%d%H%M%S)
flutter build web --release --web-renderer html --pwa-strategy=none --build-number=$BUILD_NUMBER

echo ""
echo "✅ Build complete with version: $BUILD_NUMBER"
echo ""
echo "▶️  Starting fresh PM2 process..."
pm2 serve /home/luckychit/apps/chitfund/luckychit/build/web 8080 --name luckychit-frontend --spa

echo ""
echo "💾 Saving PM2 configuration..."
pm2 save

echo ""
echo "✅ Done! Frontend restarted with fresh cache"
echo ""
echo "📋 IMPORTANT - Tell users to:"
echo "   1. Hard refresh: Ctrl + Shift + R (Windows) or Cmd + Shift + R (Mac)"
echo "   2. Or clear browser cache completely"
echo "   3. Or use Incognito/Private mode to test"
echo ""
echo "📊 PM2 Status:"
pm2 status

