package cc.smtweb.framework.core;

import cc.smtweb.framework.core.common.SwConsts;
import cc.smtweb.framework.core.db.jdbc.IdGenerator;
import cc.smtweb.framework.core.mvc.config.ControllerConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author kevin
 */
@Configuration
@ComponentScan
@EnableScheduling
public class CoreAutoConfiguration implements WebMvcConfigurer {
    /**
     * ID生成器的分步式机器码（1-1023）
     */
    @Value("${smtweb.machine-id}")
    private int machineId;
    @Value("${smtweb.enable-job}")
    private boolean enableJob;

    @Bean
    public IdGenerator idGenerator() {
        SwConsts.SysParam.machineId = machineId;
        SwConsts.SysParam.enableJob = enableJob;
        return new IdGenerator(machineId);
    }

    @Bean
    public ControllerConfig coreControllerConfig() {
        return new ControllerConfig("core", "cc.smtweb.framework.core");
    }
}
