package request

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

type ValidateError struct {
	Err error
}

func NewValidateError(err error) ValidateError {
	return ValidateError{Err: err}
}

func (e ValidateError) Error() string {
	return e.Err.Error()
}

func Check[T any](c *gin.Context, obj *T) *T {

	if err := c.ShouldBindJSON(obj); err != nil {
		panic(NewValidateError(err))
	}

	return obj
}
