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

type LocallifeData struct {
	ctx  *gin.Context
	req  *http_model.LocallifeDataRequest
	resp *http_model.CommonResponse
}

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

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

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

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

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

func newLocallifeDataHandler(ctx *gin.Context) *LocallifeData {
	return &LocallifeData{
		ctx:  ctx,
		req:  http_model.NewLocallifeDataRequest(),
		resp: http_model.NewLocallifeDataResponse(),
	}
}
