"""Slack reaction tools — add and remove emoji reactions."""

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


def register_reaction_tools(app, config: SlackConfig):
    """Register reaction tools with the FastMCP app."""

    @app.tool()
    async def slack_add_reaction(channel: str, timestamp: str, emoji: str) -> dict:
        """Add an emoji reaction to a Slack message.

        Args:
            channel: Channel ID where the message is (e.g., 'C01234ABCDE')
            timestamp: Message timestamp to react to (e.g., '1234567890.123456')
            emoji: Emoji name without colons (e.g., 'thumbsup', 'heart', 'rocket')
        """
        async with SlackClient(bot_token=config.bot_token, user_token=config.user_token) as client:
            result = await client.add_reaction(channel=channel, timestamp=timestamp, name=emoji)
            return {"success": True, "emoji": emoji, "message_ts": timestamp}

    @app.tool()
    async def slack_remove_reaction(channel: str, timestamp: str, emoji: str) -> dict:
        """Remove an emoji reaction from a Slack message.

        Args:
            channel: Channel ID where the message is
            timestamp: Message timestamp to remove reaction from
            emoji: Emoji name to remove (e.g., 'thumbsup')
        """
        async with SlackClient(bot_token=config.bot_token, user_token=config.user_token) as client:
            result = await client.remove_reaction(channel=channel, timestamp=timestamp, name=emoji)
            return {"success": True, "emoji": emoji, "removed": True}

    @app.tool()
    async def slack_pin_message(channel: str, timestamp: str) -> dict:
        """Pin a message in a Slack channel.

        Args:
            channel: Channel ID (e.g., 'C01234ABCDE')
            timestamp: Message timestamp to pin (e.g., '1234567890.123456')
        """
        async with SlackClient(bot_token=config.bot_token, user_token=config.user_token) as client:
            result = await client.pin_message(channel=channel, timestamp=timestamp)
            return {"success": True, "pinned": True, "channel": channel, "timestamp": timestamp}

    @app.tool()
    async def slack_unpin_message(channel: str, timestamp: str) -> dict:
        """Unpin a message from a Slack channel.

        Args:
            channel: Channel ID
            timestamp: Message timestamp to unpin
        """
        async with SlackClient(bot_token=config.bot_token, user_token=config.user_token) as client:
            result = await client.unpin_message(channel=channel, timestamp=timestamp)
            return {"success": True, "unpinned": True, "channel": channel}
