from telegram import Update
from telegram.ext import ContextTypes

from bot.core.logger import logger


async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    user = update.effective_user
    chat = update.effective_chat
    logger.info(
        "Received /start from user_id=%s in chat_id=%s (type=%s)",
        user.id if user else "unknown",
        chat.id if chat else "unknown",
        chat.type if chat else "unknown",
    )
    await update.message.reply_text(
        f"Hello, {user.mention_html() if user else 'there'}! I'm your dota assistant bot.\n"
        "In groups, mention me with @botname or reply to my messages to chat.",
        parse_mode="HTML",
    )


async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    text = (
        "Available commands:\n"
        "/start - Introduction\n"
        "/help  - This message\n\n"
        "Dota 2 tracking:\n"
        "/addplayer <steam_id> [name] - Track a player\n"
        "/removeplayer <steam_id>     - Stop tracking a player\n"
        "/listplayers                 - Show tracked players\n\n"
        "Party gathering (groups only):\n"
        "/party [minutes]  - Invite group members to a Dota 2 party\n"
        "/accept           - Join the active party\n"
        "/decline          - Pass on the active party\n"
        "/abandon          - Cancel the active gather (host only)\n\n"
        "In groups, mention me or reply to my messages."
    )
    await update.message.reply_text(text)


async def error_handler(update: object, context: ContextTypes.DEFAULT_TYPE) -> None:
    logger.error(
        "Exception while handling an update: %s",
        context.error,
        exc_info=context.error,
    )
