"""
Tool groups for dynamic tool selection.

When using proxies with tool limitations, we can selectively load only relevant tools.
"""

from typing import List, Dict, Any
from .registry import TOOLS_SCHEMA, TOOL_FUNCTIONS


# === PRESET: Light Mode (6 core tools for proxy compatibility) ===
LIGHT_TOOLS_NAMES = [
    "get_daily_detailed_stats",
    "get_metric_history",
    "log_diet",
    "log_supplement",
    "sync_garmin",
    "search_web",  # Added for web search functionality
]

LIGHT_TOOLS = [t for t in TOOLS_SCHEMA if t["function"]["name"] in LIGHT_TOOLS_NAMES]
LIGHT_FUNCTIONS = {k: v for k, v in TOOL_FUNCTIONS.items() if k in LIGHT_TOOLS_NAMES}


# === PRESET: Standard Mode (10 tools) ===
STANDARD_TOOLS_NAMES = LIGHT_TOOLS_NAMES + [
    "get_activity_history",
    "get_manual_history",
    "log_alcohol",
    "log_feeling",
    "get_health_insights",
]

STANDARD_TOOLS = [t for t in TOOLS_SCHEMA if t["function"]["name"] in STANDARD_TOOLS_NAMES]
STANDARD_FUNCTIONS = {k: v for k, v in TOOL_FUNCTIONS.items() if k in STANDARD_TOOLS_NAMES}


# === PRESET: Full Mode (15 tools) ===
FULL_TOOLS_NAMES = STANDARD_TOOLS_NAMES + [
    "analyze_driver",
    "search_web",
    "sync_obsidian",
    "log_fasting",
    "get_aggregated_analysis",
]

FULL_TOOLS = [t for t in TOOLS_SCHEMA if t["function"]["name"] in FULL_TOOLS_NAMES]
FULL_FUNCTIONS = {k: v for k, v in TOOL_FUNCTIONS.items() if k in FULL_TOOLS_NAMES}


def get_tool_preset(mode: str = "light") -> tuple[List[Dict[str, Any]], Dict]:
    """
    Get tool preset by mode.

    Args:
        mode: 'light' (5 tools), 'standard' (10 tools), 'full' (15 tools), 'all' (21 tools)

    Returns:
        (tools_schema, tool_functions)
    """
    if mode == "light":
        return LIGHT_TOOLS, LIGHT_FUNCTIONS
    elif mode == "standard":
        return STANDARD_TOOLS, STANDARD_FUNCTIONS
    elif mode == "full":
        return FULL_TOOLS, FULL_FUNCTIONS
    elif mode == "all":
        return TOOLS_SCHEMA, TOOL_FUNCTIONS
    else:
        raise ValueError(f"Unknown mode: {mode}. Use 'light', 'standard', 'full', or 'all'")
