package handler

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

func WrapEndTaskHandler(ctx *gin.Context) {
	handler := newEndTaskHandler(ctx)
	baseRun(handler)
}

type EndTask struct {
	ctx  *gin.Context
	req  *http_model.EndTaskRequest
	resp *http_model.CommonResponse
}

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

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

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

func (c EndTask) run() {
	data := http_model.EndTaskRequest{}
	data = *c.req
	err := db.EndTask(c.ctx, data)
	if err != nil {
		logrus.Errorf("[GetSecTaskList] call EndTask err:%+v\n", err)
		util.HandlerPackErrorResp(c.resp, consts.ErrorParamCheck, "")
		logrus.Info("GetSecTaskList fail,req:%+v", c.req)
		return
	}
	c.resp.Message = "成功终止任务状态"
	c.resp.Status = consts.ErrorSuccess
}

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

func newEndTaskHandler(ctx *gin.Context) *EndTask {
	return &EndTask{
		ctx:  ctx,
		req:  http_model.NewEndTaskRequest(),
		resp: http_model.NewEndTaskResponse(),
	}
}
