# Start-DBAOpsAPI.ps1
# RHOYLLE INNOVATION EMPIRE LLC - Start Mobile REST API
# Cross-platform: Runs Node.js API (Windows, Linux, Mac)
# Requires: Node.js 14+

param(
    [int]$Port = 9002,
    [switch]$Background
)

$apiDir = Join-Path $PSScriptRoot "..\WebDashboard\api"
if (-not (Test-Path $apiDir)) {
    Write-Error "API folder not found: $apiDir"
    exit 1
}

$serverJs = Join-Path $apiDir "server.js"
if (-not (Test-Path $serverJs)) {
    Write-Error "server.js not found"
    exit 1
}

$env:DBAOPS_API_PORT = $Port
Write-Host "Starting DBAOps Dashboard API on port $Port..." -ForegroundColor Cyan
Write-Host "  API: http://localhost:$Port/api" -ForegroundColor Gray

if ($Background) {
    Start-Process -FilePath "node" -ArgumentList $serverJs -WorkingDirectory $apiDir -WindowStyle Hidden
    Write-Host "  API started in background" -ForegroundColor Green
} else {
    Set-Location $apiDir
    node $serverJs
}
