package handler

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

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

func WrapFullProjectListHandler(ctx *gin.Context) {
	handler := newFullProjectListHandler(ctx)
	baseRun(handler)
}

func newFullProjectListHandler(ctx *gin.Context) *FullProjectListHandler {
	return &FullProjectListHandler{
		req:  http_model.NewFullProjectListRequest(),
		resp: http_model.NewFullProjectListResponse(),
		ctx:  ctx,
	}
}

type FullProjectListHandler struct {
	req  *http_model.FullProjectListRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *FullProjectListHandler) getRequest() interface{} {
	return h.req
}
func (h *FullProjectListHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *FullProjectListHandler) getResponse() interface{} {
	return h.resp
}
func (h *FullProjectListHandler) run() {
	// enterpriseID := middleware.GetSessionAuth(h.ctx).EnterpriseID
	condition := pack.HttpFullProjectRequestToCondition(h.req)
	data, err := service.Project.GetFullProjectList(h.ctx, h.req.PageSize, h.req.PageNum, h.req.SupplierId, condition)
	if err != nil {
		logrus.WithContext(h.ctx).Errorf("[FullProjectListHandler] error GetFullProjectList, err:%+v", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, consts.DefaultToast)
		return
	}
	h.resp.Data = data
}
func (h *FullProjectListHandler) checkParam() error {
	return nil
}
