# Comprehensive endpoint test with UseBasicParsing
$loginBody = @{
    tenantCode = "T202605253515"
    username = "admin"
    password = "admin123"
} | ConvertTo-Json

$resp = Invoke-RestMethod -Uri "http://localhost:8006/login" -Method POST -ContentType "application/json" -Body $loginBody
$token = $resp.token
$headers = @{ Authorization = "Bearer $token" }

Write-Output "=== Testing all endpoints on fs-company (8006) ==="
Write-Output ""

$endpoints = @(
    "/chat/chatMsg/list",
    "/chat/chatMsgLogs/list",
    "/chat/chatSession/list",
    "/chat/chatGroup/list",
    "/chat/chatLabel/list",
    "/chat/chatAutoSign/list",
    "/chat/chatAutoSignLog/list",
    "/chat/chatMaterial/list",
    "/chat/chatMaterialCategory/list",
    "/qw/qwGroupLiveCode/list",
    "/qw/qwCustomerLink/list",
    "/qw/qwDrainageLink/list",
    "/qw/qwTag/list",
    "/qw/qwTagGroup/list",
    "/qw/qwContactWay/list",
    "/qw/qwContactWayLog/list",
    "/qw/qwBatchContact/list",
    "/qwSop/sop/list",
    "/qwSop/sopLog/list",
    "/qwSop/sopUser/list",
    "/qwSop/sopUserLogsWx/list",
    "/his/redPacket/info",
    "/his/integralGoods/list",
    "/his/integralOrder/list",
    "/his/tongue/list",
    "/his/healthRecord/list",
    "/his/medicineReport/list",
    "/his/inquiryReport/list",
    "/his/exportTask/list",
    "/store/storeStatistics/list",
    "/store/collection/list",
    "/store/store/list",
    "/store/store/storeOrderOffline/list",
    "/store/store/storeOrderAudit/list",
    "/store/store/statistics/list",
    "/store/store/integralGoods/list",
    "/store/store/integralOrder/list",
    "/store/store/fsStorePay/list",
    "/index/statistics/rechargeComsumption",
    "/index/statistics/trafficLog",
    "/crm/statistics/customer",
    "/billing/wallet/list",
    "/billing/walletLog/list",
    "/transfer/transfer/list",
    "/transfer/voiceLog/list",
    "/course/courseDomainName/list",
    "/course/courseQuestionBank/list",
    "/course/courseAnswerLog/list",
    "/course/courseRedPacketLog/list",
    "/device/list",
    "/watch/deviceStatus/list"
)

foreach ($path in $endpoints) {
    try {
        $r = Invoke-WebRequest -Uri "http://localhost:8006$path" -Method GET -Headers $headers -UseBasicParsing -ErrorAction Stop
        $body = $r.Content | ConvertFrom-Json
        $code = $body.code
        $msg = $body.msg
        if ($code -eq 200) {
            Write-Output "OK   $path => code=$code"
        } else {
            $shortMsg = if ($msg.Length -gt 50) { $msg.Substring(0,50) } else { $msg }
            Write-Output "ERR  $path => code=$code msg=$shortMsg"
        }
    } catch {
        $status = $_.Exception.Response.StatusCode.value__
        if ($status -eq 404) {
            Write-Output "404  $path => NOT FOUND"
        } elseif ($status -eq 405) {
            Write-Output "405  $path => Method Not Allowed"
        } else {
            Write-Output "ERR  $path => HTTP $status"
        }
    }
}
