package handler

import (
	"youngee_b_api/consts"
	"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"
)

/*
// WrapSendCodeHandler
// @BasePath /youngee/m/
// Codelogin godoc
// @Summary login 登录
// @Schemes
// @Description 输入手机号和验证码，并登录
// @Accept json
// @Produce json
// @Param req body http_model.CodeLoginRequest true "登录输入内容请求参数结构体"
// @Success 200 {object} http_model.CommonResponse{data=http_model.CodeLoginData} "登录返回相应结构体"
// @Router /login [post]
*/

func WrapCodeLoginHandler(ctx *gin.Context) {
	handler := newCodeLoginHandler(ctx)
	baseRun(handler)
}

func newCodeLoginHandler(ctx *gin.Context) *CodeLoginHandler {
	return &CodeLoginHandler{
		req:  http_model.NewCodeLoginRequest(),
		resp: http_model.NewCodeLoginResponse(),
		ctx:  ctx,
	}
}

type CodeLoginHandler struct {
	req  *http_model.CodeLoginRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *CodeLoginHandler) getRequest() interface{} {
	return h.req
}

func (h *CodeLoginHandler) getContext() *gin.Context {
	return h.ctx
}

func (h *CodeLoginHandler) getResponse() interface{} {
	return h.resp
}

func (h *CodeLoginHandler) run() {
	msg, userData, err := service.LoginAuth.AuthCode(h.ctx, h.req.Phone, h.req.Code)
	if err != nil {
		logrus.Errorf("[CodeLoginHandler] call AuthCode err:%+v\n", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, msg)
		log.Info("login fail,req:%+v", h.req)
		return
	}
	var data *http_model.CodeLoginData
	data = userData
	// h.resp.Message = "登陆成功"
	h.resp.Data = data
}

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