# 健康管家 - 一键启动
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "  健康管家开发环境启动" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan

# 1. PostgreSQL
Write-Host "`n[1/3] 启动 PostgreSQL..." -ForegroundColor Yellow
$pgBin = "D:\PostgreSQL\18\pgsql\bin"
$pgData = "D:\PostgreSQL\18\pgsql\data"
try {
    & "$pgBin\pg_ctl.exe" -D $pgData start 2>$null
    Write-Host "  PostgreSQL OK" -ForegroundColor Green
} catch {
    Write-Host "  PostgreSQL 已在运行或启动失败" -ForegroundColor Gray
}

# 2. Backend
Write-Host "`n[2/3] 启动后端..." -ForegroundColor Yellow
$backendDir = "D:\健康管家\backend\src\Health.WebApi"
Start-Process cmd -ArgumentList "/k cd /d `"$backendDir`" && dotnet run --urls http://localhost:5000"
Write-Host "  后端窗口已打开，等待就绪..." -ForegroundColor Green

# 3. Frontend
Write-Host "`n[3/3] 等待 15 秒后启动前端..." -ForegroundColor Yellow
Start-Sleep 15
$frontendDir = "D:\健康管家\health_app"
$flutter = "C:\Users\明年\flutter\bin\flutter.bat"
Start-Process cmd -ArgumentList "/k cd /d `"$frontendDir`" && `"$flutter`" run -d edge"
Write-Host "  前端窗口已打开" -ForegroundColor Green

Write-Host "`n========================================" -ForegroundColor Cyan
Write-Host "  后端: http://localhost:5000" -ForegroundColor Green
Write-Host "  前端: 等待浏览器自动打开" -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "`n窗口可以关闭，不会影响运行中的服务"
Read-Host "按 Enter 退出"
