# =============================================================================
# WEBMoney - Servidor de Desenvolvimento Local
# =============================================================================

param(
    [switch]$FrontendOnly,
    [switch]$BackendOnly
)

$ProjectRoot = "c:\Users\marco\OneDrive\Documents\WebMoney"

Write-Host ""
Write-Host "╔═══════════════════════════════════════════════════════╗" -ForegroundColor Cyan
Write-Host "║       WEBMoney - Ambiente de Desenvolvimento          ║" -ForegroundColor Cyan
Write-Host "╚═══════════════════════════════════════════════════════╝" -ForegroundColor Cyan
Write-Host ""

if (-not $FrontendOnly) {
    Write-Host "[Backend] " -NoNewline -ForegroundColor Yellow
    Write-Host "Iniciando em http://localhost:8000" -ForegroundColor White
    
    Start-Process powershell -ArgumentList "-NoExit", "-Command", @"
        `$Host.UI.RawUI.WindowTitle = 'WebMoney Backend'
        Set-Location '$ProjectRoot\backend'
        Write-Host 'Laravel Development Server' -ForegroundColor Green
        Write-Host 'http://localhost:8000' -ForegroundColor Cyan
        Write-Host ''
        php artisan serve --host=localhost --port=8000
"@
}

if (-not $BackendOnly) {
    Start-Sleep 1
    
    Write-Host "[Frontend] " -NoNewline -ForegroundColor Yellow
    Write-Host "Iniciando em http://localhost:5173" -ForegroundColor White
    
    Start-Process powershell -ArgumentList "-NoExit", "-Command", @"
        `$Host.UI.RawUI.WindowTitle = 'WebMoney Frontend'
        Set-Location '$ProjectRoot\frontend'
        Write-Host 'Vite Development Server' -ForegroundColor Green
        Write-Host 'http://localhost:5173' -ForegroundColor Cyan
        Write-Host ''
        npm run dev
"@
}

Write-Host ""
Write-Host "═══════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host "  Servidores iniciados em janelas separadas:" -ForegroundColor White

if (-not $FrontendOnly) {
    Write-Host "    Backend:  " -NoNewline; Write-Host "http://localhost:8000/api" -ForegroundColor Cyan
}
if (-not $BackendOnly) {
    Write-Host "    Frontend: " -NoNewline; Write-Host "http://localhost:5173" -ForegroundColor Cyan
}

Write-Host ""
Write-Host "  Comandos disponíveis:" -ForegroundColor White
Write-Host "    .\scripts\quick-deploy.ps1 -Target frontend" -ForegroundColor Gray
Write-Host "    .\scripts\quick-deploy.ps1 -Target backend" -ForegroundColor Gray
Write-Host "    .\scripts\release.ps1 -VersionType patch -ChangeDescription 'desc'" -ForegroundColor Gray
Write-Host ""
