@echo off
chcp 65001 >nul
echo ========================================
echo   Phase 2 测试环境检查
echo ========================================
echo.

set PASS=0
set FAIL=0
set WARN=0

echo [检查1/10] Docker Desktop 状态...
docker ps >nul 2>&1
if errorlevel 1 (
    echo ❌ Docker未运行
    set /a FAIL+=1
) else (
    echo ✅ Docker正常运行
    set /a PASS+=1
)
echo.

echo [检查2/10] PostgreSQL容器...
docker ps | findstr "postgres" >nul
if errorlevel 1 (
    echo ⚠️  PostgreSQL容器未运行
    set /a WARN+=1
) else (
    echo ✅ PostgreSQL容器运行中
    set /a PASS+=1
)
echo.

echo [检查3/10] Redis容器...
docker ps | findstr "redis" >nul
if errorlevel 1 (
    echo ⚠️  Redis容器未运行
    set /a WARN+=1
) else (
    echo ✅ Redis容器运行中
    set /a PASS+=1
)
echo.

echo [检查4/10] Python环境...
python --version >nul 2>&1
if errorlevel 1 (
    echo ❌ Python未安装
    set /a FAIL+=1
) else (
    python --version
    echo ✅ Python已安装
    set /a PASS+=1
)
echo.

echo [检查5/10] Node.js环境...
node --version >nul 2>&1
if errorlevel 1 (
    echo ❌ Node.js未安装
    set /a FAIL+=1
) else (
    node --version
    echo ✅ Node.js已安装
    set /a PASS+=1
)
echo.

echo [检查6/10] Python微服务文件...
if exist "extraction_service\main.py" (
    echo ✅ Python微服务文件存在
    set /a PASS+=1
) else (
    echo ❌ Python微服务文件缺失
    set /a FAIL+=1
)
echo.

echo [检查7/10] Python虚拟环境...
if exist "extraction_service\venv\" (
    echo ✅ Python虚拟环境存在
    set /a PASS+=1
) else (
    echo ⚠️  Python虚拟环境未创建
    echo    运行: cd extraction_service && .\install.bat
    set /a WARN+=1
)
echo.

echo [检查8/10] Backend依赖...
if exist "backend\node_modules\" (
    echo ✅ Backend依赖已安装
    set /a PASS+=1
) else (
    echo ⚠️  Backend依赖未安装
    echo    运行: cd backend && npm install
    set /a WARN+=1
)
echo.

echo [检查9/10] Frontend依赖...
if exist "frontend\node_modules\" (
    echo ✅ Frontend依赖已安装
    set /a PASS+=1
) else (
    echo ⚠️  Frontend依赖未安装
    echo    运行: cd frontend && npm install
    set /a WARN+=1
)
echo.

echo [检查10/10] Phase 2核心文件...
set FILES_OK=1

if not exist "frontend\src\components\chat\FullTextMode.tsx" (
    echo ❌ 缺失: FullTextMode.tsx
    set FILES_OK=0
)

if not exist "frontend\src\components\chat\DeepReadMode.tsx" (
    echo ❌ 缺失: DeepReadMode.tsx
    set FILES_OK=0
)

if not exist "frontend\src\components\chat\DocumentSelector.tsx" (
    echo ❌ 缺失: DocumentSelector.tsx
    set FILES_OK=0
)

if not exist "backend\src\clients\ExtractionClient.ts" (
    echo ❌ 缺失: ExtractionClient.ts
    set FILES_OK=0
)

if not exist "backend\src\services\tokenService.ts" (
    echo ❌ 缺失: tokenService.ts
    set FILES_OK=0
)

if %FILES_OK%==1 (
    echo ✅ Phase 2核心文件完整
    set /a PASS+=1
) else (
    echo ❌ Phase 2核心文件缺失
    set /a FAIL+=1
)
echo.

echo ========================================
echo   检查结果汇总
echo ========================================
echo ✅ 通过: %PASS%/10
echo ⚠️  警告: %WARN%/10
echo ❌ 失败: %FAIL%/10
echo.

if %FAIL% GTR 0 (
    echo 🔴 状态: 测试环境有严重问题
    echo.
    echo 建议:
    echo 1. 检查上方标记❌的项目
    echo 2. 安装缺失的软件或文件
    echo 3. 重新运行此脚本验证
    echo.
    goto END
)

if %WARN% GTR 0 (
    echo 🟡 状态: 测试环境基本就绪，有小问题
    echo.
    echo 建议:
    echo 1. 检查上方标记⚠️的项目
    echo 2. 按照提示完成安装
    echo 3. 或直接运行一键启动脚本尝试自动修复
    echo.
    goto END
)

echo 🟢 状态: 测试环境完全就绪！
echo.
echo ========================================
echo   可以开始测试了！
echo ========================================
echo.
echo 快速测试（30分钟）:
echo   打开: Phase2-快速测试清单.md
echo.
echo 完整测试（90分钟）:
echo   打开: Phase2-测试指南.md
echo.
echo 立即启动服务:
echo   运行: .\一键启动.bat
echo.

:END
pause









