package tech.easyflow.common.audio.socket;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import tech.easyflow.common.audio.config.AudioThreadPoolProperties;

@Configuration
@EnableScheduling
@EnableConfigurationProperties(AudioThreadPoolProperties.class)
public class SchedulingConfig {

    private final AudioThreadPoolProperties properties;

    /**
     * 创建音频调度配置。
     *
     * @param properties 音频调度线程池配置
     */
    public SchedulingConfig(AudioThreadPoolProperties properties) {
        this.properties = properties;
    }

    /**
     * 创建调度线程池。
     *
     * @return 调度线程池
     */
    @Bean
    public TaskScheduler taskScheduler() {
        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
        scheduler.setPoolSize(properties.getPoolSize());
        scheduler.setThreadNamePrefix("scheduled-task-");
        scheduler.setDaemon(true);
        scheduler.initialize();
        return scheduler;
    }
}
