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

type Data struct {
	ctx  *gin.Context
	req  *http_model.DataRequest
	resp *http_model.CommonResponse
}

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

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

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

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

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

func newDataHandler(ctx *gin.Context) *Data {
	return &Data{
		ctx:  ctx,
		req:  http_model.NewDataRequest(),
		resp: http_model.NewDataResponse(),
	}
}
