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

type PasslocalTaskCoop struct {
	ctx  *gin.Context
	req  *http_model.PasslocalTaskCoopRequest
	resp *http_model.CommonResponse
}

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

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

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

func (c PasslocalTaskCoop) run() {
	data := *c.req
	//auth := middleware.GetSessionAuth(c.ctx)
	//enterpriseID := auth.EnterpriseID
	res, err := service.LocalTask.PassCoop(c.ctx, data)
	if err != nil {
		logrus.Errorf("[PasslocalTaskCoop] call PasslocalTaskCoop err:%+v\n", err)
		util.HandlerPackErrorResp(c.resp, consts.ErrorParamCheck, "")
		logrus.Info("PasslocalTaskCoop fail,req:%+v", c.req)
		return
	}
	c.resp.Message = "成功合作任务"
	c.resp.Data = res
	c.resp.Status = consts.ErrorSuccess
}

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

func newPasslocalTaskCoopHandler(ctx *gin.Context) *PasslocalTaskCoop {
	return &PasslocalTaskCoop{
		ctx:  ctx,
		req:  http_model.NewPasslocalTaskCoopRequest(),
		resp: http_model.NewPasslocalTaskCoopResponse(),
	}
}
