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

type TaskLinklist struct {
	ctx  *gin.Context
	req  *http_model.TaskLinklistRequest
	resp *http_model.CommonResponse
}

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

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

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

func (c TaskLinklist) run() {
	data := http_model.TaskLinklistRequest{}
	data = *c.req
	res, err := service.Task.GetTaskLinklist(c.ctx, data)
	if err != nil {
		logrus.Errorf("[GetTaskLinklist] call GetTaskLinklist err:%+v\n", err)
		util.HandlerPackErrorResp(c.resp, consts.ErrorParamCheck, "")
		logrus.Info("GetTaskLinklist fail,req:%+v", c.req)
		return
	}
	c.resp.Message = "成功查询链接待审列表"
	c.resp.Data = res
	c.resp.Status = consts.ErrorSuccess
}

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

func newTaskLinklistHandler(ctx *gin.Context) *TaskLinklist {
	return &TaskLinklist{
		ctx:  ctx,
		req:  http_model.NewTaskLinklistRequest(),
		resp: http_model.NewTaskLinklistResponse(),
	}
}
