import { hashProjectPath } from '../../../storage/base-store.js';
import { getCalibration } from '../../../storage/actuals-store.js';
import { applyCalibration } from '../../../engine/estimation-calibrator.js';
const NO_CALIBRATION = {
    calibratedHours: 0,
    applied: false,
    calibrationNote: null,
};
export async function enrichEstimationWithCalibration(projectPath, baseHours, scope, type) {
    try {
        const projectId = hashProjectPath(projectPath);
        const factors = await getCalibration(projectId);
        if (!factors) {
            return { ...NO_CALIBRATION, calibratedHours: baseHours };
        }
        const calibratedHours = applyCalibration(baseHours, scope, type, factors);
        if (calibratedHours === baseHours) {
            return { ...NO_CALIBRATION, calibratedHours: baseHours };
        }
        const deltaPct = Math.round(((calibratedHours - baseHours) / baseHours) * 100);
        const sign = deltaPct >= 0 ? '+' : '';
        const samples = (factors.sampleSize[`scope:${scope}`] ?? 0) + (factors.sampleSize[`type:${type}`] ?? 0);
        return {
            calibratedHours,
            applied: true,
            calibrationNote: `calibration: ${sign}${String(deltaPct)}% based on ${String(samples)} historical samples`,
        };
    }
    catch {
        return { ...NO_CALIBRATION, calibratedHours: baseHours };
    }
}
//# sourceMappingURL=calibration-estimation.js.map