#!/bin/bash
# Comprehensive SigNoz MCP Schema Validation Script
# Usage: ./scripts/validate.sh [--export] [--ci]

set -e

cd "$(dirname "$0")/.."

echo "🔍 SigNoz MCP Schema Validation"
echo "==============================="

# Check if Go is available
if ! command -v go &> /dev/null; then
    echo "❌ Go is not installed or not in PATH"
    exit 1
fi

# Run comprehensive schema validation
echo "📋 Running comprehensive schema validation..."
if go run scripts/comprehensive_schema_validator.go "$@"; then
    echo ""
    echo "🎉 All schemas validated successfully!"
    
    # Run additional validation tests
    echo "🧪 Running unit tests for schema validation..."
    if go test ./pkg/mcp/server -run "TestArraySchemaValidation|TestSpecificGeminiValidationIssue" -v; then
        echo ""
        echo "✅ Schema validation complete - All checks passed!"
        echo "✅ Gemini API compatibility: CONFIRMED"
        echo "✅ JSON Schema compliance: CONFIRMED"
        
        # CI-specific output
        if [[ "$*" == *"--ci"* ]]; then
            echo "::notice title=Schema Validation::All SigNoz MCP tool schemas are valid and Gemini-compatible"
        fi
        
        exit 0
    else
        echo "❌ Unit tests failed"
        exit 1
    fi
else
    echo "❌ Schema validation failed"
    
    # CI-specific output
    if [[ "$*" == *"--ci"* ]]; then
        echo "::error title=Schema Validation::SigNoz MCP tool schemas failed validation"
    fi
    
    exit 1
fi