package com.ai.trackwalker.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
@EnableAsync
public class ModelTestAsyncConfig {
    private final RailProperties properties;

    public ModelTestAsyncConfig(RailProperties properties) {
        this.properties = properties;
    }

    @Bean(name = "modelTestExecutor")
    public Executor modelTestExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(properties.getModelTest().getCorePoolSize());
        executor.setMaxPoolSize(properties.getModelTest().getMaxPoolSize());
        executor.setQueueCapacity(properties.getModelTest().getQueueCapacity());
        executor.setThreadNamePrefix("model-test-");
        executor.initialize();
        return executor;
    }
}
