package transformer

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

type Transformer interface {
	Success(c *gin.Context, statusCode int, message string, data interface{})
	Error(c *gin.Context, statusCode int, message string, err error)
}

type ResponseTransformer struct{}

func NewTransformer() Transformer {
	return &ResponseTransformer{}
}

func (t *ResponseTransformer) Success(c *gin.Context, statusCode int, message string, data interface{}) {
	response := gin.H{
		"success": true,
		"message": message,
		"data":    data,
	}
	c.JSON(statusCode, response)
}

func (t *ResponseTransformer) Error(c *gin.Context, statusCode int, message string, err error) {
	response := gin.H{
		"success": false,
		"message": message,
	}

	if err != nil {
		response["error"] = err.Error()
	}

	c.JSON(statusCode, response)
}
