#!/bin/bash

# Script de correction rapide pour la production

echo "🔧 Correction rapide en production..."

APP_DIR="/home/cundo/Bureau/symfoy_projets/symfo_vue/microservice/search-service"
cd "$APP_DIR"

# 1. Vider le cache
echo "🗑️  Vidage du cache..."
php bin/console cache:clear --env=prod --no-debug

# 2. Réchauffer le cache
echo "🔥 Préchauffage du cache..."
php bin/console cache:warmup --env=prod --no-debug

# 3. Vérifier la syntaxe
echo "✅ Vérification de la syntaxe..."
php bin/console lint:container --env=prod

# 4. Test local de l'endpoint de santé
echo "🏥 Test de l'endpoint de santé..."
response=$(php -S localhost:8003 -t public/ > /dev/null 2>&1 & 
sleep 2 && 
curl -s "http://localhost:8003/api/search/health" && 
pkill -f "php.*localhost:8003")

if echo "$response" | grep -q "OK"; then
    echo "✅ Service fonctionne localement"
else
    echo "❌ Service ne fonctionne pas localement"
    echo "Réponse: $response"
fi

echo "🚀 Correction terminée!"