"""Slack file tools — upload files to channels."""

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


def register_file_tools(app, config: SlackConfig):
    """Register file tools with the FastMCP app."""

    @app.tool()
    async def slack_upload_file(channel: str, content: str, filename: str, title: str = "") -> dict:
        """Upload a text file to a Slack channel.

        Args:
            channel: Channel ID or name to upload to (e.g., 'C01234ABCDE' or '#general')
            content: Text content of the file
            filename: Name for the file (e.g., 'report.txt', 'code.py')
            title: Display title for the file (defaults to filename if empty)
        """
        async with SlackClient(bot_token=config.bot_token, user_token=config.user_token) as client:
            result = await client.upload_file(channels=channel, content=content, filename=filename, title=title)
            return {"success": True, "file_id": result["file_id"], "filename": result["filename"], "url": result["url"]}
