"""Slack search tools — search messages across workspace."""

from slack_mcp_server.client import SlackClient
from slack_mcp_server.config import SlackConfig


def register_search_tools(app, config: SlackConfig):
    """Register search tools with the FastMCP app."""

    @app.tool()
    async def slack_search_messages(query: str, count: int = 10) -> dict:
        """Search for messages across the Slack workspace.

        Args:
            query: Search query (supports Slack operators: 'from:@user', 'in:#channel', 'has:link', 'before:2024-01-01', 'after:2024-01-01')
            count: Maximum results to return (1-50, default: 10)
        """
        count = min(max(count, 1), 50)
        async with SlackClient(bot_token=config.bot_token, user_token=config.user_token) as client:
            messages = await client.search_messages(query=query, count=count)
            return {"success": True, "query": query, "count": len(messages), "messages": messages}
