#!/bin/bash

echo "🔍 Tidewave MCP Verification Script"
echo "=================================="
echo

# Check if Phoenix server is running
echo "1. Checking Phoenix server..."
if curl -s http://localhost:4040 > /dev/null; then
    echo "   ✅ Phoenix server is running on port 4040"
else
    echo "   ❌ Phoenix server is not responding on port 4040"
    echo "   Run: mix phx.server"
    exit 1
fi

echo

# Check Tidewave MCP endpoint
echo "2. Testing Tidewave MCP endpoint..."
response=$(curl -s -X POST -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "initialize", "id": 1, "params": {"protocolVersion": "2024-11-05", "capabilities": {"roots": {"listChanged": true}}, "clientInfo": {"name": "verification-test", "version": "1.0.0"}}}' \
  http://localhost:4040/tidewave/mcp)

if echo "$response" | grep -q "jsonrpc"; then
    echo "   ✅ Tidewave MCP is responding correctly"
    echo "   📋 Response preview: $(echo "$response" | head -c 100)..."
else
    echo "   ❌ Tidewave MCP is not responding correctly"
    echo "   📋 Response: $response"
fi

echo

# Check Tidewave web interface
echo "3. Checking Tidewave web interface..."
if curl -s http://localhost:4040/tidewave > /dev/null; then
    echo "   ✅ Tidewave web interface is accessible"
    echo "   🌐 Open: http://localhost:4040/tidewave"
else
    echo "   ❌ Tidewave web interface is not accessible"
fi

echo

# Check VS Code configuration
echo "4. Checking VS Code configuration..."
if [ -f ".vscode/settings.json" ]; then
    if grep -q "4040" .vscode/settings.json; then
        echo "   ✅ VS Code settings configured for port 4040"
    else
        echo "   ⚠️  VS Code settings may need port update"
    fi
else
    echo "   ⚠️  VS Code settings file not found"
fi

echo

# Check Claude Desktop configuration
echo "5. Checking Claude Desktop configuration..."
if [ -f "mcp-config.json" ]; then
    if grep -q "4040" mcp-config.json; then
        echo "   ✅ Claude Desktop config configured for port 4040"
    else
        echo "   ⚠️  Claude Desktop config may need port update"
    fi
else
    echo "   ⚠️  Claude Desktop config file not found"
fi

echo
echo "🎉 Verification complete!"
echo
echo "Next steps:"
echo "- Restart VS Code to ensure MCP integration is active"
echo "- Try using Copilot or other MCP-compatible AI assistants"
echo "- Explore the web interface at http://localhost:4040/tidewave"
echo
