# Test actual backend paths (from @RequestMapping annotations)
$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 actual backend controller paths ==="

$endpoints = @(
    # qw controllers from com.fs.company.controller.qw
    "/qwGroupLiveCode/list",
    "/qw/tag/list",
    "/qw/tagGroup/list",
    "/qw/sop/list",
    "/qw/sopLogs/list",
    "/qw/sopTemp/list",
    "/qw/material/list",
    "/qw/materialGroup/list",
    "/qw/user/list",
    "/qw/groupMsg/list",
    "/qw/welcome/list",
    "/qw/qwSession/list",
    "/qw/statistic/list",
    "/qw/userBehaviorData/list",
    "/qw/userVideo/list",
    "/qw/qwUserVoiceLog/list",
    "/qwSop/sopUserLogs/list",
    "/qwSop/sopUserLogsInfo/list",
    # transfer controllers
    "/transfer/transfer/list",
    "/transfer/voiceLog/list",
    # billing controllers
    "/billing/wallet/list",
    "/billing/walletLog/list",
    # hisStore controllers
    "/hisStore/fsStoreStatisticsScrm/list",
    "/hisStore/fsStoreOrderOfflineScrm/list",
    "/hisStore/fsStoreOrderAuditScrm/list",
    "/store/store/fsStorePay/list",
    # course controllers (company package)
    "/course/courseAnswerLog/list",
    "/course/courseRedPacketLog/list",
    "/course/courseWatchLog/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 = if ($body.msg) { $body.msg.Substring(0, [Math]::Min(50, $body.msg.Length)) } else { "" }
        if ($code -eq 200) {
            Write-Output "OK   $path => code=$code"
        } else {
            Write-Output "ERR  $path => code=$code msg=$msg"
        }
    } catch {
        $status = $_.Exception.Response.StatusCode.value__
        if ($status -eq 404) {
            Write-Output "404  $path"
        } elseif ($status -eq 405) {
            Write-Output "405  $path => Method Not Allowed"
        } else {
            Write-Output "ERR  $path => HTTP $status"
        }
    }
}
