#!/bin/bash
# 验证所有依赖是否正确安装
# 此脚本在容器内运行，验证构建是否正确

echo "🔍 开始验证依赖安装..."
echo ""

EXIT_CODE=0

# 检查关键包是否能导入
check_python_package() {
    package=$1
    echo -n "  Checking $package... "
    if python3 -c "import $package" 2>/dev/null; then
        echo "✅ OK"
    else
        echo "❌ FAILED"
        EXIT_CODE=1
    fi
}

# 检查关键基础包
echo "📦 检查基础依赖包:"
check_python_package vnpy
check_python_package numpy
check_python_package pandas
check_python_package scipy
check_python_package matplotlib
check_python_package fastapi
check_python_package uvicorn
check_python_package jupyterlab
check_python_package voila

echo ""
echo "📦 检查额外依赖包:"
check_python_package akshare

echo ""
# 检查命令是否存在
check_command() {
    cmd=$1
    echo -n "  Checking $cmd... "
    if command -v $cmd >/dev/null 2>&1; then
        echo "✅ OK ($(which $cmd))"
    else
        echo "❌ NOT FOUND"
        EXIT_CODE=1
    fi
}

echo "🛠️  检查系统命令:"
check_command code-server
check_command jupyter

echo ""
if [ $EXIT_CODE -eq 0 ]; then
    echo "✅ 所有依赖验证通过!"
else
    echo "❌ 部分依赖验证失败，请检查!"
fi

exit $EXIT_CODE
