#!/bin/bash
# Test script for AWS Qdrant Cluster deployment

# Get the Load Balancer DNS from CloudFormation
echo "🔍 Fetching AWS Qdrant cluster endpoint..."
NLB_DNS=$(aws cloudformation describe-stacks \
  --stack-name qdrant-cluster-dev \
  --region ap-south-1 \
  --query 'Stacks[0].Outputs[?OutputKey==`LoadBalancerDNS`].OutputValue' \
  --output text 2>/dev/null)

if [ -z "$NLB_DNS" ]; then
  echo "⚠️  Could not fetch NLB DNS from CloudFormation. Using hardcoded value..."
  NLB_DNS="dev-qdrant-nlb-e8c337edc3ee861b.elb.ap-south-1.amazonaws.com"
fi

# Set the Qdrant URL
export QDRANT_URL="http://${NLB_DNS}:6334"

echo "✅ AWS Qdrant Cluster Configuration:"
echo "   Endpoint: $QDRANT_URL"
echo "   Dashboard: http://${NLB_DNS}:6333/dashboard"
echo ""

# Check cluster health
echo "🏥 Checking cluster health..."
if curl -s "http://${NLB_DNS}:6333/health" > /dev/null 2>&1; then
  echo "✅ Cluster is healthy!"
else
  echo "⚠️  Cluster health check failed. Is the deployment complete?"
fi

echo ""
echo "🚀 Running complete chat example with AWS cluster..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""

# Run the example
cargo run --example complete_chat_example
