"""Attachment tools."""

from cerebro_mcp.connection import execute
from cerebro_mcp.converters import attachment_to_dict


def register(mcp):

    @mcp.tool()
    async def get_task_attachments(task_id: str) -> str:
        """Получить все вложения задачи (файлы, тамбнейлы, линки). Удалённые отфильтрованы."""
        try:
            tid = int(task_id)
            raw = await execute("task_attachments", tid)
            atts = [attachment_to_dict(a) for a in (raw or []) if a[2] == 0]
            return str(atts)
        except Exception as e:
            return f"Ошибка: {e}"

    @mcp.tool()
    async def get_message_attachments(message_id: str) -> str:
        """Получить вложения конкретного сообщения."""
        try:
            mid = int(message_id)
            raw = await execute("message_attachments", mid)
            atts = [attachment_to_dict(a) for a in (raw or []) if a[2] == 0]
            return str(atts)
        except Exception as e:
            return f"Ошибка: {e}"
