$body = @{tenantCode='T202605253515';username='admin';password='admin123'} | ConvertTo-Json
$resp = Invoke-RestMethod -Uri 'http://localhost:8006/company/login' -Method Post -ContentType 'application/json' -Body $body
$token = $resp.token
Write-Host "TOKEN: $token"

# Test his endpoints that were previously 404
$hisTests = @(
    '/his/healthTongue/list',
    '/his/healthRecord/list',
    '/his/drugReport/list',
    '/his/exportTask/list',
    '/his/inquiryOrder/list',
    '/his/doctorAdvice/list',
    '/his/prescription/list',
    '/his/healthTongueQuestion/list',
    '/his/healthRecordTemplate/list',
    '/his/followPlan/list',
    '/his/recoveryRecord/list',
    '/his/recoveryPlan/list',
    '/his/healthReport/list'
)

Write-Host "`n=== HIS Tests ==="
foreach ($path in $hisTests) {
    try {
        $r = Invoke-WebRequest -Uri "http://localhost:8006$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        Write-Host "$path => $($r.StatusCode) OK"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        if ($code -eq 404) {
            Write-Host "$path => 404 NOT FOUND"
        } else {
            Write-Host "$path => $code ERROR"
        }
    }
}

# Test course endpoints that were previously 404
$courseTests = @(
    '/course/courseDomainName/list',
    '/course/courseQuestionBank/list',
    '/course/courseAnswerlogs/list',
    '/course/courseRedPacketLog/list',
    '/course/courseFinishTemp/list',
    '/course/courseSopLogs/list',
    '/course/courseInfo/list',
    '/course/coursePeriod/list'
)

Write-Host "`n=== COURSE Tests ==="
foreach ($path in $courseTests) {
    try {
        $r = Invoke-WebRequest -Uri "http://localhost:8006$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        Write-Host "$path => $($r.StatusCode) OK"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        if ($code -eq 404) {
            Write-Host "$path => 404 NOT FOUND"
        } else {
            Write-Host "$path => $code ERROR"
        }
    }
}

# Test billing endpoints
$billingTests = @(
    '/billing/wallet/list',
    '/billing/bill/list',
    '/api/fee/wallet/list',
    '/api/fee/bill/list'
)

Write-Host "`n=== BILLING Tests ==="
foreach ($path in $billingTests) {
    try {
        $r = Invoke-WebRequest -Uri "http://localhost:8006$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        Write-Host "$path => $($r.StatusCode) OK"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        if ($code -eq 404) {
            Write-Host "$path => 404 NOT FOUND"
        } else {
            Write-Host "$path => $code ERROR"
        }
    }
}

# Test transfer endpoints
$transferTests = @(
    '/transfer/fsTransfer/list',
    '/transfer/fsTransferConfig/list'
)

Write-Host "`n=== TRANSFER Tests ==="
foreach ($path in $transferTests) {
    try {
        $r = Invoke-WebRequest -Uri "http://localhost:8006$path" -Method Get -Headers @{Authorization="Bearer $token"} -UseBasicParsing -ErrorAction Stop
        Write-Host "$path => $($r.StatusCode) OK"
    } catch {
        $code = $_.Exception.Response.StatusCode.value__
        if ($code -eq 404) {
            Write-Host "$path => 404 NOT FOUND"
        } else {
            Write-Host "$path => $code ERROR"
        }
    }
}
