package render

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

type RespJsonData struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func Json(c *gin.Context, code *Code, data interface{}) {
	result := &RespJsonData{
		Code: code.Code(),
		Msg:  code.Message(),
		Data: data,
	}
	c.JSON(http.StatusOK, result)
}

func JsonByStatus(c *gin.Context, status int, code *Code, data interface{}) {
	result := &RespJsonData{
		Code: code.Code(),
		Msg:  code.Message(),
		Data: data,
	}
	c.JSON(status, result)
}

func AbortJson(c *gin.Context, code *Code, data interface{}) {
	result := &RespJsonData{
		Code: code.Code(),
		Msg:  code.Message(),
		Data: data,
	}
	c.AbortWithStatusJSON(http.StatusOK, result)
}
