package user

import (
	"net/http"

	"git.i2edu.net/i2/go-zero/rest/httpx"
	"git.i2edu.net/i2/i2-bill-api/internal/logic/user"
	"git.i2edu.net/i2/i2-bill-api/internal/svc"
	"git.i2edu.net/i2/i2-bill-api/internal/utils"
)

func JzQrCodeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		uid, skey, err := ctx.GetClaims(r)
		if err != nil {
			httpx.OkJson(w, utils.ReturnHTTPFail(err))
			return
		}
		l := user.NewJzQrCodeLogic(r.Context(), ctx)
		l.UserId = uid
		l.SessionKey = skey
		resp, err := l.JzQrCode()
		if err != nil {
			httpx.OkJson(w, utils.ReturnHTTPFail(err))
		} else {
			httpx.OkJson(w, utils.ReturnHTTPSuccess(resp))
		}
	}
}
