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

func newFindAllJobHandler(ctx *gin.Context) *FindAllJobHandler {
	return &FindAllJobHandler{
		req:  http_model.NewFindAllJobRequest(),
		resp: http_model.NewFindAllJobResponse(),
		ctx:  ctx,
	}
}

type FindAllJobHandler struct {
	req  *http_model.FindAllJobRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *FindAllJobHandler) getRequest() interface{} {
	return h.req
}
func (h *FindAllJobHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *FindAllJobHandler) getResponse() interface{} {
	return h.resp
}
func (h *FindAllJobHandler) run() {
	data, err := service.Job.FindJobByEnterpriseId(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
	}
	h.resp.Data = data
	h.resp.Status = 20000
	h.resp.Message = "ok"
}

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