#!/bin/bash
# 检查 backend 依赖是否完整安装

cd "$(dirname "$0")"

echo "=== 检查 Backend 依赖 ==="
echo ""

# 检查虚拟环境
if [ -d "../.venv" ]; then
    echo "✓ 找到虚拟环境: ../.venv"
    source ../.venv/bin/activate
elif [ -d ".venv" ]; then
    echo "✓ 找到虚拟环境: .venv"
    source .venv/bin/activate
else
    echo "⚠ 未找到虚拟环境，使用系统 Python"
fi

echo ""
echo "Python 路径: $(which python3)"
echo "Python 版本: $(python3 --version)"
echo ""

# 检查关键依赖
echo "检查关键依赖..."
python3 -c "import fastapi; print('✓ fastapi:', fastapi.__version__)" 2>&1 || echo "✗ fastapi 未安装"
python3 -c "import uvicorn; print('✓ uvicorn:', uvicorn.__version__)" 2>&1 || echo "✗ uvicorn 未安装"
python3 -c "from jose import jwt; print('✓ python-jose: 已安装')" 2>&1 || echo "✗ python-jose 未安装"
python3 -c "import pymysql; print('✓ pymysql:', pymysql.__version__)" 2>&1 || echo "✗ pymysql 未安装"
python3 -c "import redis; print('✓ redis:', redis.__version__)" 2>&1 || echo "✗ redis 未安装"
python3 -c "from cryptography.fernet import Fernet; print('✓ cryptography: 已安装')" 2>&1 || echo "✗ cryptography 未安装"

echo ""
echo "=== 尝试导入 api.main ==="
python3 -c "import api.main; print('✓ api.main 导入成功')" 2>&1 || echo "✗ api.main 导入失败"

echo ""
echo "=== 检查完成 ==="
echo ""
echo "如果缺少依赖，请运行："
echo "  pip install -r backend/requirements.txt"
echo ""
echo "或者激活虚拟环境后运行："
echo "  source .venv/bin/activate"
echo "  pip install -r backend/requirements.txt"
