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

type ExecuteData struct {
	ctx  *gin.Context
	req  *http_model.ExecuteDataRequest
	resp *http_model.CommonResponse
}

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

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

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

func (c ExecuteData) run() {
	data := http_model.ExecuteDataRequest{}
	data = *c.req
	//auth := middleware.GetSessionAuth(c.ctx)
	//enterpriseID := auth.EnterpriseID
	res, err := service.Project.ExecuteData(c.ctx, data)
	if err != nil {
		logrus.Errorf("[ExecuteData] call ExecuteData err:%+v\n", err)
		util.HandlerPackErrorResp(c.resp, consts.ErrorParamCheck, "")
		logrus.Info("ExecuteData fail,req:%+v", c.req)
		return
	}
	c.resp.Message = "成功看数据"
	c.resp.Data = res
	c.resp.Status = consts.ErrorSuccess
}

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

func newExecuteDataHandler(ctx *gin.Context) *ExecuteData {
	return &ExecuteData{
		ctx:  ctx,
		req:  http_model.NewExecuteDataRequest(),
		resp: http_model.NewExecuteDataResponse(),
	}
}
