#!/bin/bash

# Production Cleanup Script for Seraph3
# This script fixes composer autoloading issues and cleans up duplicate seeder files

echo "🧹 Starting Seraph3 Production Cleanup..."

# 1. Fix composer cache directory permissions
echo "📁 Fixing composer cache permissions..."
sudo mkdir -p /var/www/.cache/composer/files/
sudo chown -R www-data:www-data /var/www/.cache
sudo chmod -R 755 /var/www/.cache

# 2. Remove old seeds directory to prevent autoloading conflicts
echo "🗑️  Removing old database/seeds directory..."
rm -rf database/seeds/

# 3. Regenerate composer autoloader
echo "🔄 Regenerating composer autoloader..."
composer dump-autoload --optimize

# 4. Clear Laravel caches
echo "🧼 Clearing Laravel caches..."
php artisan cache:clear
php artisan config:clear
php artisan route:clear
php artisan view:clear

echo "✅ Production cleanup completed successfully!"
echo ""
echo "📋 Next steps:"
echo "   1. Run: composer install --optimize-autoloader --no-dev"
echo "   2. Run: php artisan migrate:fresh --seed"
echo "   3. Verify all seeders work correctly" 