import { backfillDiffStats } from '../../../../modules/statistics-insights/usecases/stats/backfillDiffStats.usecase.js';
import { recalculateProjectStats } from '../../../../modules/statistics-insights/usecases/stats/recalculateProjectStats.usecase.js';
export async function recalculateWithBackfill(input, dependencies) {
    const { projectPath, shouldBackfill, platform } = input;
    const { statsGateway, diffStatsFetchGateways, onProgress, logger } = dependencies;
    try {
        if (shouldBackfill && diffStatsFetchGateways && platform) {
            const resolvedPlatform = platform === 'github' ? 'github' : 'gitlab';
            const gateway = diffStatsFetchGateways[resolvedPlatform];
            await backfillDiffStats({
                projectPath,
                onProgress: (progress) => {
                    onProgress(progress);
                },
            }, {
                statsGateway,
                diffStatsFetchGateway: gateway,
                logger: { warn: logger.warn },
            });
        }
        recalculateProjectStats(projectPath, { statsGateway });
        onProgress({
            total: 0,
            completed: 0,
            failed: 0,
            status: 'completed',
        });
    }
    catch (error) {
        logger.error('Recalculation failed', { projectPath, error });
    }
}
//# sourceMappingURL=recalculateWithBackfill.usecase.js.map