#!/bin/bash

echo "🧪 Testing Product Creation API with Price Validation..."
echo ""

# Test with valid price (should fail with 401 Unauthorized due to missing auth, not validation error)
echo "Test 1: Valid price (29.99) - Should fail with 401 (auth), not 400 (validation)"
curl -X POST http://localhost:3001/shop/products \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test Product",
    "description": "A test product for validation", 
    "price": 29.99,
    "type": "DIGITAL",
    "isActive": true,
    "downloadUrl": "https://example.com/download",
    "fileSize": "50MB"
  }' \
  -w "\nStatus: %{http_code}\n\n"

echo "---"

# Test with invalid price string (should fail with 400 Bad Request - validation error)
echo "Test 2: Invalid price string - Should fail with 400 (validation error)"  
curl -X POST http://localhost:3001/shop/products \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test Product",
    "description": "A test product for validation",
    "price": "invalid-price",
    "type": "DIGITAL", 
    "isActive": true,
    "downloadUrl": "https://example.com/download",
    "fileSize": "50MB"
  }' \
  -w "\nStatus: %{http_code}\n\n"

echo "---"

# Test with negative price (should fail with 400 Bad Request - validation error)  
echo "Test 3: Negative price (-10.50) - Should fail with 400 (validation error)"
curl -X POST http://localhost:3001/shop/products \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Test Product", 
    "description": "A test product for validation",
    "price": -10.50,
    "type": "DIGITAL",
    "isActive": true,
    "downloadUrl": "https://example.com/download", 
    "fileSize": "50MB"
  }' \
  -w "\nStatus: %{http_code}\n\n"

echo "✅ Price validation tests completed!"
