package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	log "github.com/sirupsen/logrus"
	"youngee_b_api/consts"
	"youngee_b_api/model/http_model"
	"youngee_b_api/service"
	"youngee_b_api/util"
)

func WrapUpdateContactInfoHandler(ctx *gin.Context) {
	handler := newUpdateContactInfoHandler(ctx)
	baseRun(handler)
}

func newUpdateContactInfoHandler(ctx *gin.Context) *UpdateContactInfoHandler {
	return &UpdateContactInfoHandler{
		req:  http_model.NewUpdateContactInfoRequest(),
		resp: http_model.NewUpdateContactInfoResponse(),
		ctx:  ctx,
	}
}

type UpdateContactInfoHandler struct {
	req  *http_model.UpdateContactInfoRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *UpdateContactInfoHandler) getRequest() interface{} {
	return h.req
}
func (h *UpdateContactInfoHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *UpdateContactInfoHandler) getResponse() interface{} {
	return h.resp
}
func (h *UpdateContactInfoHandler) run() {
	data, tag, err := service.LoginAuth.UpdateEnterpriseContactInfo(h.ctx, h.req)
	if err != nil {
		logrus.Errorf("[FindSubAccountByEnterpriseId] call SetSession err:%+v\n", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, err.Error())
		log.Info("FindSubAccountByEnterpriseId fail,req:%+v", h.req)
		h.resp.Message = err.Error()
		h.resp.Status = 40000
		return
	}
	if tag == true && data == nil {
		h.resp.Message = "验证码校验错误"
		h.resp.Status = 34000
		return
	}
	h.resp.Data = data
	h.resp.Status = 20000
	h.resp.Message = "ok"
}

func (h *UpdateContactInfoHandler) checkParam() error {
	return nil
}
