package auxhttp

import (
	"net/http"

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

type GenericResponse[T any] struct {
	Result    T      `json:"result,omitempty"`
	Message   string `json:"message,omitempty"`
	Error     bool   `json:"error"`
	ErrorCode int64  `json:"errorCode"`
}

func SendError(c *gin.Context, err error) {
	var response GenericResponse[interface{}]
	response.Error = true
	if err != nil {
		response.Message = err.Error()
		response.ErrorCode = 101
	}
	c.AbortWithStatusJSON(http.StatusOK, response)
}

func SendResult(c *gin.Context, result any) {
	var response GenericResponse[any]
	response.Result = result
	c.JSON(http.StatusOK, response)
}
