from typing import Dict, Any, Tuple, Callable, Optional
from app.core.tools.base import BaseToolPlugin

class MeshSyncControlTool(BaseToolPlugin):
    @property
    def name(self) -> str:
        return "mesh_sync_control"

    def prepare_task(self, args: Dict[str, Any], context: Dict[str, Any]) -> Tuple[Optional[Callable], Dict[str, Any]]:
        action_str = args.get("action", "start").upper()
        # Normalize mapping user string to assistant enum
        action_map = {
            "START": "START",
            "STOP": "STOP",
            "LOCK": "LOCK",
            "UNLOCK": "UNLOCK",
            "RESYNC": "RESYNC"
        }
        internal_action = action_map.get(action_str, "START")
        
        node_id = context.get("node_id")
        resolved_sid = context.get("session_id")
        assistant = context.get("assistant")
        
        if not assistant:
             return None, {"success": False, "error": "Orchestrator not available"}

        return assistant.control_sync, {
            "node_id": node_id, 
            "session_id": resolved_sid,
            "action": internal_action,
            "path": args.get("path", ".")
        }
