package httpx

import (
	"net/http"

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

type ErrorDetail struct {
	Message string `json:"message"`
}

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

type SuccessResponse struct {
	Data any `json:"data"`
}

func OK(c *gin.Context, data any) {
	c.JSON(http.StatusOK, SuccessResponse{
		Data: data,
	})
}

func Error(c *gin.Context, status int, msg string) {
	c.JSON(status, ErrorResponse{
		Error: ErrorDetail{
			Message: msg,
		},
	})
}

func Created(c *gin.Context, data any) {
	c.JSON(http.StatusCreated, SuccessResponse{
		Data: data,
	})
}

func NoContent(c *gin.Context) {
	c.Status(http.StatusNoContent)
}

func Unauthorized(c *gin.Context, msg string) {
	Error(c, http.StatusUnauthorized, msg)
}

func BadRequest(c *gin.Context, msg string) {
	Error(c, http.StatusBadRequest, msg)
}

func NotFound(c *gin.Context, msg string) {
	Error(c, http.StatusNotFound, msg)
}

func InternalServerError(c *gin.Context, msg string) {
	Error(c, http.StatusInternalServerError, msg)
}
