from typing import List, Dict, Any, Optional
from langchain_core.tools import tool
import json

# We can use a global or context-based store for session-based items if needed,
# but for now we'll rely on the tool call payload being sent to the frontend.

@tool
async def add_inbox_task(type: str, title: str, description: str, options: List[str] = None) -> str:
    """
    Add a task to the Director's Inbox (Human-in-the-Loop).
    Use this when you need the user (Director) to make a decision, review something, or confirm a setting.
    
    Args:
        type: Task type. One of: 'decision' (for choices), 'review' (for checking content), 'notification' (for info).
        title: Short title of the task.
        description: Detailed description of what needs to be done.
        options: For 'decision' type, a list of choices (e.g. ["Fight", "Flight"]).
    
    Returns:
        Confirmation message.
    """
    # In a real system, this would save to a DB. 
    # Here, the tool call itself serves as the signal to the frontend.
    return f"[Inbox Task Added] {title} ({type})"

@tool
async def update_plan(steps: List[str], current_step_index: int) -> str:
    """
    Update the execution plan visible to the user.
    Call this at the beginning of a complex task (like writing a chapter) and update it as you progress.
    
    Args:
        steps: List of strings describing the steps (e.g. ["Analyze Context", "Draft Outline", "Write Scene"]).
        current_step_index: The 0-based index of the current step being executed.
    
    Returns:
        Confirmation message.
    """
    return f"[Plan Updated] Step {current_step_index + 1}/{len(steps)}: {steps[current_step_index] if steps and 0 <= current_step_index < len(steps) else 'Unknown'}"

@tool
async def ask_director(question: str) -> str:
    """
    Directly ask the Director (User) a question in the chat interface.
    Use this for conversational clarifications, not for structured tasks.
    
    Args:
        question: The question to ask.
    """
    return f"[Question Asked] {question}"
