package handler

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	log "github.com/sirupsen/logrus"
	"youngee_b_api/consts"
	"youngee_b_api/model/http_model"
	"youngee_b_api/service"
	"youngee_b_api/util"
)

func WrapLocalLifeDetailHandler(ctx *gin.Context) {
	handler := newLocalLifeDetailHandler(ctx)
	baseRun(handler)
}

func newLocalLifeDetailHandler(ctx *gin.Context) *LocalLifeDetailHandler {
	return &LocalLifeDetailHandler{
		req:  http_model.NewShowProjectRequest(),
		resp: http_model.NewShowProjectResponse(),
		ctx:  ctx,
	}
}

type LocalLifeDetailHandler struct {
	req  *http_model.ShowProjectRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *LocalLifeDetailHandler) getRequest() interface{} {
	return h.req
}

func (h *LocalLifeDetailHandler) getContext() *gin.Context {
	return h.ctx
}

func (h *LocalLifeDetailHandler) getResponse() interface{} {
	return h.resp
}

func (h *LocalLifeDetailHandler) run() {
	data := http_model.ShowProjectRequest{}
	data = *h.req
	//auth := middleware.GetSessionAuth(h.ctx)
	//enterpriseID := auth.EnterpriseID
	fmt.Printf("projectID %+v", data.ProjectID)
	res, err := service.Project.GetPorjectDetail(h.ctx, data.ProjectID)
	if err != nil {
		logrus.Errorf("[ShowProjectHandler] call Show err:%+v\n", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, "")
		log.Info("ShowProject fail,req:%+v", h.req)
		return
	}
	h.resp.Message = "成功查询项目"
	h.resp.Data = res
}

func (h *LocalLifeDetailHandler) checkParam() error {
	return nil
}
