import { DEFAULT_PROJECT_CONCURRENCY_CAP, effectiveProjectConcurrencyCap, } from '../../../../modules/cli-configuration/entities/projectConcurrencyCap/projectConcurrencyCap.valueObject.js';
export class RecomputeGlobalConcurrencyUseCase {
    dependencies;
    constructor(dependencies) {
        this.dependencies = dependencies;
    }
    execute(_input) {
        const { repositoriesListGateway, projectConfigGateway, queueCapacityPort } = this.dependencies;
        const repositories = repositoriesListGateway.list();
        const perProjectCaps = [];
        for (const repository of repositories) {
            const readResult = projectConfigGateway.read(repository.localPath);
            const cap = readResult.status === 'ok'
                ? effectiveProjectConcurrencyCap(readResult.config)
                : DEFAULT_PROJECT_CONCURRENCY_CAP;
            perProjectCaps.push({ path: repository.localPath, cap });
            queueCapacityPort.setProjectConcurrencyCap(repository.localPath, cap);
        }
        const totalCapacity = perProjectCaps.reduce((sum, entry) => sum + entry.cap, 0);
        queueCapacityPort.setGlobalConcurrency(Math.max(totalCapacity, 1));
        return { totalCapacity, perProjectCaps };
    }
}
//# sourceMappingURL=recomputeGlobalConcurrency.usecase.js.map