"""
成就系统查询处理模块

处理成就系统查询命令，显示已解锁成就和进度。
"""

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

from ..utils import get_gacha_system
from ..utils import format_user_mention

logger = nonebot.logger


async def handle_achievement(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()
    achievements = await gacha_system.get_user_achievements(user_id)
    
    if not achievements:
        await event.finish("您还没有解锁任何成就哦~ 继续抽卡吧！")
    
    msg = f"🏅 {format_user_mention(user_id, user_name)} 的成就：\n\n"
    
    for ach in achievements:
        name = ach.get("name", "未知成就")
        desc = ach.get("description", "")
        reward = ach.get("reward", 0)
        claimed = ach.get("claimed", False)
        
        status = "✅已领取" if claimed else "🎁可领取"
        msg += f"🎖️ {name}\n   {desc}\n   奖励：{reward} {status}\n\n"
    
    await event.send(msg.strip())
