package utils

import (
	"jannex/log-manager/modules/structs"

	"github.com/go-playground/validator/v10"
)

type ErrorResponse struct {
	FailedField string
	Tag         string
	Value       string
}

var Validate = validator.New()

func ValidateStruct(event interface{}) []*ErrorResponse {
	var errors []*ErrorResponse
	err := Validate.Struct(event)
	if err != nil {
		for _, err := range err.(validator.ValidationErrors) {
			var element ErrorResponse
			element.FailedField = err.StructNamespace()
			element.Tag = err.Tag()
			element.Value = err.Param()
			errors = append(errors, &element)
		}
	}
	return errors
}

func ValidatorInit() {
	Validate.RegisterStructValidationMapRules(logRules,
		structs.LogBody{},
		structs.GetLogParams{},
		structs.GetLogQuery{})
}
