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

"""
@Project   : lq-agent-api
@File      : types.py
@IDE       : VsCode
@Date      : 2026-01-08

工作流类型定义模块

本模块定义了工作流相关的类型，避免循环导入问题。
"""

from typing import Optional, TypedDict, Annotated, List, Dict, Any
from langchain_core.messages import BaseMessage
from langgraph.graph.message import add_messages


class AIReviewState(TypedDict):
    """AI审查工作流状态"""

    file_id: str
    callback_task_id: str
    file_name: str
    user_id: str
    structured_content: Dict[str, Any]
    review_results: Optional[Dict[str, Any]]
    current_stage: str
    status: str
    error_message: Optional[str]
    progress_manager: Optional[Any]
    messages: Annotated[List[BaseMessage], add_messages]


class TaskChainState(TypedDict):
    """任务链工作流状态（外层LangGraph状态）"""

    # 任务基本信息
    file_id: str
    callback_task_id: str
    user_id: str
    file_name: str
    file_type: str
    file_content: bytes

    # 任务状态管理
    current_stage: str  # 当前阶段: document_processing, ai_review, report_generation, complete
    overall_task_status: str  # 整体任务状态: processing, completed, failed, terminated
    stage_status: Dict[str, str]  # 各阶段状态: {"document": "completed", "ai_review": "processing", ...}

    # 各阶段结果
    document_result: Optional[Dict[str, Any]]  # 文档处理结果
    ai_review_result: Optional[Dict[str, Any]]  # AI审查结果
    report_result: Optional[Dict[str, Any]]  # 报告生成结果

    # 错误处理
    error_message: Optional[str]

    # 服务组件
    progress_manager: Optional[Any]
    task_file_info: Optional[Any]  # TaskFileInfo 实例

    # 消息列表
    messages: Annotated[List[BaseMessage], add_messages]
