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/pack"
	"youngee_b_api/service"
	"youngee_b_api/util"
)

func WrapSProjectListHandler(ctx *gin.Context) {
	handler := newSProjectListHandler(ctx)
	baseRun(handler)
}

func newSProjectListHandler(ctx *gin.Context) *SProjectListHandler {
	return &SProjectListHandler{
		req:  http_model.NewSProjectListRequest(),
		resp: http_model.NewSProjectListResponse(),
		ctx:  ctx,
	}
}

type SProjectListHandler struct {
	req  *http_model.SProjectListRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

func (h *SProjectListHandler) getRequest() interface{} {
	return h.req
}
func (h *SProjectListHandler) getContext() *gin.Context {
	return h.ctx
}
func (h *SProjectListHandler) getResponse() interface{} {
	return h.resp
}
func (h *SProjectListHandler) run() {
	condition := pack.HttpSProjectListRequestToCondition(h.req)
	data, err := service.SProject.GetSProjectList(h.ctx, h.req.SupplierId, h.req.PageSize, h.req.PageNum, condition)
	if err != nil {
		logrus.WithContext(h.ctx).Errorf("[FullProjectListHandler] error GetFullProjectList, err:%+v", err)
		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, consts.DefaultToast)
		h.resp.Message = "失败"
		return
	}
	// fmt.Println("data: ", data, "total: ", total)
	// fmt.Println("sProjectInfo: ", sProjectInfo)
	h.resp.Data = data
	h.resp.Message = "成功"
}

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