#!/usr/bin/env python
# -*- coding: utf-8 -*-

import asyncio
import sys
from pathlib import Path

current_dir = Path(__file__).parent.absolute()
project_root = current_dir.parent.parent
sys.path.insert(0, str(project_root))


# 导入必要的类
from core.base.task_models import TaskFileInfo
from core.construction_review.workflows.ai_review_workflow import AIReviewWorkflow


def create_test_file_info(review_item_config):
    """创建测试用 TaskFileInfo"""
    file_info = {
        'file_id': 'test_file_001',
        'user_id': 'test_user_001',
        'callback_task_id': 'test_task_001',
        'file_name': 'test_file.pdf',
        'file_type': 'pdf',
        'review_item_config': review_item_config,
        'review_config': [],
        'project_plan_type': '施工组织设计'
    }
    return TaskFileInfo(file_info)


def create_test_state():
    """创建测试用 AIReviewState"""
    return {
        'file_id': 'test_file_001',
        'callback_task_id': 'test_task_001',
        'user_id': 'test_user_001',
        'file_name': 'test_file.pdf',
        'structured_content': {'chunks': []},
        'review_results': None,
        'current_stage': 'ai_review_check_item',
        'status': 'processing',
        'error_message': None,
        'progress_manager': None,
        'messages': []
    }



async def test_case_03_multi_items():
    """测试用例03: 多个审查项"""
    print("\n=== 测试用例03: 多个审查项 ===")

    review_item_config = [
        "basis_timeliness_check",
        "basis_sensitive_word_check",
        "catalogue_sensitive_word_check",
        "catalogue_semantic_logic_check",
        "basis_timeliness_check",
        "overview_completeness_check"
    ]
    task_info = create_test_file_info(review_item_config)
    structured_content = {'chunks': []}

    print(f"输入: review_item_config={review_item_config}")

    try:
        workflow = AIReviewWorkflow(task_info, structured_content)
        state = create_test_state()

        result = await workflow._ai_review_node_check_item(state)

        print(f"输出: {result}")
        print(f"期望: 返回处理后的状态")
        print(f"PASS 方法调用成功")

    except Exception as e:
        print(f"ERROR: {str(e)}")
        print(f"FAIL 方法调用失败")


async def run_all_tests():
    """运行所有测试用例"""
    print("=" * 70)
    print("开始 _ai_review_node_check_item 方法测试")
    print("直接调用 AIReviewWorkflow._ai_review_node_check_item 方法")
    print("=" * 70)
    await test_case_03_multi_items()

    print("\n" + "=" * 70)
    print("测试完成")
    print("=" * 70)


def main():
    """主函数"""
    asyncio.run(run_all_tests())
    return 0


if __name__ == "__main__":
    sys.exit(main())
