package org.example.Config;

import jakarta.annotation.PostConstruct;
import org.example.Utils.CacheUtil;
import org.example.Utils.JsEngine;
import org.example.Utils.ResourceExecutors;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ResourceGovernanceConfig {
    @Value("${app.cache.max-entries:5000}")
    private int cacheMaxEntries;

    @Value("${app.js-cache.max-entries:1000}")
    private int jsCacheMaxEntries;

    @Value("${app.executor.file-cleanup.core-size:2}")
    private int fileCleanupCoreSize;

    @Value("${app.executor.file-cleanup.max-size:4}")
    private int fileCleanupMaxSize;

    @Value("${app.executor.file-cleanup.queue-capacity:200}")
    private int fileCleanupQueueCapacity;

    @Value("${app.executor.push.core-size:4}")
    private int pushCoreSize;

    @Value("${app.executor.push.max-size:16}")
    private int pushMaxSize;

    @Value("${app.executor.push.queue-capacity:500}")
    private int pushQueueCapacity;

    @PostConstruct
    public void applyResourceGovernanceSettings() {
        CacheUtil.setMaxEntries(cacheMaxEntries);
        JsEngine.setMaxCacheEntries(jsCacheMaxEntries);
        ResourceExecutors.configure(
                fileCleanupCoreSize,
                fileCleanupMaxSize,
                fileCleanupQueueCapacity,
                pushCoreSize,
                pushMaxSize,
                pushQueueCapacity
        );
    }
}
