/**
 * Validate the combined results from all teammates after parallel execution.
 * Checks for file conflicts between teammates and criteria coverage.
 */
export function validateTeamResults(teammateOutputs, expectedCriteria, fileOwnershipPlan) {
    // Detect file conflicts: same file modified by multiple teammates
    const fileToTeammates = new Map();
    for (const output of teammateOutputs) {
        for (const file of output.modifiedFiles) {
            const existing = fileToTeammates.get(file) ?? [];
            existing.push(output.name);
            fileToTeammates.set(file, existing);
        }
    }
    const fileConflicts = [...fileToTeammates.entries()]
        .filter(([, teammates]) => teammates.length > 1)
        .map(([file, teammates]) => ({ file, teammates }));
    // Also check ownership violations
    for (const [file, expectedOwner] of Object.entries(fileOwnershipPlan)) {
        const modifiers = fileToTeammates.get(file);
        if (modifiers?.length === 1 && modifiers[0] !== expectedOwner) {
            fileConflicts.push({
                file,
                teammates: [expectedOwner, modifiers[0] ?? 'unknown'],
            });
        }
    }
    // Check criteria coverage per spec
    const allCovered = new Set(teammateOutputs.flatMap((o) => o.coveredCriteria));
    const criteriaReport = [];
    for (const [specId, criteria] of Object.entries(expectedCriteria)) {
        const covered = criteria.filter((c) => allCovered.has(c)).length;
        criteriaReport.push({ specId, covered, total: criteria.length });
    }
    const allCriteriaMet = criteriaReport.every((r) => r.total === 0 || r.covered === r.total);
    const passed = allCriteriaMet && fileConflicts.length === 0;
    return {
        passed,
        typecheckPassed: true, // LLM runs these commands separately
        lintPassed: true,
        testsPassed: true,
        coveragePassed: true,
        fileConflicts,
        criteriaReport,
        mergeOrder: teammateOutputs.map((o) => o.name),
        summary: passed
            ? `All ${String(teammateOutputs.length)} teammates passed validation.`
            : `Validation issues: ${String(fileConflicts.length)} file conflict(s), ${String(criteriaReport.filter((r) => r.covered < r.total).length)} spec(s) with missing criteria.`,
    };
}
//# sourceMappingURL=result-validator.js.map