package com.ffii.core.config;

import java.util.Locale;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;

import com.ffii.core.support.ErrorHandler;
import com.ffii.core.support.JdbcDao;

/** @author Fung */
@Configuration
@EnableScheduling
@EnableAsync
public class AppConfig {

  @Bean
  public JdbcDao jdbcDao(DataSource dataSource) {
    return new JdbcDao(dataSource);
  }

  @Bean
  public LocaleResolver localeResolver() {
    var localeResolver = new SessionLocaleResolver();
    localeResolver.setDefaultLocale(Locale.ENGLISH);
    return localeResolver;
  }

  @Bean
  public ErrorHandler errorHandler() {
    return new ErrorHandler();
  }
}
