"""
Hello World Plugin - Test Plugin for DSS MCP Server

Simple plugin to validate the plugin loading system is working correctly.
"""

from typing import Dict, Any, List
from mcp import types


PLUGIN_METADATA = {
    "name": "Hello World Plugin",
    "version": "1.0.0",
    "author": "DSS Team",
    "description": "Simple test plugin to validate plugin system"
}


TOOLS = [
    types.Tool(
        name="hello_world",
        description="Simple hello world tool to test plugin loading",
        inputSchema={
            "type": "object",
            "properties": {
                "name": {
                    "type": "string",
                    "description": "Name to greet",
                    "default": "World"
                }
            }
        }
    ),
    types.Tool(
        name="plugin_status",
        description="Get status of the plugin system",
        inputSchema={
            "type": "object",
            "properties": {}
        }
    )
]


class PluginTools:
    """Handler for hello world plugin tools"""

    def __init__(self, **kwargs):
        self.call_count = 0

    async def execute_tool(self, name: str, arguments: Dict[str, Any]) -> List:
        """Execute tool by name"""
        self.call_count += 1

        if name == "hello_world":
            return await self._hello_world(arguments)
        elif name == "plugin_status":
            return await self._plugin_status(arguments)
        else:
            raise ValueError(f"Unknown tool: {name}")

    async def _hello_world(self, arguments: Dict[str, Any]) -> List[types.TextContent]:
        """Simple hello world implementation"""
        name = arguments.get("name", "World")

        message = (
            f"Hello, {name}!\n\n"
            f"✓ Plugin system is operational\n"
            f"✓ Dynamic loading works correctly\n"
            f"✓ Tool routing is functional\n"
            f"✓ Call count: {self.call_count}"
        )

        return [
            types.TextContent(
                type="text",
                text=message
            )
        ]

    async def _plugin_status(self, arguments: Dict[str, Any]) -> List[types.TextContent]:
        """Return plugin system status"""
        status = {
            "status": "operational",
            "plugin_name": PLUGIN_METADATA["name"],
            "plugin_version": PLUGIN_METADATA["version"],
            "tools_count": len(TOOLS),
            "call_count": self.call_count,
            "tools": [tool.name for tool in TOOLS]
        }

        import json
        return [
            types.TextContent(
                type="text",
                text=json.dumps(status, indent=2)
            )
        ]
