
import requests
import json
import time

BASE_URL = "http://localhost:7891/api"

print("="*80)
print("  🎉 朝堂议政引擎 - 开通成功！")
print("="*80)

# 1. 测试列出官员
print("\n[1] 👥 列出官员...")
r = requests.get(f"{BASE_URL}/court-discuss/officials")
result = r.json()
if result.get('ok'):
    officials = list(result.get('officials', {}).keys())
    print("  成功！可用官员: " + ", ".join(officials))

# 2. 创建会话
print("\n[2] 🏛️ 创建议政会话...")
r = requests.post(
    f"{BASE_URL}/court-discuss/start",
    json={
        'topic': '如何建立一个稳定高效的量化交易系统？',
        'officials': ['zhongshu', 'menxia', 'shangshu', 'hubu']
    }
)
result = r.json()
session_id = None
if result.get('ok'):
    session_id = result.get('session_id')
    print("  成功！会话ID: " + str(session_id))

if not session_id:
    print("\n  创建会话失败")
    exit(1)

# 3. 等待一下
time.sleep(1)

# 4. 推进讨论
print("\n[3] 💬 推进讨论...")
r = requests.post(
    f"{BASE_URL}/court-discuss/advance",
    json={'sessionId': session_id}
)
result = r.json()
if result.get('ok'):
    print("  成功！第 " + str(result.get('round')) + " 轮讨论")
    msgs = result.get('new_messages', [])
    print("  新增 " + str(len(msgs)) + " 条消息")

# 5. 皇帝发言
time.sleep(1)
print("\n[4] 👑 皇帝发言...")
r = requests.post(
    f"{BASE_URL}/court-discuss/advance",
    json={
        'sessionId': session_id,
        'userMessage': '诸位爱卿的讨论很有见地，朕想听听关于风险控制方面的具体建议。'
    }
)
result = r.json()
if result.get('ok'):
    print("  成功！")

# 6. 获取会话详情
time.sleep(1)
print("\n[5] 📋 查看会话详情...")
r = requests.get(f"{BASE_URL}/court-discuss/session/{session_id}")
result = r.json()
if result.get('session_id'):
    print("  成功！")
    print("  议题: " + result.get('topic'))
    print("  轮数: " + str(result.get('round')))
    print("  状态: " + result.get('phase'))
    print("  消息总数: " + str(len(result.get('messages', []))))

# 7. 结束会话
time.sleep(1)
print("\n[6] 🏁 结束议政...")
r = requests.post(
    f"{BASE_URL}/court-discuss/conclude",
    json={'sessionId': session_id}
)
result = r.json()
if result.get('ok'):
    print("  成功！总结: " + str(result.get('summary')))

print("\n" + "="*80)
print("  ✅ 朝堂议政功能完全开通成功！")
print("="*80)
print("\n  🎊 现在你可以:")
print("  1. 访问看板: http://192.168.2.153:7891")
print("  2. 用API调用朝堂议政功能")
print("  3. 或等我给你做一个更好的UI！")
print("\n  📋 完整API列表:")
print("  - GET  /api/court-discuss/officials   - 列出官员")
print("  - POST /api/court-discuss/start       - 创建会话")
print("  - POST /api/court-discuss/advance     - 推进讨论")
print("  - GET  /api/court-discuss/session/{id} - 获取会话")
print("  - POST /api/court-discuss/conclude    - 结束议政")
print("  - GET  /api/court-discuss/list        - 列出会话")
print("  - GET  /api/court-discuss/fate        - 命运骰子")

