"""
我的抽卡统计处理模块

处理用户的个人抽卡统计查询命令。
"""

from nonebot.adapters.onebot.v11 import Bot, MessageEvent, GroupMessageEvent
import nonebot

from ..utils import get_gacha_system
from .. import formatters

logger = nonebot.logger


async def handle_stats(bot: Bot, event: MessageEvent, state: dict):
    """处理我的抽卡统计命令"""
    user_id = str(event.user_id)
    user_name = event.sender.card or event.sender.nickname or "未知用户"
    
    gacha_system = get_gacha_system()
    stats = await gacha_system.get_user_stats(user_id)
    
    if not stats or stats.get("total_draws", 0) == 0:
        await event.finish("您还没有抽卡记录哦~")
    
    msg = formatters.format_user_stats(stats, user_id, user_name)
    await event.send(msg)
