package middle

import (
	"Crimson-Gatekeeper/internal/common"
	"Crimson-Gatekeeper/internal/ero"

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

// GeneralResponse 通用的返回包装结构体。不管错误与否
type GeneralResponse struct {
	success string
	data    any
}

// ResponsePackageMiddle 返回包装中间件
func ResponsePackageMiddle(c *gin.Context) {
	c.Next()
	data := common.GetData(c)
	if data, ok := data.(ero.GeneralError); ok {
		c.JSON(200, &GeneralResponse{"false", data})
	} else {
		c.JSON(200, &GeneralResponse{"fail", data})
	}
}
