# Test key endpoints through the proxy after vue.config.js fix
$body = '{"tenantCode":"T202605253515","username":"admin","password":"admin123"}'
$loginResp = Invoke-WebRequest -Uri 'http://localhost:80/prod-api/login' -Method Post -ContentType 'application/json' -Body $body -UseBasicParsing
$token = ($loginResp.Content | ConvertFrom-Json).token
Write-Host "Login OK, token length: $($token.Length)"

# Test key proxy rewrite rules
$tests = @(
    # /store/store/* → /store/* 
    @{name='store/store→store'; path='/store/store/list'},
    @{name='store/storeOrder→store'; path='/store/storeOrder/list'},
    @{name='store/storeProduct→store'; path='/store/storeProduct/list'},
    # /store/his/* → /his/*
    @{name='store/his→his'; path='/store/his/doctor/list'},
    # /store/doctor/* → /his/doctor/*
    @{name='store/doctor→his/doctor'; path='/store/doctor/list'},
    # /store/healthTongue → /his/healthTongue
    @{name='store/healthTongue→his'; path='/store/healthTongue/list'},
    # /store/inquiryOrder → /his/inquiryOrder
    @{name='store/inquiryOrder→his'; path='/store/inquiryOrder/list'},
    # /his/fsPatient → /store/patient
    @{name='his/fsPatient→store/patient'; path='/his/fsPatient/list'},
    @{name='his/fsUser→store/user'; path='/his/fsUser/list'},
    @{name='his/fsMaterial→store/material'; path='/his/fsMaterial/list'},
    @{name='his/fsCoupon→store/coupon'; path='/his/fsCoupon/list'},
    @{name='his/fsDrugReport→store/drugReport'; path='/his/fsDrugReport/list'},
    @{name='his/fsStoreOrderOffline→hisStore'; path='/his/fsStoreOrderOffline/list'},
    @{name='his/fsStoreOrderAudit→hisStore'; path='/his/fsStoreOrderAudit/list'},
    @{name='his/fsStoreStatistics→hisStore'; path='/his/fsStoreStatistics/list'},
    @{name='his/fsCollection→store/collection'; path='/his/fsCollection/list'},
    @{name='his/fsFirstDiagnosis→his/diagnosis'; path='/his/fsFirstDiagnosis/list'},
    # hisStore/collection → store/collection
    @{name='hisStore/collection→store'; path='/hisStore/collection/list'},
    # /his_store/* → /hisStore/*
    @{name='his_store→hisStore'; path='/his_store/store_instant_discount/list'},
    # /wx/wxSop → /qwSop/sopUserLogs
    @{name='wx/wxSop→qwSop'; path='/wx/wxSop/list'},
    @{name='wx/wxSopUser→qwSop'; path='/wx/wxSopUser/list'},
    # /wxSop/sopUserLogsWx → /qwSop/sopUserLogs
    @{name='wxSop/sopUserLogsWx→qwSop'; path='/wxSop/sopUserLogsWx/list'},
    # /fast_gpt/* → /fastGpt/*
    @{name='fast_gpt→fastGpt'; path='/fast_gpt/read_package/list'},
    # /admin/medical → fs-admin(8003)
    @{name='admin/medical→admin'; path='/admin/medical/list'},
    # /company/company → /company
    @{name='company/company→company'; path='/company/company/list'},
    # /company/companyTag → /companyTag
    @{name='company/companyTag→companyTag'; path='/company/companyTag/list'},
    # /company/companyUser → /companyUser
    @{name='company/companyUser→companyUser'; path='/company/companyUser/list'},
    # /company/companyVoice → /companyVoice
    @{name='company/companyVoice→companyVoice'; path='/company/companyVoice/list'},
    # /company/easyCall → /easyCall
    @{name='company/easyCall→easyCall'; path='/company/easyCall/gateway/list'},
    # /sop/companySopRole → /companySopRole
    @{name='sop/companySopRole→companySopRole'; path='/sop/companySopRole/list'},
    # Direct paths that should work
    @{name='his:healthTongue'; path='/his/healthTongue/list'},
    @{name='his:healthRecord'; path='/his/healthRecord/list'},
    @{name='his:drugReport'; path='/his/drugReport/list'},
    @{name='his:exportTask'; path='/his/exportTask/list'},
    @{name='his:inquiryOrder'; path='/his/inquiryOrder/list'},
    @{name='his:doctor'; path='/his/doctor/list'},
    @{name='his:prescription'; path='/his/prescription/list'},
    @{name='course:courseDomainName'; path='/course/courseDomainName/list'},
    @{name='course:courseQuestionBank'; path='/course/courseQuestionBank/list'},
    @{name='billing:wallet'; path='/billing/wallet/list'},
    @{name='billing:bill'; path='/billing/bill/list'},
    @{name='transfer:fsTransfer'; path='/transfer/fsTransfer/list'},
    @{name='chat:chatMsg'; path='/chat/chatMsg/list'},
    @{name='qw:tag'; path='/qw/tag/list'},
    @{name='qw:sop'; path='/qw/sop/list'},
    @{name='qw:material'; path='/qw/material/list'},
    @{name='qw:user'; path='/qw/user/list'},
    @{name='crm:customer'; path='/crm/customer/list'},
    @{name='index:statistics'; path='/index/statistics/rechargeComsumption'},
    # system → fs-admin
    @{name='system:user→admin'; path='/system/user/list'},
    @{name='system:role→admin'; path='/system/role/list'},
    @{name='system:menu→admin'; path='/system/menu/list'}
)

$ok = 0; $fail = 0; $err = 0
foreach ($t in $tests) {
    $url = "http://localhost:80/prod-api$($t.path)"
    try {
        $r = Invoke-WebRequest -Uri $url -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -TimeoutSec 10 -ErrorAction Stop
        $content = $r.Content | ConvertFrom-Json
        if ($content.code -eq 200) {
            Write-Host "OK  $($t.name)"
            $ok++
        } elseif ($content.code -eq 500) {
            $msg = $content.msg
            if ($msg.Length -gt 60) { $msg = $msg.Substring(0,60) }
            Write-Host "ERR $($t.name) => code=500 msg=$msg"
            $err++
        } else {
            $msg = $content.msg
            if ($msg -and $msg.Length -gt 60) { $msg = $msg.Substring(0,60) }
            Write-Host "WRN $($t.name) => code=$($content.code) msg=$msg"
            $fail++
        }
    } catch {
        $statusCode = 0
        if ($_.Exception.Response) { $statusCode = [int]$_.Exception.Response.StatusCode }
        Write-Host "$statusCode $($t.name) => ERROR"
        $fail++
    }
}

Write-Host "`n=== SUMMARY: OK=$ok, ERR(500)=$err, FAIL=$fail ==="
