#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
增强版多群聊协调系统验证脚本
"""

import asyncio
import sys
import traceback

async def verify_enhanced_coordinator():
    """验证增强版协调器"""
    try:
        print("🧪 验证增强版多群聊协调系统")
        print("=" * 40)
        
        # 导入系统
        from enhanced_multi_chat_coordinator import EnhancedMultiChatCoordinator
        print("✅ 成功导入增强版协调器")
        
        # 创建实例
        coordinator = EnhancedMultiChatCoordinator()
        print("✅ 成功创建协调器实例")
        
        # 检查初始状态
        status = coordinator.get_enhanced_status()
        print(f"✅ 系统状态: {status['version']}")
        print(f"   - 群聊数量: {status['total_rooms']}")
        print(f"   - 消息总数: {status['total_messages']}")
        
        # 测试消息发送
        message = await coordinator.send_enhanced_message(
            "main_debate", "测试用户", "这是一条测试消息", tags=["测试"]
        )
        print(f"✅ 消息发送成功: {message['id']}")
        
        # 测试紧急消息处理
        urgent_message = await coordinator.send_enhanced_message(
            "main_debate", "紧急用户", "紧急情况需要立即处理！", tags=["紧急"]
        )
        print(f"🚨 紧急消息处理: {urgent_message['id']}")
        
        # 测试策略消息分发
        strategy_message = await coordinator.send_enhanced_message(
            "strategy_meeting", "策略制定者", "新策略已制定", tags=["策略"]
        )
        print(f"📋 策略消息分发: {strategy_message['id']}")
        
        # 获取最终状态
        final_status = coordinator.get_enhanced_status()
        print(f"\n📊 最终状态:")
        print(f"   - 总消息数: {final_status['total_messages']}")
        print(f"   - 性能数据: {final_status['performance']}")
        
        # 验证分析功能
        analytics = final_status['analytics']
        if analytics:
            for chat_id, data in analytics.items():
                if data['message_count'] > 0:
                    print(f"   - {chat_id}: {data['message_count']}条消息, 参与度{data['engagement_score']:.2f}")
        
        print("\n🎉 增强版多群聊协调系统验证完成！")
        print("✅ 所有功能正常运行")
        
        return True
        
    except Exception as e:
        print(f"❌ 验证失败: {e}")
        print("错误详情:")
        traceback.print_exc()
        return False

if __name__ == "__main__":
    success = asyncio.run(verify_enhanced_coordinator())
    
    if success:
        print("\n🎯 增强版多群聊协调系统 v2.1.0 部署成功！")
        print("📈 新增功能:")
        print("  • 智能消息分析和分类")
        print("  • 负载均衡和自动路由")
        print("  • 实时性能监控")
        print("  • 紧急消息升级机制")
        print("  • 策略消息自动分发")
        print("  • 群聊活跃度分析")
    else:
        print("\n❌ 部署失败，请检查错误信息")
        sys.exit(1)