#!/bin/bash

# Cleanup Old Documentation and Scripts
# Run this to remove redundant files after consolidation

echo "🧹 Cleaning up old documentation and scripts..."
echo ""

# Backup before deletion
BACKUP_DIR="old_docs_backup_$(date +%Y%m%d_%H%M%S)"
mkdir -p "$BACKUP_DIR"

echo "📦 Creating backup in: $BACKUP_DIR"

# List of files to remove
OLD_DOCS=(
    "ACTUAL_PRODUCTION_SETUP.md"
    "ARCHITECTURE_OVERVIEW.md"
    "CACHE_BUSTING_GUIDE.md"
    "CACHE_FIX_SUMMARY.md"
    "COMPLETE_FEATURES_DELIVERED.md"
    "COMPLETE_IMPLEMENTATION_SUMMARY.md"
    "CREATE_GROUP_IMPROVEMENTS.md"
    "DEPLOYMENT_MASTER_GUIDE.md"
    "DEPLOYMENT_README.md"
    "DEPLOYMENT_TROUBLESHOOTING.md"
    "EVERYTHING_DELIVERED.md"
    "FINAL_SETUP_GUIDE.md"
    "FIX_502_ERROR.md"
    "FIX_CACHE_NOW.md"
    "FIX_NOW_SERVICE_WORKER.md"
    "FIX_SERVICE_WORKER_CACHE.md"
    "FLUTTER_DEPLOYMENT_GUIDE.md"
    "LuckyChit_Development_Plan_Revised.md"
    "LuckyChit_Development_Plan.md"
    "NGINX_PROXY_CACHE_FIX.md"
    "PM2_QUICK_START.md"
    "PRODUCTION_DIFFERENCES.md"
    "PRODUCTION_UPDATE_GUIDE.md"
    "Project_Implementation_Plan.md"
    "PROXMOX_DEPLOYMENT_GUIDE.md"
    "QUICK_DEPLOY.md"
    "README_DEPLOYMENT.md"
    "README_NEW_FEATURES.md"
    "SIGNUP_FEATURE_IMPLEMENTATION.md"
    "SIGNUP_NAVIGATION_UPDATE.md"
    "SIGNUP_QUICK_START.md"
    "START_HERE.md"
    "Technical_Architecture.md"
    "Technical_Implementation_Guide_Revised.md"
    "TRADITIONAL_CHIT_FUND_MATHEMATICS.md"
    "UI_UX_Design_Guide.md"
    "CHEATSHEET.txt"
    "Untitled-1.txt"
)

OLD_SCRIPTS=(
    "backup-database.sh"
    "clear-cache-and-deploy.sh"
    "deploy-backend-only.sh"
    "deploy-frontend-only.sh"
    "deploy-frontend-simple.sh"
    "deploy-frontend.sh"
    "deploy-full.sh"
    "deploy.sh"
    "diagnose-502.sh"
    "fix-502-auto.sh"
    "fix-and-deploy.sh"
    "force-cache-bust.sh"
    "nginx-clear-cache.sh"
    "restore-database.sh"
    "setup-deployment-scripts.sh"
)

# Move docs to backup
echo ""
echo "Moving old documentation..."
for file in "${OLD_DOCS[@]}"; do
    if [ -f "$file" ]; then
        mv "$file" "$BACKUP_DIR/" 2>/dev/null && echo "  ✓ $file"
    fi
done

# Move scripts to backup
echo ""
echo "Moving old scripts..."
for file in "${OLD_SCRIPTS[@]}"; do
    if [ -f "$file" ]; then
        mv "$file" "$BACKUP_DIR/" 2>/dev/null && echo "  ✓ $file"
    fi
done

echo ""
echo "✅ Cleanup complete!"
echo ""
echo "📦 Old files backed up to: $BACKUP_DIR"
echo ""
echo "📚 New documentation structure:"
echo "  README.md           - Main documentation"
echo "  QUICK_START.md      - Getting started"
echo "  DEPLOYMENT.md       - Deployment guide"
echo "  TROUBLESHOOTING.md  - Common issues & fixes"
echo ""
echo "🔧 New scripts (in scripts/ folder):"
echo "  scripts/deploy.sh    - Unified deployment"
echo "  scripts/diagnose.sh  - Full diagnostics"
echo "  scripts/backup-db.sh - Database backup"
echo "  scripts/restore-db.sh - Database restore"
echo "  scripts/fix-502.sh   - Fix 502 errors"
echo ""
echo "💡 To restore old files if needed:"
echo "   cp $BACKUP_DIR/* ."
echo ""
echo "🗑️  To permanently delete backup:"
echo "   rm -rf $BACKUP_DIR"

