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

type GetRecruitTime struct {
	ctx  *gin.Context
	req  *http_model.GetRecruitTimeRequest
	resp *http_model.CommonResponse
}

func (c GetRecruitTime) getContext() *gin.Context {
	return c.ctx
}

func (c GetRecruitTime) getResponse() interface{} {
	return c.resp
}

func (c GetRecruitTime) getRequest() interface{} {
	return c.req
}

func (c GetRecruitTime) run() {
	data := http_model.GetRecruitTimeRequest{}
	data = *c.req
	res, err := service.Task.GetRecruitTime(c.ctx, data)
	if err != nil {
		logrus.Errorf("[GetRecruitTime] call GetRecruitTime err:%+v\n", err)
		util.HandlerPackErrorResp(c.resp, consts.ErrorParamCheck, "")
		logrus.Info("GetRecruitTime fail,req:%+v", c.req)
		return
	}
	c.resp.Message = "成功查询招募截止时间"
	c.resp.Data = res
	c.resp.Status = consts.ErrorSuccess
}

func (c GetRecruitTime) checkParam() error {
	return nil
}

func newGetRecruitTimeHandler(ctx *gin.Context) *GetRecruitTime {
	return &GetRecruitTime{
		ctx:  ctx,
		req:  http_model.NewGetRecruitTimeRequest(),
		resp: http_model.NewGetRecruitTimeResponse(),
	}
}
