import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.ResourceHttpMessageConverter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Root application context
 * This context imports XML configs from all the other jars, and is created by {@link WebAppInitializer}
 * NB: modules are excluded from component scan since spring-context.xml sometimes holds important parameters and / or annotations
 * @author krylov
 */
@Configuration
@ComponentScan(basePackages = {
    "service",
    "dao",
    "bpmn",
    "i18n",
    "errorhandling",
    "component.addresses",
    "gen",
    "ru.cg",
    "ru.micord"
}, excludeFilters = {
    @ComponentScan.Filter(type = FilterType.REGEX, pattern = "service.sql.SqlExecutorServiceImpl")
})
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableWebMvc
@EnableScheduling
public class AppConfig implements WebMvcConfigurer {

  @Bean
  public PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer(){
    return new PropertySourcesPlaceholderConfigurer();
  }

  @Override
  public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new ResourceHttpMessageConverter());
  }
}
