#!/bin/bash
# 快速测试陪练功能API

echo "============================================================"
echo "陪练功能快速测试"
echo "============================================================"

# 获取token
echo -e "\n1. 登录获取token..."
TOKEN=$(curl -s -X POST "http://localhost:8000/api/v1/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"admin123"}' \
  | python3 -c "import sys,json; data=json.load(sys.stdin); print(data['data']['token']['access_token'] if data['code']==200 else '')")

if [ -z "$TOKEN" ]; then
  echo "❌ 登录失败"
  exit 1
fi

echo "✅ 登录成功"

# 测试场景列表
echo -e "\n2. 测试场景列表..."
SCENES=$(curl -s "http://localhost:8000/api/v1/practice/scenes" \
  -H "Authorization: Bearer $TOKEN")

COUNT=$(echo $SCENES | python3 -c "import sys,json; data=json.load(sys.stdin); print(data['data']['total'] if data['code']==200 else 0)")

if [ "$COUNT" -gt 0 ]; then
  echo "✅ 成功获取 $COUNT 个场景"
else
  echo "❌ 获取场景失败"
  exit 1
fi

# 测试场景详情
echo -e "\n3. 测试场景详情..."
DETAIL=$(curl -s "http://localhost:8000/api/v1/practice/scenes/1" \
  -H "Authorization: Bearer $TOKEN")

NAME=$(echo $DETAIL | python3 -c "import sys,json; data=json.load(sys.stdin); print(data['data']['name'] if data['code']==200 else '')")

if [ -n "$NAME" ]; then
  echo "✅ 成功获取场景: $NAME"
else
  echo "❌ 获取场景详情失败"
  exit 1
fi

echo -e "\n============================================================"
echo "✅ 陪练功能API测试通过"
echo "============================================================"
echo ""
echo "📌 提示："
echo "  - 场景列表: http://localhost:3001/trainee/ai-practice-center"
echo "  - 后端API: http://localhost:8000/docs"
echo "  - 运行完整测试: python3 test_practice_api.py"
echo ""


