/**
 * Report Writer
 *
 * Generates markdown reports for technical debt, team structure, and other documentation.
 */
/**
 * Writes formatted markdown reports.
 */
export class ReportWriter {
    /**
     * Generate technical debt report in markdown format.
     */
    generateTechDebtReport(report) {
        const { items, summary } = report;
        let md = `# Technical Debt Report

**Generated**: ${new Date().toISOString().split('T')[0]}
**Total Items**: ${summary.totalCount}

---

## Summary

| Severity | Count | Description |
|----------|-------|-------------|
| **P1 (Critical)** | ${summary.p1Count} | Must fix - impacts production or security |
| **P2 (Important)** | ${summary.p2Count} | Should fix - reduces maintainability |
| **P3 (Nice-to-have)** | ${summary.p3Count} | Optional - minor improvements |

---

`;
        // Group by severity
        const p1Items = items.filter(i => i.severity === 'P1');
        const p2Items = items.filter(i => i.severity === 'P2');
        const p3Items = items.filter(i => i.severity === 'P3');
        // P1 Critical Issues
        if (p1Items.length > 0) {
            md += `## 🔴 P1 - Critical Issues\n\n`;
            md += `**These issues must be addressed immediately.**\n\n`;
            p1Items.forEach((item, index) => {
                md += this.formatTechDebtItem(item, index + 1);
            });
        }
        // P2 Important Issues
        if (p2Items.length > 0) {
            md += `## 🟡 P2 - Important Issues\n\n`;
            md += `**These issues should be addressed in the next sprint.**\n\n`;
            p2Items.forEach((item, index) => {
                md += this.formatTechDebtItem(item, index + 1);
            });
        }
        // P3 Nice-to-have
        if (p3Items.length > 0) {
            md += `## 🟢 P3 - Nice-to-have Improvements\n\n`;
            md += `**These improvements can be addressed when time permits.**\n\n`;
            p3Items.forEach((item, index) => {
                md += this.formatTechDebtItem(item, index + 1);
            });
        }
        // No issues
        if (items.length === 0) {
            md += `## ✅ No Technical Debt Detected\n\n`;
            md += `Great work! No significant technical debt was found during analysis.\n\n`;
        }
        // Footer
        md += `---\n\n`;
        md += `**Next Steps**:\n`;
        md += `1. Review all P1 issues and create tasks to address them\n`;
        md += `2. Prioritize P2 issues for next sprint planning\n`;
        md += `3. Consider P3 improvements during refactoring cycles\n\n`;
        md += `Generated by SpecWeave Intelligent Living Docs\n`;
        return md;
    }
    /**
     * Format individual tech debt item.
     */
    formatTechDebtItem(item, index) {
        const location = item.lineNumber
            ? `${item.file}:${item.lineNumber}`
            : item.file;
        let md = `### ${index}. ${this.getCategoryLabel(item.category)}\n\n`;
        md += `**File**: \`${location}\`\n\n`;
        md += `**Description**: ${item.description}\n\n`;
        md += `**Impact**: ${item.impact}\n\n`;
        md += `**Recommendation**: ${item.recommendation}\n\n`;
        md += `**Estimated Effort**: ${item.estimatedEffort}\n\n`;
        md += `---\n\n`;
        return md;
    }
    /**
     * Get human-readable category label.
     */
    getCategoryLabel(category) {
        const labels = {
            'large-file': 'Large File (>1000 lines)',
            'high-complexity': 'High Complexity Function',
            'outdated-deps': 'Outdated Dependencies',
            'pattern-inconsistency': 'Pattern Inconsistency',
            'circular-dep': 'Circular Dependency',
        };
        return labels[category] || category;
    }
    /**
     * Generate team structure documentation.
     */
    generateTeamStructure(teams) {
        let md = `# Team Structure & Ownership

**Generated**: ${new Date().toISOString().split('T')[0]}
**Teams**: ${teams.length}

---

## Overview

This document describes the team structure, module ownership, and technical responsibilities across the organization.

---

`;
        teams.forEach((team, index) => {
            md += `## ${index + 1}. ${team.name}\n\n`;
            if (team.contact) {
                md += `**Contact**: ${team.contact}\n\n`;
            }
            md += `**Repositories**:\n`;
            team.repos.forEach(repo => {
                md += `- \`${repo}\`\n`;
            });
            md += `\n`;
            md += `**Owned Modules**:\n`;
            team.modules.forEach(module => {
                md += `- ${module}\n`;
            });
            md += `\n`;
            md += `**Tech Stack**:\n`;
            team.techStack.forEach(tech => {
                md += `- ${tech}\n`;
            });
            md += `\n`;
            md += `---\n\n`;
        });
        // Footer
        md += `**Note**: This document is automatically generated from codebase analysis and configuration files. Update team information in \`.specweave/config.json\` to reflect changes.\n\n`;
        md += `Generated by SpecWeave Intelligent Living Docs\n`;
        return md;
    }
    /**
     * Generate organization chart in Mermaid format.
     */
    generateOrgChart(teams) {
        let mmd = `graph TD\n`;
        mmd += `  ROOT[Organization]\n\n`;
        teams.forEach(team => {
            const teamId = this.sanitizeId(team.name);
            mmd += `  ROOT --> ${teamId}["${team.name}"]\n`;
            // Add repos under each team
            team.repos.forEach(repo => {
                const repoId = this.sanitizeId(`${team.name}-${repo}`);
                mmd += `  ${teamId} --> ${repoId}["${repo}"]\n`;
            });
            mmd += `\n`;
        });
        return mmd;
    }
    /**
     * Sanitize ID for Mermaid diagrams.
     */
    sanitizeId(id) {
        return id.replace(/[^a-zA-Z0-9_]/g, '_');
    }
}
//# sourceMappingURL=report-writer.js.map