package handler

import (
	"youngee_b_api/consts"
	"youngee_b_api/model/http_model"
	"youngee_b_api/service"
	"youngee_b_api/util"

	"github.com/sirupsen/logrus"

	"github.com/gin-gonic/gin"
)

func WrapProjectChangeTaskStatusHandler(ctx *gin.Context) {
	handler := newProjectChangeTaskStatusHandler(ctx)
	baseRun(handler)
}

func newProjectChangeTaskStatusHandler(ctx *gin.Context) *ProjectChangeTaskStatusHandler {
	return &ProjectChangeTaskStatusHandler{
		req:  http_model.NewProjectChangeTaskStatusRequst(),
		resp: http_model.NewProjectChangeTaskStatusResponse(),
		ctx:  ctx,
	}
}

type ProjectChangeTaskStatusHandler struct {
	req  *http_model.ProjectChangeTaskStatusRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (p *ProjectChangeTaskStatusHandler) getContext() *gin.Context {
	return p.ctx
}

func (p *ProjectChangeTaskStatusHandler) getResponse() interface{} {
	return p.resp
}

func (p *ProjectChangeTaskStatusHandler) getRequest() interface{} {
	return p.req
}

func (p *ProjectChangeTaskStatusHandler) run() {
	data := http_model.ProjectChangeTaskStatusRequest{}
	data = *p.req
	if data.IsSpecial == "1" {
		// 定向种草
		err := service.Project.ChangeSpecialTaskStatus(p.ctx, data)
		if err != nil {
			logrus.Errorf("[ChangeTaskStatusHandler] call Create err:%+v\n", err)
			util.HandlerPackErrorResp(p.resp, consts.ErrorInternal, "")
			logrus.Info("ChangeTaskStatus fail,req:%+v", p.req)
			return
		}
	} else {
		// 公开种草
		err := service.Project.ChangeTaskStatus(p.ctx, data)
		if err != nil {
			logrus.Errorf("[ChangeTaskStatusHandler] call Create err:%+v\n", err)
			util.HandlerPackErrorResp(p.resp, consts.ErrorInternal, "")
			logrus.Info("ChangeTaskStatus fail,req:%+v", p.req)
			return
		}
	}
	p.resp.Message = "任务状态更换成功"
}

func (p *ProjectChangeTaskStatusHandler) checkParam() error {
	return nil
}
