#!/bin/bash
# Verification script for IDEA_REVIEW_PLAN implementation - File checks only

echo "🔍 IDEA_REVIEW_PLAN Implementation Verification (Files Only)"
echo "============================================================"
echo ""

PASSED=0
FAILED=0

# Function to check if file exists
check_file() {
    local name=$1
    local path=$2

    if [ -f "$path" ]; then
        local size=$(wc -c < "$path")
        echo "✅ $name"
        echo "   Path: $path"
        echo "   Size: $size bytes"
        ((PASSED++))
    else
        echo "❌ $name"
        echo "   Path: $path"
        echo "   Missing!"
        ((FAILED++))
    fi
    echo ""
}

# Function to check if text appears in file
check_text_in_file() {
    local name=$1
    local path=$2
    local text=$3

    if [ -f "$path" ] && grep -q "$text" "$path"; then
        echo "✅ $name"
        echo "   Found in: $path"
        ((PASSED++))
    else
        echo "❌ $name"
        echo "   Not found in: $path"
        ((FAILED++))
    fi
    echo ""
}

# Checks

# 1. Prompt files
check_file "Review Plan Prompt (Main)" "lib/idea-prompts/review-plan-job.md"
check_file "Review Plan Prompt (MCP)" "../scrum4me-mcp/src/prompts/idea/review-plan.md"

# 2. Components
check_file "ReviewLogViewer Component" "components/ideas/review-log-viewer.tsx"

# 3. Server Actions
check_file "Idea Actions" "actions/ideas.ts"
check_text_in_file "startReviewPlanJobAction in Idea Actions" "actions/ideas.ts" "startReviewPlanJobAction"

# 4. MCP Tools
check_file "MCP Update Plan Reviewed Tool" "../scrum4me-mcp/src/tools/update-idea-plan-reviewed.ts"

# 5. Kind Prompts Registration
check_text_in_file "IDEA_REVIEW_PLAN in kind-prompts.ts" "../scrum4me-mcp/src/lib/kind-prompts.ts" "IDEA_REVIEW_PLAN"

# 6. Wait-for-job Discriminator
check_text_in_file "IDEA_REVIEW_PLAN in wait-for-job.ts" "../scrum4me-mcp/src/tools/wait-for-job.ts" "IDEA_REVIEW_PLAN"

# 7. Documentation
check_file "Review Plan Job Runbook" "docs/runbooks/review-plan-job.md"
check_file "Phase 6 Test Plan" "docs/implementation-complete/PHASE6-END-TO-END-TEST-PLAN.md"
check_file "Implementation Summary" "docs/implementation-complete/IDEA_REVIEW_PLAN-implementation-summary.md"

# 8. Tests
check_file "Review Plan Job Tests" "__tests__/review-plan-job.test.ts"

# 9. Migrations
check_file "Migration SQL" "prisma/migrations/20260514000000_add_review_plan_support/migration.sql"

# Summary
echo "============================================================"
echo "Summary: $PASSED passed, $FAILED failed"
echo ""

if [ $FAILED -eq 0 ]; then
    echo "✅ All file checks passed! Implementation is complete."
    exit 0
else
    echo "❌ Some files are missing. See above for details."
    exit 1
fi
