#!/bin/bash
# Script de vérification rapide de l'intégration des workflows

echo "╔══════════════════════════════════════════════════════════╗"
echo "║     🔍 VÉRIFICATION INTÉGRATION WORKFLOWS               ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""

# Couleurs
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

check_file() {
    local file=$1
    local pattern=$2
    local description=$3
    
    if grep -q "$pattern" "$file" 2>/dev/null; then
        echo -e "${GREEN}✅${NC} $description"
        return 0
    else
        echo -e "${RED}❌${NC} $description"
        return 1
    fi
}

echo "📋 Vérification des fichiers..."
echo ""

# 1. VisionAnalysis fix
echo "1️⃣  VisionAnalysis"
check_file "geniusia2/core/vision_analysis.py" "if self.llm and" "   Fix attribut self.llm"
echo ""

# 2. EventCapture intégration
echo "2️⃣  EventCapture"
check_file "geniusia2/core/event_capture.py" "self.session_manager.add_action" "   Appel SessionManager.add_action()"
check_file "geniusia2/core/event_capture.py" "_on_session_completed" "   Callback _on_session_completed()"
check_file "geniusia2/core/event_capture.py" "_on_workflow_detected" "   Callback _on_workflow_detected()"
echo ""

# 3. Orchestrator intégration
echo "3️⃣  Orchestrator"
check_file "geniusia2/core/orchestrator.py" "self.session_manager = SessionManager" "   Initialisation SessionManager"
check_file "geniusia2/core/orchestrator.py" "self.workflow_detector = WorkflowDetector" "   Initialisation WorkflowDetector"
check_file "geniusia2/core/orchestrator.py" "def _on_session_completed" "   Méthode _on_session_completed()"
check_file "geniusia2/core/orchestrator.py" "def _on_workflow_detected" "   Méthode _on_workflow_detected()"
echo ""

# 4. SuggestionManager support
echo "4️⃣  SuggestionManager"
check_file "geniusia2/core/suggestion_manager.py" "def on_workflow_detected" "   Méthode on_workflow_detected()"
check_file "geniusia2/core/suggestion_manager.py" "_check_workflow_suggestion" "   Méthode _check_workflow_suggestion()"
check_file "geniusia2/core/suggestion_manager.py" "_match_workflow_start" "   Méthode _match_workflow_start()"
echo ""

# 5. SessionManager
echo "5️⃣  SessionManager"
check_file "geniusia2/core/session_manager.py" "class SessionManager" "   Classe SessionManager existe"
check_file "geniusia2/core/session_manager.py" "def add_action" "   Méthode add_action()"
check_file "geniusia2/core/session_manager.py" "def finalize_current_session" "   Méthode finalize_current_session()"
echo ""

# 6. WorkflowDetector
echo "6️⃣  WorkflowDetector"
if [ -f "geniusia2/core/workflow_detector.py" ]; then
    echo -e "${GREEN}✅${NC}    Fichier workflow_detector.py existe"
    check_file "geniusia2/core/workflow_detector.py" "class WorkflowDetector" "   Classe WorkflowDetector existe"
    check_file "geniusia2/core/workflow_detector.py" "def analyze_sessions" "   Méthode analyze_sessions()"
else
    echo -e "${RED}❌${NC}    Fichier workflow_detector.py manquant"
fi
echo ""

# Résumé
echo "════════════════════════════════════════════════════════════"
echo ""
echo "📊 RÉSUMÉ"
echo ""

# Compter les succès
total=0
success=0

for file in "geniusia2/core/vision_analysis.py" "geniusia2/core/event_capture.py" "geniusia2/core/orchestrator.py" "geniusia2/core/suggestion_manager.py" "geniusia2/core/session_manager.py" "geniusia2/core/workflow_detector.py"; do
    if [ -f "$file" ]; then
        ((total++))
        ((success++))
    else
        ((total++))
    fi
done

if [ $success -eq $total ]; then
    echo -e "${GREEN}🎉 TOUS LES FICHIERS SONT PRÉSENTS !${NC}"
    echo ""
    echo "✅ L'intégration est complète"
    echo ""
    echo "🚀 Prochaine étape : Tester avec une vraie application"
    echo "   Commande : ./lancer_test.sh"
else
    echo -e "${YELLOW}⚠️  Certains fichiers manquent${NC}"
    echo ""
    echo "Fichiers présents : $success/$total"
fi

echo ""
echo "════════════════════════════════════════════════════════════"
echo ""
echo "📚 Documentation :"
echo "   • État : ETAT_INTEGRATION_WORKFLOWS.md"
echo "   • Test manuel : TEST_MANUEL.md"
echo "   • Guide : docs/sessions/ETAT_ACTUEL_WORKFLOWS.md"
echo ""
