package User

import (
	"net/http"
	jwtutils "wechat-api/internal/utils/jwt"

	"github.com/zeromicro/go-zero/rest/httpx"

	"wechat-api/internal/logic/User"
	"wechat-api/internal/svc"
)

// swagger:route post /gpts/user/balance User GetGptsUserBalance
//
// Get user balance information | 获取用户余额信息
//
// Get user balance information | 获取用户余额信息
//
// Responses:
//  200: UserBalanceResp

func GetGptsUserBalanceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		l := User.NewGetGptsUserBalanceLogic(r.Context(), svcCtx)
		tokenStr := jwtutils.StripBearerPrefixFromToken(r.Header.Get("Authorization"))
		resp, err := l.GetGptsUserBalance(tokenStr)
		if err != nil {
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			httpx.OkJsonCtx(r.Context(), w, resp)
		}
	}
}
