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

func newSpecialSProjectListHandler(ctx *gin.Context) *SpecialSProjectListHandler {
	return &SpecialSProjectListHandler{
		req:  http_model.NewSpecialSProjectListRequest(),
		resp: http_model.NewSpecialSProjectListResponse(),
		ctx:  ctx,
	}
}

type SpecialSProjectListHandler struct {
	req  *http_model.SpecialProjectListRequest
	resp *http_model.CommonResponse
	ctx  *gin.Context
}

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

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

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

func (h *SpecialSProjectListHandler) run() {
	condition := pack.HttpSpecialProjectRequestToCondition(h.req)
	data, err := service.SProject.GetSpecialSProjectList(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.Status = 40000
		h.resp.Message = err.Error()
		return
	}
	h.resp.Status = 20000
	h.resp.Data = data
}

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