$loginBody = '{"tenantCode":"T202605253515","username":"admin","password":"admin123"}'
$resp = Invoke-WebRequest -Uri 'http://localhost:8006/company/login' -Method POST -ContentType 'application/json' -Body $loginBody -UseBasicParsing
Write-Host "Status: $($resp.StatusCode)"
$content = $resp.Content | ConvertFrom-Json
Write-Host "Response code: $($content.code)"
Write-Host "Response msg: $($content.msg)"

# Check token field
if ($content.token) {
    Write-Host "Token field found, length: $($content.token.Length)"
    $token = $content.token
} elseif ($content.data -and $content.data.token) {
    Write-Host "Token in data.token"
    $token = $content.data.token
} else {
    Write-Host "Token structure:"
    $content | Get-Member -MemberType NoteProperty | ForEach-Object { Write-Host "  $($_.Name): $($_.MemberType)" }
    # Show full response
    $resp.Content.Substring(0, [Math]::Min(500, $resp.Content.Length))
}

# Try with proper headers
$headers = @{ Authorization = "Bearer $token" }

# Test a simple API
Write-Host "`n=== Test /getInfo ==="
try {
    $infoResp = Invoke-WebRequest -Uri 'http://localhost:8006/getInfo' -Method GET -Headers $headers -UseBasicParsing
    $info = $infoResp.Content | ConvertFrom-Json
    Write-Host "getInfo code: $($info.code)"
    Write-Host "User: $($info.user.userName)"
} catch {
    Write-Host "getInfo error: $($_.Exception.Message)"
}
