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

type PassproTaskCoop struct {
	ctx  *gin.Context
	req  *http_model.PassproTaskCoopRequest
	resp *http_model.CommonResponse
}

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

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

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

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

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

func newPassproTaskCoopHandler(ctx *gin.Context) *PassproTaskCoop {
	return &PassproTaskCoop{
		ctx:  ctx,
		req:  http_model.NewPassproTaskCoopRequest(),
		resp: http_model.NewPassproTaskCoopResponse(),
	}
}
