package router

import (
	"github.com/gin-gonic/gin"
	"io.wdd.message_pusher/cmii"
	"net/http"
)

func ImageSyncRouter(r *gin.Engine) {
	octopusGroup := r.Group("/image")
	{
		octopusGroup.POST("/sync", ImageSync)
	}
}

// ImageSync godoc
// @Summary 镜像同步消息
// @Schemes
// @Description response to cmii update notification
// @Tags ImageSync
// @Accept json
// @Produce json
// @Param body body cmii.ImageSyncMessage true "请求体"
// @Success 200 {object} pusher.Message
// @Router /image/sync [post]
func ImageSync(c *gin.Context) {
	// 获取请求中的参数
	var imageSyncMessage cmii.ImageSyncMessage
	if err := c.ShouldBindJSON(&imageSyncMessage); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request body"})
		return
	}
	// 处理请求
	upgradeMessage := imageSyncMessage.PublishMessage()

	// *pusher.Message
	c.JSON(http.StatusOK, upgradeMessage)
}
