@echo off
title OpenFin Intelligence - Launcher
echo.
echo  ============================================
echo    OpenFin Intelligence Cockpit v2.0
echo  ============================================
echo.

echo  Liberation des ports...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :8000 ^| findstr LISTENING') do (
    taskkill /PID %%a /F >nul 2>&1
)
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :5173 ^| findstr LISTENING') do (
    taskkill /PID %%a /F >nul 2>&1
)
echo  Ports 8000 et 5173 liberes.
echo.

echo  Demarrage du backend (port 8000)...
start "OpenFin Backend" cmd /k "cd /d %~dp0backend && (if not exist venv python -m venv venv) && call venv\Scripts\activate.bat && pip install -r requirements.txt -q && python -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload"

timeout /t 5 /nobreak >nul

echo  Demarrage du frontend (port 5173)...
start "OpenFin Frontend" cmd /k "cd /d %~dp0frontend && (if not exist node_modules npm install) && npm run dev"

timeout /t 5 /nobreak >nul

echo  Ouverture du navigateur...
start http://localhost:5173

echo.
echo  Cockpit disponible sur: http://localhost:5173
echo  API disponible sur:     http://localhost:8000/docs
echo.
