#!/bin/bash
# validate-catalog.sh - Validate service catalog TOML structure

echo "═══════════════════════════════════════════════════════════════"
echo "SERVICE CATALOG VALIDATION TEST"
echo "═══════════════════════════════════════════════════════════════"
echo ""

# Check file exists
if [ ! -f "configs/services-catalog.toml" ]; then
    echo "❌ Error: configs/services-catalog.toml not found"
    exit 1
fi

echo "✓ Configuration file found: configs/services-catalog.toml"
echo ""

# Validate it's valid TOML via NuShell
echo "Validating TOML syntax..."
RESULT=$(nu -c "open configs/services-catalog.toml" 2>&1)
if echo "$RESULT" | grep -q "parse"; then
    echo "❌ TOML parsing failed"
    echo "$RESULT"
    exit 1
fi
echo "✓ TOML syntax is valid"
echo ""

# Display structure
echo "Catalog structure:"
nu -c "
let catalog = open configs/services-catalog.toml
print '  Version: ' + \$catalog.version.catalog_version
print '  Services: '
\$catalog.service | transpose | each { |s| print ('    - ' + \$s.value.display_name?) }
"
echo ""

echo "═══════════════════════════════════════════════════════════════"
echo "✅ Catalog validation complete!"
echo "═══════════════════════════════════════════════════════════════"
