package app

import (
    "net/http"

    "bindbox-game/internal/pkg/core"
)

type userStatsResponse struct {
    ItemCardCount int64 `json:"item_card_count"`
    CouponCount   int64 `json:"coupon_count"`
    PointsBalance int64 `json:"points_balance"`
}

// GetUserStats 获取用户统计
// @Summary 获取用户统计
// @Description 返回当前登录用户的道具卡数量、优惠券数量、积分余额
// @Tags APP端.用户
// @Accept json
// @Produce json
// @Param user_id path integer true "用户ID"
// @Security LoginVerifyToken
// @Success 200 {object} userStatsResponse
// @Failure 400 {object} code.Failure "参数错误"
// @Failure 401 {object} code.Failure "未授权"
// @Failure 500 {object} code.Failure "服务器内部错误"
// @Router /api/app/users/{user_id}/stats [get]
func (h *handler) GetUserStats() core.HandlerFunc {
    return func(ctx core.Context) {
        userID := int64(ctx.SessionUserInfo().Id)
        stats, err := h.user.GetUserStats(ctx.RequestContext(), userID)
        if err != nil {
            ctx.AbortWithError(core.Error(http.StatusBadRequest, 10010, err.Error()))
            return
        }
        rsp := &userStatsResponse{
            ItemCardCount: stats.ItemCardCount,
            CouponCount:   stats.CouponCount,
            PointsBalance: stats.PointsBalance,
        }
        ctx.Payload(rsp)
    }
}