// Package common 公共包
package common

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

// Response 统一响应结构
type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

// PageResponse 分页响应
type PageResponse struct {
	List  interface{} `json:"list"`
	Total int64       `json:"total"`
	Page  int         `json:"page"`
	Size  int         `json:"size"`
}

func Success(c *gin.Context, data interface{}) {
	c.JSON(200, Response{Code: 200, Message: "success", Data: data})
}

func SuccessPage(c *gin.Context, list interface{}, total int64, page, size int) {
	c.JSON(200, Response{
		Code:    200,
		Message: "success",
		Data:    PageResponse{List: list, Total: total, Page: page, Size: size},
	})
}

func Error(c *gin.Context, code int, message string) {
	c.JSON(code, Response{Code: code, Message: message, Data: nil})
}
