using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using MCPForUnity.Editor.Tools.MenuItems;
using MCPForUnity.Editor.Tools.Prefabs;
namespace MCPForUnity.Editor.Tools
{
///
/// Registry for all MCP command handlers (Refactored Version)
///
public static class CommandRegistry
{
// Maps command names (matching those called from Python via ctx.bridge.unity_editor.HandlerName)
// to the corresponding static HandleCommand method in the appropriate tool class.
private static readonly Dictionary> _handlers = new()
{
{ "manage_script", ManageScript.HandleCommand },
{ "manage_scene", ManageScene.HandleCommand },
{ "manage_editor", ManageEditor.HandleCommand },
{ "manage_gameobject", ManageGameObject.HandleCommand },
{ "manage_asset", ManageAsset.HandleCommand },
{ "read_console", ReadConsole.HandleCommand },
{ "manage_menu_item", ManageMenuItem.HandleCommand },
{ "manage_shader", ManageShader.HandleCommand},
{ "manage_prefabs", ManagePrefabs.HandleCommand},
};
///
/// Gets a command handler by name.
///
/// Name of the command handler (e.g., "HandleManageAsset").
/// The command handler function if found, null otherwise.
public static Func GetHandler(string commandName)
{
if (!_handlers.TryGetValue(commandName, out var handler))
{
throw new InvalidOperationException(
$"Unknown or unsupported command type: {commandName}");
}
return handler;
}
public static void Add(string commandName, Func handler)
{
_handlers.Add(commandName, handler);
}
}
}