"""
State type for the Deep Analysis Agent graph.
"""

import operator
from typing import Annotated, List, Dict, Optional

from langchain_core.messages import BaseMessage
from langgraph.graph.message import add_messages
from typing_extensions import TypedDict


class DeepAnalysisState(TypedDict):
    """
    State for the Deep Analysis Agent.
    profile_json holds a paragraph summary of the profile (built by orchestrator).
    max_turns is passed at invoke time (default from env DEEP_ANALYSIS_MAX_TURNS or 5).
    Multi-query: last_queries_batch is a list of {hypothesis, query}; failed_query_index + fixed_query for QueryFixer.
    """
    messages: Annotated[List[BaseMessage], add_messages]
    user_id: int
    profile_json: str
    last_query: Optional[str]
    last_queries_batch: Optional[List[Dict[str, str]]]
    last_error: Optional[str]
    failed_query_index: Optional[int]
    fixed_query: Optional[str]
    findings: Annotated[List[str], operator.add]
    llm_findings: Optional[List[str]]
    failed_investigations: Annotated[List[str], operator.add]
    retry_count: int
    tool_call_count: int
    context_near_limit: Optional[bool]
    batch_all_empty: Optional[bool]
    empty_turn_decision: Optional[str]
    final_analysis: Optional[str]
