package tech.easyflow.ai.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

/**
 * EasyFlow 业务线程池配置。
 */
@ConfigurationProperties(prefix = "easyflow.thread-pool")
public class EasyFlowThreadPoolProperties {

    private Pool sse = new Pool(4, 16, 2000, 30, true);
    private Pool documentImport = new Pool(2, 4, 200, 60, true);
    private Pool agentAsyncTool = new Pool(2, 8, 200, 60, true);

    /**
     * 获取 SSE 线程池配置。
     *
     * @return SSE 线程池配置
     */
    public Pool getSse() {
        return sse;
    }

    /**
     * 设置 SSE 线程池配置。
     *
     * @param sse SSE 线程池配置
     */
    public void setSse(Pool sse) {
        this.sse = sse;
    }

    /**
     * 获取文档导入线程池配置。
     *
     * @return 文档导入线程池配置
     */
    public Pool getDocumentImport() {
        return documentImport;
    }

    /**
     * 设置文档导入线程池配置。
     *
     * @param documentImport 文档导入线程池配置
     */
    public void setDocumentImport(Pool documentImport) {
        this.documentImport = documentImport;
    }

    /**
     * 获取 Agent 异步工具后台执行线程池配置。
     *
     * @return Agent 异步工具线程池配置
     */
    public Pool getAgentAsyncTool() {
        return agentAsyncTool;
    }

    /**
     * 设置 Agent 异步工具后台执行线程池配置。
     *
     * @param agentAsyncTool Agent 异步工具线程池配置
     */
    public void setAgentAsyncTool(Pool agentAsyncTool) {
        this.agentAsyncTool = agentAsyncTool;
    }

    /**
     * 线程池配置项。
     */
    public static class Pool {

        private int coreSize;
        private int maxSize;
        private int queueCapacity;
        private int keepAliveSeconds;
        private boolean allowCoreThreadTimeout;

        /**
         * 创建默认线程池配置。
         */
        public Pool() {
        }

        /**
         * 创建线程池配置。
         *
         * @param coreSize 核心线程数
         * @param maxSize 最大线程数
         * @param queueCapacity 队列容量
         * @param keepAliveSeconds 空闲线程存活时间
         * @param allowCoreThreadTimeout 是否允许核心线程超时
         */
        public Pool(int coreSize, int maxSize, int queueCapacity, int keepAliveSeconds, boolean allowCoreThreadTimeout) {
            this.coreSize = coreSize;
            this.maxSize = maxSize;
            this.queueCapacity = queueCapacity;
            this.keepAliveSeconds = keepAliveSeconds;
            this.allowCoreThreadTimeout = allowCoreThreadTimeout;
        }

        public int getCoreSize() {
            return coreSize;
        }

        public void setCoreSize(int coreSize) {
            this.coreSize = coreSize;
        }

        public int getMaxSize() {
            return maxSize;
        }

        public void setMaxSize(int maxSize) {
            this.maxSize = maxSize;
        }

        public int getQueueCapacity() {
            return queueCapacity;
        }

        public void setQueueCapacity(int queueCapacity) {
            this.queueCapacity = queueCapacity;
        }

        public int getKeepAliveSeconds() {
            return keepAliveSeconds;
        }

        public void setKeepAliveSeconds(int keepAliveSeconds) {
            this.keepAliveSeconds = keepAliveSeconds;
        }

        public boolean isAllowCoreThreadTimeout() {
            return allowCoreThreadTimeout;
        }

        public void setAllowCoreThreadTimeout(boolean allowCoreThreadTimeout) {
            this.allowCoreThreadTimeout = allowCoreThreadTimeout;
        }
    }
}
