package common

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

// 统一 JSON 响应

func Ok(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, gin.H{"success": true, "data": data})
}

func OkMessage(c *gin.Context, message string) {
	c.JSON(http.StatusOK, gin.H{"success": true, "message": message})
}

func OkWithMessage(c *gin.Context, data interface{}, message string) {
	c.JSON(http.StatusOK, gin.H{"success": true, "data": data, "message": message})
}

func Error(c *gin.Context, code int, message string) {
	c.JSON(code, gin.H{"success": false, "message": message})
}

// VditorUploadOk Vditor 图片上传成功响应
// succMap: key=原始文件名, value=文件 URL
func VditorUploadOk(c *gin.Context, succMap map[string]string) {
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "",
		"data": gin.H{
			"errFiles": []string{},
			"succMap":  succMap,
		},
	})
}
