package handler

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

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	log "github.com/sirupsen/logrus"
)

func WrapShowProjectHandler(ctx *gin.Context) {
	handler := newShowProjectHandler(ctx)
	baseRun(handler)
}

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

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

func (h *ShowProjectHandler) getRequest() interface{} {
	return h.req
}
func (h *ShowProjectHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *ShowProjectHandler) getResponse() interface{} {
	return h.resp
}
func (h *ShowProjectHandler) 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 *ShowProjectHandler) checkParam() error {
	return nil
}
