$ErrorActionPreference = "Stop"
$ProjectRoot = Split-Path -Parent $PSScriptRoot
$FrontendPath = Join-Path $ProjectRoot "frontend"
$FrontendJob = Start-Job -ScriptBlock {
    param($WorkingDirectory)
    Set-Location $WorkingDirectory
    pnpm dev
} -ArgumentList $FrontendPath

Push-Location (Join-Path $ProjectRoot "backend")
try {
    Write-Host "H5：http://127.0.0.1:5173"
    Write-Host "管理后台：http://127.0.0.1:5174"
    Write-Host "后端API：http://127.0.0.1:8000/docs"
    uv run uvicorn zbt.main:app --host 127.0.0.1 --port 8000 --reload
}
finally {
    Pop-Location
    Stop-Job -Job $FrontendJob -ErrorAction SilentlyContinue
    Remove-Job -Job $FrontendJob -Force -ErrorAction SilentlyContinue
}
