package cokr.xit.ens.core.config;

import cokr.xit.ens.core.filter.RequestWrapperFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.json.MappingJackson2JsonView;

import java.util.Arrays;

@Configuration
public class WebConfig implements WebMvcConfigurer {

	@Bean(name = "jsonView")
	public MappingJackson2JsonView jsonView() {
		return new MappingJackson2JsonView();
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Bean
//	@Profile("!prod-iup")
	public FilterRegistrationBean requestWrapperFilter() {
		FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new RequestWrapperFilter());
		filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
		return filterRegistrationBean;
	}
	
}
