# core/handlers/callback.py
from __future__ import annotations

from core.protocol import IncomingCallback, OutgoingMessage, SettingsAction


async def handle_confirm(event: IncomingCallback, auth_mgr, platform, chat_mgr, settings_mgr) -> list:
    action_id = event.payload.get("action_id", "unknown")
    return [OutgoingMessage(chat_id=event.chat_id, text=f"Действие подтверждено (id: {action_id}).")]


async def handle_cancel(event: IncomingCallback, auth_mgr, platform, chat_mgr, settings_mgr) -> list:
    action_id = event.payload.get("action_id", "unknown")
    return [OutgoingMessage(chat_id=event.chat_id, text=f"Действие отменено (id: {action_id}).")]


async def handle_toggle_skill(event: IncomingCallback, auth_mgr, platform, chat_mgr, settings_mgr) -> list:
    skill = event.payload.get("skill")
    enabled = event.payload.get("enabled", True)
    if not skill:
        return [OutgoingMessage(chat_id=event.chat_id, text="Ошибка: не указан навык.")]
    action = SettingsAction(action="toggle_skill", payload={"skill": skill, "enabled": enabled})
    await settings_mgr.apply(event.user_id, action)
    state = "включён" if enabled else "выключен"
    return [OutgoingMessage(chat_id=event.chat_id, text=f"Навык {skill} {state}.")]
