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 WrapUpdateAccountInfoHandler(ctx *gin.Context) {
	handler := newUpdateAccountInfoHandler(ctx)
	baseRun(handler)
}

func newUpdateAccountInfoHandler(ctx *gin.Context) *UpdateAccountInfoHandler {
	return &UpdateAccountInfoHandler{
		req:  http_model.NewUpdateAccountInfoRequest(),
		resp: http_model.NewUpdateAccountInfoResponse(),
		ctx:  ctx,
	}
}

type UpdateAccountInfoHandler struct {
	req  *http_model.UpdateAccountInfoRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *UpdateAccountInfoHandler) getRequest() interface{} {
	return h.req
}
func (h *UpdateAccountInfoHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *UpdateAccountInfoHandler) getResponse() interface{} {
	return h.resp
}
func (h *UpdateAccountInfoHandler) run() {
	data, tag, err := service.LoginAuth.UpdateEnterpriseAccountInfo(h.ctx, h.req)
	if err != nil {
		logrus.Errorf("[UpdateSupplierAccountInfo] call SetSession err:%+v\n", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, err.Error())
		log.Info("UpdateSupplierAccountInfo fail,req:%+v", h.req)
		h.resp.Message = err.Error()
		h.resp.Status = 40000
		return
	}
	if tag == 1 {
		h.resp.Message = "验证码校验错误"
		h.resp.Status = 34000
		return
	}
	if tag == 2 {
		h.resp.Message = "手机号已经被其他主账号绑定"
		h.resp.Status = 35000
		return
	}
	if tag == 3 {
		h.resp.Message = "手机号已经被其他子账号绑定"
		h.resp.Status = 36000
		return
	}
	h.resp.Data = data
	h.resp.Status = 20000
	h.resp.Message = "ok"
}

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