# Test frontend paths through proxy (port 80)
$base = 'http://localhost:80'

# Login first
$body = @{tenantCode='T202605253515';username='admin';password='admin123'} | ConvertTo-Json
$resp = Invoke-RestMethod -Uri "$base/dev-api/company/login" -Method Post -ContentType 'application/json' -Body $body
$token = $resp.token
Write-Host "TOKEN obtained: $($token.Substring(0,20))..."

# Test HIS paths (direct /his/xxx - from fs-admin-saas)
$hisDirectTests = @(
    '/dev-api/his/healthTongue/list',
    '/dev-api/his/healthRecord/list',
    '/dev-api/his/drugReport/list',
    '/dev-api/his/exportTask/list',
    '/dev-api/his/inquiryOrder/list',
    '/dev-api/his/redPacket/info',
    '/dev-api/his/integralGoods/list',
    '/dev-api/his/doctor/list',
    '/dev-api/his/prescription/list',
    '/dev-api/his/doctorAdvice/list',
    '/dev-api/his/healthTongueQuestion/list',
    '/dev-api/his/healthRecordTemplate/list',
    '/dev-api/his/followPlan/list',
    '/dev-api/his/recoveryRecord/list',
    '/dev-api/his/diagnosis/list'
)

Write-Host "`n=== HIS Direct Tests (via proxy) ==="
foreach ($path in $hisDirectTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}

# Test HIS/fs* paths (rewritten to /store/*)
$hisFsTests = @(
    '/dev-api/his/fsStoreOrder/list',
    '/dev-api/his/fsPatient/list',
    '/dev-api/his/fsUser/list',
    '/dev-api/his/fsMaterial/list',
    '/dev-api/his/fsCoupon/list',
    '/dev-api/his/fsStoreOrderOffline/list',
    '/dev-api/his/fsStoreOrderAudit/list',
    '/dev-api/his/fsStoreStatistics/list',
    '/dev-api/his/fsCollection/list'
)

Write-Host "`n=== HIS/fs* Tests (rewritten to /store/*) ==="
foreach ($path in $hisFsTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}

# Test COURSE paths
$courseTests = @(
    '/dev-api/course/courseDomainName/list',
    '/dev-api/course/courseQuestionBank/list',
    '/dev-api/course/courseAnswerlogs/list',
    '/dev-api/course/courseInfo/list',
    '/dev-api/course/coursePeriod/list'
)

Write-Host "`n=== COURSE Tests (via proxy) ==="
foreach ($path in $courseTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}

# Test BILLING paths
$billingTests = @(
    '/dev-api/billing/wallet/list',
    '/dev-api/billing/bill/list'
)

Write-Host "`n=== BILLING Tests (via proxy) ==="
foreach ($path in $billingTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}

# Test TRANSFER paths
$transferTests = @(
    '/dev-api/transfer/fsTransfer/list',
    '/dev-api/transfer/fsTransferConfig/list'
)

Write-Host "`n=== TRANSFER Tests (via proxy) ==="
foreach ($path in $transferTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}

# Test WX/wxSop paths (rewritten to qwSop)
$wxTests = @(
    '/dev-api/wx/wxSop/list',
    '/dev-api/wx/wxSopUser/list',
    '/dev-api/wx/wxSopUserInfo/list',
    '/dev-api/wx/wxSopLogs/list'
)

Write-Host "`n=== WX/wxSop Tests (via proxy) ==="
foreach ($path in $wxTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}

# Test QW paths
$qwTests = @(
    '/dev-api/qw/tag/list',
    '/dev-api/qw/sop/list',
    '/dev-api/qw/material/list',
    '/dev-api/qw/user/list',
    '/dev-api/qw/welcome/list',
    '/dev-api/qw/groupMsg/list',
    '/dev-api/qwSop/sopUserLogs/list'
)

Write-Host "`n=== QW Tests (via proxy) ==="
foreach ($path in $qwTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}

# Test CHAT paths
$chatTests = @(
    '/dev-api/chat/chatMsg/list',
    '/dev-api/chat/chatMsgLogs/list',
    '/dev-api/chat/chatSession/list'
)

Write-Host "`n=== CHAT Tests (via proxy) ==="
foreach ($path in $chatTests) {
    try {
        $r = Invoke-WebRequest -Uri "$base$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        Write-Host "$path => $($r.StatusCode) code=$($content.code)"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        Write-Host "$path => $code ERROR"
    }
}
