/**
 * @author chengliang
 * @date 2026/1/12 21:06
 * @brief
 *
 **/

package hotupdate

import (
	"dsbqj-admin/app/service"
	"dsbqj-admin/pkg/app"
	"dsbqj-admin/pkg/e"
	"dsbqj-admin/pkg/logger"
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
hotupdate/getversion?os=ios&proj=bzst
获取最新的version内容
*/

func GetVersion(c *gin.Context) {
	logger.Info("uri %s", c.Request.RequestURI)
	var appG = app.Gin{C: c}
	req := service.TGetVersionReq{}
	err := c.ShouldBind(&req)
	if err == nil {
		var rsp, err = service.GetTHotUpdateVerManager().GetMaxVerInfo(req.Proj, req.Os)
		if err != nil {
			appG.Response(http.StatusOK, e.NO_RECORD, err.Error())
		} else {
			// 不需要code等
			c.JSON(http.StatusOK, rsp)
		}
	} else {
		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
	}
}

func AddVersion(c *gin.Context) {
	var appG = app.Gin{C: c}
	logger.Info("uri %s", c.Request.RequestURI)
	req := service.TAddVersionReq{}
	err := c.ShouldBind(&req)
	if err == nil {
		var err = service.GetTHotUpdateVerManager().AddVersion(&req)
		if err != nil {
			appG.Response(http.StatusOK, e.NO_RECORD, err.Error())
		} else {
			appG.Response(http.StatusOK, e.SUCCESS, "")
		}
	} else {
		appG.Response(http.StatusOK, e.INVALID_PARAMS, err.Error())
	}
}
