// tools/analytics-report-handler.ts — Unified analytics_report handler (SPEC-556)
// Consolidates: velocity_report, velocity_trend, tech_debt_report,
//               estimation_accuracy_report, team_analytics into one tool.
import { handleVelocityReport, handleVelocityTrend } from './velocity-handler.js';
import { handleEstimationAccuracyReport } from './estimation-accuracy-handler.js';
import { handleTechDebtReport } from './tech-debt-handler.js';
import { handleTeamAnalytics } from './team-analytics-handler.js';
import { formatError, toolResult } from './response-helpers.js';
import { hashProjectPath } from '../storage/base-store.js';
// ---------------------------------------------------------------------------
// Main handler
// ---------------------------------------------------------------------------
export async function handleAnalyticsReport(args) {
    const { type, window: windowDays = 30 } = args;
    // Resolve projectPath — required for most sub-handlers
    const projectPath = args.projectPath?.trim() ?? '';
    const projectId = args.projectId?.trim() ?? (projectPath ? hashProjectPath(projectPath) : '');
    if (!projectPath && !projectId) {
        return toolResult(formatError('projectPath or projectId is required', 'Provide the absolute path to your project root via projectPath.'), undefined, true);
    }
    // Convert window (days) to weeks for velocity handlers
    const weeks = Math.max(1, Math.round(windowDays / 7));
    switch (type) {
        case 'velocity':
            return handleVelocityReport({ projectPath, weeks });
        case 'velocity-trend':
            return handleVelocityTrend({ projectPath, compareWeeks: Math.max(1, Math.floor(weeks / 2)) });
        case 'tech-debt':
            if (!projectPath) {
                return toolResult(formatError('projectPath is required for tech-debt report', 'Provide the absolute path to your project root.'), undefined, true);
            }
            return handleTechDebtReport({ projectPath });
        case 'estimation-accuracy':
            return handleEstimationAccuracyReport({ projectId, projectPath: projectPath || undefined });
        case 'team':
            return handleTeamAnalytics({ projectPath, weeks });
        default: {
            // TypeScript exhaustiveness guard — should never reach here at runtime
            const exhaustive = type;
            return toolResult(formatError(`Unknown report type: "${String(exhaustive)}"`, 'Valid types: velocity, velocity-trend, tech-debt, estimation-accuracy, team'), undefined, true);
        }
    }
}
//# sourceMappingURL=analytics-report-handler.js.map