package handler

import (
	"youngee_b_api/consts"
	"youngee_b_api/middleware"
	"youngee_b_api/model/http_model"
	"youngee_b_api/service"
	"youngee_b_api/util"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	log "github.com/sirupsen/logrus"
)

func WrapFindUserInfoHandler(ctx *gin.Context) {
	handler := newFindUserInfoHandler(ctx)
	baseRun(handler)
}

func newFindUserInfoHandler(ctx *gin.Context) *FindUserInfoHandler {
	return &FindUserInfoHandler{
		req:  http_model.NewFindUserInfoRequest(),
		resp: http_model.NewFindUserInfoResponse(),
		ctx:  ctx,
	}
}

type FindUserInfoHandler struct {
	req  *http_model.FindUserInfoRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *FindUserInfoHandler) getRequest() interface{} {
	return h.req
}
func (h *FindUserInfoHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *FindUserInfoHandler) getResponse() interface{} {
	return h.resp
}
func (h *FindUserInfoHandler) run() {
	auth := middleware.GetSessionAuth(h.ctx)
	//fmt.Printf("auth test %+v", auth)
	res, err := service.User.Find(h.ctx, auth.EnterpriseID, auth.ID)
	if err != nil {
		// 数据库查询失败，返回5001
		logrus.Errorf("[FindUserInfoHandler] call FindByID err:%+v\n", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
		log.Info("FindUserInfo fail,req:%+v", h.req)
		return
	}
	h.resp.Data = res
}
func (h *FindUserInfoHandler) checkParam() error {
	return nil
}
