# DBAOps Sovereign™ — Run (API + Dashboard)
# Run from repository root

$ErrorActionPreference = "Stop"
$root = (Get-Item $PSScriptRoot).Parent.FullName
Set-Location $root

# Copy .env.example to .env if .env doesn't exist
if (-not (Test-Path ".env")) {
    if (Test-Path ".env.example") {
        Copy-Item ".env.example" ".env"
        Write-Host "Created .env from .env.example — update SOVEREIGN_DB_CONNECTION for real SQL Server." -ForegroundColor Yellow
    }
}

# Ensure deps installed (root, API, and web — web needs react-scripts)
if (-not (Test-Path "node_modules") -or -not (Test-Path "src\api\node_modules") -or -not (Test-Path "src\web\node_modules")) {
    Write-Host "Installing dependencies first..." -ForegroundColor Yellow
    & "$PSScriptRoot\install.ps1"
}

Write-Host "DBAOps Sovereign™ — Starting API and Dashboard..." -ForegroundColor Cyan
Write-Host "  API:      http://localhost:3041" -ForegroundColor Gray
Write-Host "  Dashboard: http://localhost:3000" -ForegroundColor Gray
Write-Host ""

$env:BROWSER = "none"
npm start
