# Comprehensive API endpoint scanner and tester for saasadminui
# Step 1: Login
$body = '{"tenantCode":"T202605253515","username":"admin","password":"admin123"}'
$loginResp = Invoke-WebRequest -Uri 'http://localhost:8006/login' -Method Post -ContentType 'application/json' -Body $body -UseBasicParsing
$loginJson = $loginResp.Content | ConvertFrom-Json
$token = $loginJson.token
Write-Host "Login OK, token: $($token.Substring(0,20))..."

# Step 2: Get all routes to find menu components
$routesResp = Invoke-WebRequest -Uri 'http://localhost:8006/getRouters' -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing
$routesResp.Content | Out-File -FilePath 'd:\ylrz\saasadminui\routes_raw.json' -Encoding UTF8
Write-Host "Routes saved to routes_raw.json"

# Step 3: Get menu data from the tenant database via API
$menusResp = Invoke-WebRequest -Uri 'http://localhost:8006/system/menu/list' -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing
$menusResp.Content | Out-File -FilePath 'd:\ylrz\saasadminui\menus_raw.json' -Encoding UTF8
Write-Host "Menus saved to menus_raw.json"

# Quick parse to show menu count
$menusJson = $menusResp.Content | ConvertFrom-Json
$menuRows = $menusJson.rows
Write-Host "Total menu entries: $($menuRows.Count)"

# Show menu types
$types = $menuRows | Group-Object menuType | Select-Object Name, Count
Write-Host "`nMenu types:"
$types | Format-Table -AutoSize
