"""Wait-for-subagents tool for orchestrator subagents."""

from typing import Any, TYPE_CHECKING

from nanobot.agent.tools.base import Tool

if TYPE_CHECKING:
    from nanobot.agent.subagent import SubagentManager


class WaitForSubagentsTool(Tool):
    """
    Tool to wait for child subagents to complete and collect their results.

    Use this after spawning multiple subagents to wait for all of them
    and get their results for synthesis.
    """

    def __init__(self, manager: "SubagentManager"):
        self._manager = manager

    @property
    def name(self) -> str:
        return "wait_for_subagents"

    @property
    def description(self) -> str:
        return (
            "Wait for one or more child subagents to complete and return their results. "
            "Use this after spawning subagents to collect all results before synthesizing. "
            "Blocks until all specified subagents finish."
        )

    @property
    def parameters(self) -> dict[str, Any]:
        return {
            "type": "object",
            "properties": {
                "task_ids": {
                    "type": "array",
                    "items": {"type": "string"},
                    "description": "List of task IDs to wait for (from spawn tool responses)",
                },
            },
            "required": ["task_ids"],
        }

    async def execute(self, task_ids: list[str], **kwargs: Any) -> str:
        """Wait for the specified subagents and return their results."""
        return await self._manager.wait_for(task_ids)
