package net.northking.cctp.se.config;

import com.google.common.annotations.VisibleForTesting;
import lombok.Data;
import net.northking.cctp.se.thread.ExecutorPool;
import net.northking.cctp.se.util.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.Serializable;

@Configuration
public class ExecutorPoolConfig {

    private static final Logger logger = LoggerFactory.getLogger(ExecutorPoolConfig.class);

    @Bean
    public ExecutorPool createExecutorPool() {
        ExecutorPoolProperties pp = SpringUtils.getBean(ExecutorPoolProperties.class);
        ExecutorPool executorPool = new ExecutorPool(pp.getEnablePc(), pp.getPcSize(),pp.getPcCoreSize(), pp.getEnableMobile(), pp.getMobileSize(), pp.getMobileCoreSize(),pp.getEnableApi(), pp.getApiSize(),pp.getApiCoreSize());
        logger.info("执行线程池创建成功：{}", ExecutorPool.info());
        logger.info("执行引擎所在的系统:{}", System.getProperty("os.name"));
        return executorPool;
    }


    @ConfigurationProperties(prefix = "atu.engine.executor-pool")
    @Configuration
    @Data
    static
    class ExecutorPoolProperties implements Serializable {
        @VisibleForTesting
        private Integer pcSize;

        @VisibleForTesting
        private Boolean enablePc;

        @VisibleForTesting
        private Integer mobileSize;

        @VisibleForTesting
        private Boolean enableMobile;

        @VisibleForTesting
        private Integer apiSize;

        @VisibleForTesting
        private Boolean enableApi;

        @VisibleForTesting
        private Integer pcCoreSize;

        @VisibleForTesting
        private Integer mobileCoreSize;

        @VisibleForTesting
        private Integer apiCoreSize;
    }


}
