#!/bin/bash
echo "🏢 Testing Company Info API..."
echo ""

# Get CSRF token
CSRF_TOKEN=$(curl -s -c /tmp/company-test-cookies.txt http://localhost:9000/api/auth/csrf | jq -r .csrfToken)
echo "1️⃣ CSRF Token: ${CSRF_TOKEN:0:20}..."
echo ""

# Test company info submission
echo "2️⃣ Testing company info API..."
RESPONSE=$(curl -s -b /tmp/company-test-cookies.txt \
  -X POST http://localhost:9000/api/onboarding/company-info \
  -H "Content-Type: application/json" \
  -H "X-CSRF-Token: $CSRF_TOKEN" \
  -d '{
    "email": "realtest@mawidi.com",
    "companyName": "Test Company Inc",
    "industry": "healthcare",
    "companySize": "11-50",
    "gccCountry": "uae",
    "phoneNumber": "+971501234567",
    "agentCount": "5",
    "services": ["booking", "reminders"],
    "selectedPlan": "tier2"
  }')

echo "$RESPONSE" | jq
echo ""

if echo "$RESPONSE" | jq -e '.success' > /dev/null 2>&1; then
  echo "✅ Company info saved successfully!"
else
  echo "❌ Failed to save company info"
  echo "Error: $(echo "$RESPONSE" | jq -r '.error')"
  if echo "$RESPONSE" | jq -e '.details' > /dev/null 2>&1; then
    echo "Details:"
    echo "$RESPONSE" | jq '.details'
  fi
fi

rm -f /tmp/company-test-cookies.txt
