"""Activities, statuses, project tags metadata."""

from cerebro_mcp.connection import execute
from cerebro_mcp.converters import activity_to_dict, status_to_dict, tag_to_dict


def register(mcp):

    @mcp.tool()
    async def get_activities() -> str:
        """Получить все виды деятельности (activities) в Universe."""
        try:
            raw = await execute("activities")
            acts = [activity_to_dict(a) for a in (raw or [])]
            return str(acts)
        except Exception as e:
            return f"Ошибка: {e}"

    @mcp.tool()
    async def get_statuses() -> str:
        """Получить все статусы Universe."""
        try:
            raw = await execute("statuses")
            sts = [status_to_dict(s) for s in (raw or [])]
            return str(sts)
        except Exception as e:
            return f"Ошибка: {e}"

    @mcp.tool()
    async def get_project_tags(project_id: str) -> str:
        """Получить все теги (кастомные поля) проекта. Нужно для set_tag_value()."""
        try:
            pid = int(project_id)
            raw = await execute("project_tags", pid)
            tags = [tag_to_dict(t) for t in (raw or [])]
            return str(tags)
        except Exception as e:
            return f"Ошибка: {e}"
