# Check if 404 paths exist in fs-admin-saas but are blocked by @Profile("admin")
$companyUrl = "http://localhost:8006"

# Login
$loginBody = '{"tenantCode":"T202605253515","username":"admin","password":"admin123"}'
$loginResp = Invoke-WebRequest -Uri "$companyUrl/login" -Method POST -ContentType "application/json" -Body $loginBody -UseBasicParsing
$loginJson = $loginResp.Content | ConvertFrom-Json
$token = $loginJson.token
$headers = @{ Authorization = "Bearer $token" }

# Also login to fs-admin
$adminLoginBody = '{"username":"admin","password":"admin123"}'
$adminLoginResp = Invoke-WebRequest -Uri "http://localhost:8003/login" -Method POST -ContentType "application/json" -Body $adminLoginBody -UseBasicParsing
$adminLoginJson = $adminLoginResp.Content | ConvertFrom-Json
$adminToken = $adminLoginJson.token
Write-Host "Admin token OK"
$adminHeaders = @{ Authorization = "Bearer $adminToken" }

# Test key 404 paths on both servers
$testPaths = @(
    "/his/healthRecord/list",
    "/his/healthRecord/",
    "/course/courseDomainName/list",
    "/course/courseDomainName/",
    "/ad/AdDyAccount/list",
    "/ad/adDomain/list",
    "/company/companyUser/list",
    "/companyUser/list",
    "/company/companyTagGroup/list",
    "/companyTagGroup/list",
    "/his/user/list",
    "/his/adv/list",
    "/store/healthRecord/list",
    "/system/menu/list",
    "/system/dict/type/list",
    "/system/user/list",
    "/monitor/online/list",
    "/admin/medical/indicator/page",
    "/admin/medical/report/page",
    "/ad/clickLog/list",
    "/qw/qwCompany/list",
    "/crm/customer/list",
    "/live/liveActivity/list"
)

Write-Host "`nPath | fs-company(8006) | fs-admin(8003)"
Write-Host "--- | --- | ---"
foreach ($path in $testPaths) {
    $companyCode = "?"
    $adminCode = "?"
    
    try {
        $resp = Invoke-WebRequest -Uri "$companyUrl$path" -Method GET -Headers $headers -UseBasicParsing -TimeoutSec 5
        $body = $resp.Content | ConvertFrom-Json
        $companyCode = "$($body.code)"
    } catch {
        $err = "$($_.Exception.Message)"
        if ($err -match "(\d{3})") { $companyCode = $Matches[1] } else { $companyCode = "ERR" }
    }
    
    try {
        $resp = Invoke-WebRequest -Uri "http://localhost:8003$path" -Method GET -Headers $adminHeaders -UseBasicParsing -TimeoutSec 5
        $body = $resp.Content | ConvertFrom-Json
        $adminCode = "$($body.code)"
    } catch {
        $err = "$($_.Exception.Message)"
        if ($err -match "(\d{3})") { $adminCode = $Matches[1] } else { $adminCode = "ERR" }
    }
    
    Write-Host "$path | $companyCode | $adminCode"
}
