#!/bin/bash

# Q ROVER - Shared Hosting Deployment Script
# This script optimizes the Laravel application for shared hosting

echo "🚗 Q ROVER - Shared Hosting Deployment Script"
echo "=============================================="

# Check if we're in the right directory
if [ ! -f "artisan" ]; then
    echo "❌ Error: artisan file not found. Please run this script from the Laravel root directory."
    exit 1
fi

echo "📦 Step 1: Installing/Updating Composer Dependencies..."
composer install --no-dev --optimize-autoloader --no-interaction

echo "🔧 Step 2: Optimizing Application..."
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan event:cache

echo "🗄️ Step 3: Running Database Migrations..."
php artisan migrate --force

echo "🌱 Step 4: Seeding Database (if needed)..."
read -p "Do you want to seed the database? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
    php artisan db:seed --class=VehicleCategorySeeder
    php artisan db:seed --class=LocationSeeder
fi

echo "🔗 Step 5: Creating Storage Link..."
php artisan storage:link

echo "📁 Step 6: Setting Permissions..."
chmod -R 755 storage/
chmod -R 755 bootstrap/cache/
chmod -R 755 public/

echo "🧹 Step 7: Clearing Caches..."
php artisan cache:clear
php artisan config:clear

echo "✅ Deployment Complete!"
echo ""
echo "📋 Next Steps:"
echo "1. Upload all files to your shared hosting directory"
echo "2. Update your .env file with production settings"
echo "3. Point your domain to the 'public' directory"
echo "4. Test the application"
echo ""
echo "🌐 Your Q ROVER application is ready for production!"
