# Test all previously-404 endpoints on fs-company (8006) after his/course controller un-exclusion
$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 his/course/store endpoints on fs-company (8006) ==="
$endpoints = @(
    # Previously 404 - his controllers
    "/his/healthTongue/list",
    "/his/healthRecord/list",
    "/his/drugReport/list",
    "/his/drugReportCount/list",
    "/his/exportTask/list",
    "/his/inquiryOrderReport/list",
    "/his/tongue/list",
    "/his/user/list",
    "/his/userCoupon/list",
    "/his/storeOrder/list",
    "/his/storePayment/list",
    "/his/coupon/list",
    "/his/doctor/list",
    "/his/package/list",
    "/his/testReport/list",
    "/his/testTemp/list",
    "/his/testTempItem/list",
    "/his/inquiryOrder/list",
    "/his/inquiryTemp/list",
    "/his/inquiryDisease/list",
    "/his/physicalReportTemplate/list",
    "/his/physicalReportTemplateField/list",
    "/his/healthData/list",
    "/his/healthHistoryTemp/list",
    "/his/healthLife/list",
    "/his/patient/list",
    "/his/disease/list",
    "/his/department/list",
    "/his/vessel/list",
    "/his/article/list",
    "/his/articleCate/list",
    "/his/prescribe/list",
    "/his/storeProduct/list",
    "/his/storeProductCategory/list",
    "/his/storeProductPackage/list",
    "/his/storeAfterSales/list",
    "/his/hospital/list",
    "/his/chineseMedicine/list",
    "/his/illnessLibrary/list",
    # Previously 404 - course controllers
    "/course/courseDomainName/list",
    "/course/courseQuestionBank/list",
    "/course/courseQuestionCategory/list",
    "/course/userCourseComment/list",
    "/course/videoResource/list",
    # Previously working - should still work
    "/chat/chatMsg/list",
    "/chat/chatMsgLogs/list",
    "/chat/chatSession/list",
    "/his/redPacket/info",
    "/his/integralGoods/list",
    "/his/integralOrder/list",
    "/qw/tag/list",
    "/qw/sop/list",
    "/qw/material/list",
    "/store/store/storeOrderOffline/list",
    "/store/store/storeOrderAudit/list",
    "/index/statistics/rechargeComsumption",
    "/crm/statistics/customer"
)

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
        if ($code -eq 200) {
            Write-Output "OK   $path"
        } else {
            $msg = if ($body.msg) { $body.msg.Substring(0, [Math]::Min(60, $body.msg.Length)) } 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"
        } else {
            Write-Output "$status  $path"
        }
    }
}
