# #region AssistantToolCapabilities [C:3] [TYPE Module] [SEMANTICS assistant, tool, capabilities, catalog]
# @BRIEF Handler for the "show_capabilities" tool — lists available assistant commands and examples.
# @LAYER API
# @RELATION DEPENDS_ON -> [AssistantToolRegistry]

from __future__ import annotations

from typing import Any

from sqlalchemy.orm import Session

from src.core.config_manager import ConfigManager
from src.core.logger import belief_scope, logger
from src.core.task_manager import TaskManager
from src.schemas.auth import User

from ._schemas import AssistantAction
from ._tool_registry import assistant_tool, get_catalog

_HUMAN_LABELS: dict[str, str] = {
    "create_branch": "Git: создание ветки",
    "commit_changes": "Git: коммит",
    "deploy_dashboard": "Git: деплой дашборда",
    "execute_migration": "Миграции: запуск переноса",
    "run_backup": "Бэкапы: запуск резервного копирования",
    "run_llm_validation": "LLM: валидация дашборда",
    "run_llm_documentation": "LLM: генерация документации",
    "get_task_status": "Статус: проверка задачи",
    "get_health_summary": "Здоровье: сводка по дашбордам",
}


# #region handle_show_capabilities [C:2] [TYPE Function]
@assistant_tool(
    operation="show_capabilities",
    domain="assistant",
    description="Show available assistant commands and examples",
    risk_level="safe",
    requires_confirmation=False,
)
@belief_scope("show_capabilities")
async def handle_show_capabilities(
    intent: dict[str, Any],
    current_user: User,
    task_manager: TaskManager,
    config_manager: ConfigManager,
    db: Session,
) -> tuple[str, str | None, list[AssistantAction]]:
    """Show available assistant commands and examples."""
    tools_catalog = get_catalog(current_user, config_manager, db)
    available = [
        _HUMAN_LABELS[t["operation"]]
        for t in tools_catalog
        if t["operation"] in _HUMAN_LABELS
    ]
    if not available:
        return ("Сейчас нет доступных для вас операций ассистента.", None, [])
    commands = "\n".join(f"- {item}" for item in available)
    text = (
        f"Вот что я могу сделать для вас:\n{commands}\n\n"
        "Пример: `запусти миграцию с dev на prod для дашборда 42`."
    )
    return (text, None, [])


# #endregion handle_show_capabilities
# #endregion AssistantToolCapabilities
