#!/bin/bash
#
# SDK 状态检查
# 用法：./scripts/check_sdk.sh
#

echo "============================================"
echo "  工作手机 SDK 状态检查"
echo "============================================"
echo ""

# SDK 健康
echo "[1] SDK 服务 (localhost:8899)"
if curl -s http://localhost:8899/health > /dev/null 2>&1; then
    curl -s http://localhost:8899/health | python3 -c "
import json,sys
d=json.load(sys.stdin)
print('  ✅ 运行中')
print(f'  devices_online={d.get(\"devices_online\",0)}')
print(f'  adb_devices={d.get(\"adb_devices\",0)}')
print(f'  adb_serials={d.get(\"adb_serials\",[])}')
" 2>/dev/null || echo "  ✅ 运行中"
else
    echo "  ❌ 未运行"
fi
echo ""

# ADB 设备
echo "[2] ADB 设备"
if command -v adb &> /dev/null; then
    if adb devices 2>/dev/null | grep -q "device$"; then
        adb devices | grep "device$" | while read line; do echo "  ✅ $line"; done
    else
        echo "  ⚠️ 无设备"
    fi
else
    echo "  ⚠️ adb 未安装"
fi
echo ""

# 存客宝后端（可选）
echo "[3] 存客宝后端 (localhost:8081)"
if curl -s -X POST http://localhost:8081/v1/auth/login -H "Content-Type: application/json" -d '{"account":"15880802661","password":"kr123456","typeId":1}' 2>/dev/null | grep -q '"code":200'; then
    echo "  ✅ 运行中（登录成功）"
else
    echo "  ⚠️ 未运行或登录失败"
fi
echo ""

echo "============================================"
