# Quick test script
$body = '{"email":"riseup@popcode.com.br","password":"riseup"}'
$resp = Invoke-RestMethod -Uri "https://yuanqfswhberkoevtmfr.supabase.co/auth/v1/token?grant_type=password" -Method Post -Body $body -ContentType "application/json" -Headers @{"apikey"="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1YW5xZnN3aGJlcmtvZXZ0bWZyIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTQ5NTQzNjksImV4cCI6MjA3MDUzMDM2OX0.g8Fm4XAvtX46zifBZnYVH4tVuQkqUH6Ia9CXQj4DztQ"}

$jwt = $resp.access_token
$serviceKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV0YmxmeXBjeHh0dnZ1cWprcmdkIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc2NDE1NzM2MywiZXhwIjoyMDc5NzMzMzYzfQ.dJVEzm26MuxIEAzeeIOLd-83fFHhfX0Z7UgF4LEX-98"

Write-Host "Testing 3 endpoints..." -ForegroundColor Cyan

# Test 1: availability-list
Write-Host "`n[1] availability-list" -ForegroundColor Yellow
try {
    $result = Invoke-RestMethod -Uri "https://etblfypcxxtvvuqjkrgd.supabase.co/functions/v1/availability-list" -Method Get -Headers @{"Authorization"="Bearer $serviceKey";"x-external-jwt"=$jwt;"apikey"=$serviceKey}
    Write-Host "✅ SUCCESS" -ForegroundColor Green
    $result | ConvertTo-Json -Depth 2
} catch {
    Write-Host "❌ FAILED" -ForegroundColor Red
}

# Test 2: audit-list  
Write-Host "`n[2] audit-list" -ForegroundColor Yellow
try {
    $result = Invoke-RestMethod -Uri "https://etblfypcxxtvvuqjkrgd.supabase.co/functions/v1/audit-list" -Method Get -Headers @{"Authorization"="Bearer $serviceKey";"x-external-jwt"=$jwt;"apikey"=$serviceKey}
    Write-Host "✅ SUCCESS" -ForegroundColor Green
    $result | ConvertTo-Json -Depth 2
} catch {
    Write-Host "❌ FAILED" -ForegroundColor Red
}

# Test 3: system-health-check
Write-Host "`n[3] system-health-check" -ForegroundColor Yellow
try {
    $result = Invoke-RestMethod -Uri "https://etblfypcxxtvvuqjkrgd.supabase.co/functions/v1/system-health-check" -Method Get -Headers @{"Authorization"="Bearer $serviceKey";"x-external-jwt"=$jwt;"apikey"=$serviceKey}
    Write-Host "✅ SUCCESS" -ForegroundColor Green
    $result | ConvertTo-Json -Depth 3
} catch {
    Write-Host "❌ FAILED" -ForegroundColor Red
}
