@echo off
REM =============================
REM Script de Diagnóstico - BeeLife Social Post
REM =============================

echo =====================================
echo DIAGNÓSTICO DEL SERVIDOR BEELIFE
echo =====================================
echo.

echo [1/6] Verificando puertos en uso...
echo.
echo Puerto 3000 (Frontend):
netstat -an | findstr :3000 | findstr LISTENING
if %errorlevel% equ 0 (
    echo ✓ Puerto 3000 está ACTIVO
) else (
    echo ✗ Puerto 3000 NO está activo
)
echo.

echo Puerto 3080 (Vertex AI):
netstat -an | findstr :3080 | findstr LISTENING
if %errorlevel% equ 0 (
    echo ✓ Puerto 3080 está ACTIVO
) else (
    echo ✗ Puerto 3080 NO está activo
)
echo.

echo Puerto 8000 (OpenAI):
netstat -an | findstr :8000 | findstr LISTENING
if %errorlevel% equ 0 (
    echo ✓ Puerto 8000 está ACTIVO
) else (
    echo ✗ Puerto 8000 NO está activo
)
echo.

echo Puerto 3090 (Video):
netstat -an | findstr :3090 | findstr LISTENING
if %errorlevel% equ 0 (
    echo ✓ Puerto 3090 está ACTIVO
) else (
    echo ✗ Puerto 3090 NO está activo
)
echo.

echo [2/6] Verificando archivos de configuración...
if exist "public\js\config.js" (
    echo ✓ config.js existe
    echo Verificando contenido de config.js...
    findstr /C:"AppConfig" public\js\config.js >nul 2>&1
    if %errorlevel% equ 0 (
        echo ✓ config.js contiene AppConfig
    ) else (
        echo ✗ config.js está vacío o incorrecto
    )
) else (
    echo ✗ config.js NO existe
)

if exist "public\js\api.js" (
    echo ✓ api.js existe
) else (
    echo ✗ api.js NO existe
)

if exist "vertexai-proxy.js" (
    echo ✓ vertexai-proxy.js existe
) else (
    echo ✗ vertexai-proxy.js NO existe
)

if exist "veo2-proxy.js" (
    echo ✓ veo2-proxy.js existe
) else (
    echo ✗ veo2-proxy.js NO existe
)
echo.

echo [3/6] Verificando dependencias de Node.js...
if exist "node_modules" (
    echo ✓ node_modules existe
) else (
    echo ✗ node_modules NO existe - ejecuta 'npm install'
)

if exist "api\node_modules" (
    echo ✓ api/node_modules existe (para FastAPI)
) else (
    echo ⚠ api/node_modules NO existe - puede ser normal si usas Python
)
echo.

echo [4/6] Verificando procesos Node.js activos...
echo Procesos Node.js en ejecución:
tasklist | findstr node.exe
echo.

echo [5/6] Verificando conectividad local...
echo Probando conexión a servicios locales...

REM Probar con curl si está disponible
where curl >nul 2>nul
if %errorlevel% equ 0 (
    echo Probando Frontend (localhost:3000)...
    curl -s -o nul -w "Status: %%{http_code}\n" http://localhost:3000 2>nul || echo ✗ No responde
    
    echo Probando Vertex AI (localhost:3080)...
    curl -s -o nul -w "Status: %%{http_code}\n" http://localhost:3080 2>nul || echo ✗ No responde
    
    echo Probando OpenAI (localhost:8000)...
    curl -s -o nul -w "Status: %%{http_code}\n" http://localhost:8000 2>nul || echo ✗ No responde
    
    echo Probando Video (localhost:3090)...
    curl -s -o nul -w "Status: %%{http_code}\n" http://localhost:3090 2>nul || echo ✗ No responde
) else (
    echo ⚠ curl no está disponible - no se pueden probar las conexiones HTTP
)
echo.

echo [6/6] Información del sistema...
echo Dirección IP del servidor:
ipconfig | findstr "IPv4"
echo.

echo Variables de entorno importantes:
if defined VERTEX_PROJECT_ID (
    echo ✓ VERTEX_PROJECT_ID está definida: %VERTEX_PROJECT_ID%
) else (
    echo ⚠ VERTEX_PROJECT_ID no está definida
)

if defined GOOGLE_APPLICATION_CREDENTIALS (
    echo ✓ GOOGLE_APPLICATION_CREDENTIALS está definida: %GOOGLE_APPLICATION_CREDENTIALS%
) else (
    echo ⚠ GOOGLE_APPLICATION_CREDENTIALS no está definida
)
echo.

echo =====================================
echo RESUMEN DEL DIAGNÓSTICO
echo =====================================
echo.
echo Si todos los servicios están ACTIVOS:
echo - Frontend: http://TU_IP:3000/beelife-dashboard.html
echo - Generador: http://TU_IP:3000/beelife-image-generator.html
echo.
echo Si hay servicios INACTIVOS:
echo 1. Ejecuta: start-server-production.cmd
echo 2. Espera unos segundos y vuelve a ejecutar este diagnóstico
echo 3. Verifica que los puertos estén abiertos en el firewall
echo.
echo =====================================
pause 