package system

import (
	"sun-panel/api/api_v1/common/apiReturn"
	"sun-panel/global"
	"sun-panel/lib/cmn/systemSetting"

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

type SiteCustomizeApi struct{}

// 获取站点自定义配置（无需登录，登录页使用）
func (a *SiteCustomizeApi) Get(c *gin.Context) {
	cfg := systemSetting.SiteCustomize{}
	global.SystemSetting.GetValueByInterface(systemSetting.SITE_CUSTOMIZE, &cfg)
	apiReturn.SuccessData(c, cfg)
}

// 保存站点自定义配置（管理员）
func (a *SiteCustomizeApi) Set(c *gin.Context) {
	cfg := systemSetting.SiteCustomize{}
	if err := c.ShouldBindBodyWith(&cfg, binding.JSON); err != nil {
		apiReturn.ErrorParamFomat(c, err.Error())
		return
	}
	if err := global.SystemSetting.Set(systemSetting.SITE_CUSTOMIZE, cfg); err != nil {
		apiReturn.ErrorDatabase(c, err.Error())
		return
	}
	apiReturn.Success(c)
}
