#!/bin/bash
set -e

API_URL="http://localhost:8080"
MAX_RETRIES=5
RETRY_INTERVAL=2

echo "🚀 Starting Smoke Test..."

check_endpoint() {
    local endpoint=$1
    local description=$2
    
    echo -n "   - Checking $description ($endpoint)... "
    for i in $(seq 1 $MAX_RETRIES); do
        if curl -s -f "$API_URL$endpoint" > /dev/null; then
            echo "✅ OK"
            return 0
        fi
        echo -n "."
        sleep $RETRY_INTERVAL
    done
    
    echo "❌ FAILED"
    return 1
}

# 1. Health Check
if ! check_endpoint "/api/v1/health" "Health Endpoint"; then
    echo "⚠️  Ensure the server is running on $API_URL"
    exit 1
fi

# 2. Metrics Check
if ! check_endpoint "/api/v1/metrics" "Metrics Endpoint"; then
    exit 1
fi

echo "✅ Smoke Test Passed!"
