package handler

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

func WrapPreDataListHandler(ctx *gin.Context) {
	handler := newPreDataListHandler(ctx)
	baseRun(handler)
}

func newPreDataListHandler(ctx *gin.Context) *PreDataListHandler {
	return &PreDataListHandler{
		req:  http_model.NewPreDataListRequest(),
		resp: http_model.NewPreDataListResponse(),
		ctx:  ctx,
	}
}

type PreDataListHandler struct {
	req  *http_model.PreDataListRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h PreDataListHandler) getRequest() interface{} {
	return h.req
}
func (h PreDataListHandler) getContext() *gin.Context {
	return h.ctx
}
func (h PreDataListHandler) getResponse() interface{} {
	return h.resp
}
func (h PreDataListHandler) run() {
	data := http_model.PreDataListRequest{}
	data = *h.req
	res, err := service.Task.GetPreDataList(h.ctx, data)
	if err != nil {
		logrus.Errorf("[GetPreDataList] call GetPreDataList err:%+v\n", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorParamCheck, "")
		logrus.Info("GetPreDataList fail,req:%+v", h.req)
		return
	}
	h.resp.Message = "成功查询数据待传列表"
	h.resp.Data = res
	h.resp.Status = consts.ErrorSuccess
}

func (h PreDataListHandler) checkParam() error {
	return nil
}
