package com.imprimelibros.erp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer;

import jakarta.validation.ValidatorFactory;

@Configuration
public class BeanValidationConfig {

    // Asegura que usamos la factory de Spring (con SpringConstraintValidatorFactory)
    @Bean
    public LocalValidatorFactoryBean validator() {
        return new LocalValidatorFactoryBean();
    }

    // Inserta esa factory en Hibernate/JPA
    @Bean
    public HibernatePropertiesCustomizer hibernateValidationCustomizer(ValidatorFactory vf) {
        return props -> props.put("jakarta.persistence.validation.factory", vf);
    }
}
