package work

import (
	"kpt-pasture/http/middleware"
	"net/http"

	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
	"gitee.com/xuyiping_admin/pkg/apierr"
	"gitee.com/xuyiping_admin/pkg/ginutil"
	"gitee.com/xuyiping_admin/pkg/valid"
	"github.com/gin-gonic/gin"
)

func CalendarList(c *gin.Context) {
	var req pasturePb.CalendarRequest
	if err := ginutil.BindProto(c, &req); err != nil {
		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
		return
	}

	if err := valid.ValidateStruct(&req,
		valid.Field(&req.ShowStartDay, valid.Required),
		valid.Field(&req.ShowEndDay, valid.Required),
	); err != nil {
		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
		return
	}

	res, err := middleware.Dependency(c).StoreEventHub.OpsService.CalendarList(c, &req)
	if err != nil {
		apierr.ClassifiedAbort(c, err)
		return
	}
	ginutil.JSONResp(c, res)
}

func CalendarTableDetail(c *gin.Context) {
	var req pasturePb.CalendarTableRequest
	if err := ginutil.BindProto(c, &req); err != nil {
		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
		return
	}

	if err := valid.ValidateStruct(&req,
		valid.Field(&req.CalendarType, valid.Required),
		valid.Field(&req.Start, valid.Required),
	); err != nil {
		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
		return
	}

	res, err := middleware.Dependency(c).StoreEventHub.OpsService.CalendarTableDetail(c, &req)
	if err != nil {
		apierr.ClassifiedAbort(c, err)
		return
	}
	c.JSON(http.StatusOK, res)
}