// Planu — Team Document Generators
// Generates team-type documents: architecture-decision-log, contributing
// ── Private helpers ──────────────────────────────────────────────────────────
function buildAdrIndexSection(adrs) {
    return {
        title: 'Index',
        level: 2,
        content: adrs
            .map((s, idx) => {
            const statusIcon = s.status === 'done' ? '✅' : s.status === 'implementing' ? '🔄' : '📝';
            return `${idx + 1}. ${statusIcon} [${s.id}: ${s.title}](#${s.id.toLowerCase().replace(/[^a-z0-9]/g, '-')}) — ${s.status}`;
        })
            .join('\n'),
    };
}
function buildAdrStatusSections(accepted, inProgress, pending, draft) {
    const sections = [];
    if (accepted.length > 0) {
        sections.push({
            title: 'Accepted Decisions',
            level: 2,
            content: accepted
                .map((s) => [
                `### ${s.id}: ${s.title}`,
                '',
                `**Status:** Accepted | **Date:** ${s.updatedAt}`,
                s.tags.length > 0 ? `**Tags:** ${s.tags.join(', ')}` : '',
                '',
                `**Dependencies:** ${s.dependencies.length > 0 ? s.dependencies.join(', ') : 'none'}`,
                '',
                `See [${s.id}](${s.specPath}) for full details and acceptance criteria.`,
            ]
                .filter(Boolean)
                .join('\n'))
                .join('\n\n'),
        });
    }
    if (inProgress.length > 0) {
        sections.push({
            title: 'In Progress',
            level: 2,
            content: inProgress
                .map((s) => `### ${s.id}: ${s.title}\n\n**Status:** In Progress — decision being implemented.\n\nSee [${s.id}](${s.specPath}) for details.`)
                .join('\n\n'),
        });
    }
    /* v8 ignore start */ // pending-review branch — requires spec with 'pending' status (rare in tests)
    if (pending.length > 0) {
        sections.push({
            title: 'Pending Review',
            level: 2,
            content: pending
                .map((s) => `### ${s.id}: ${s.title}\n\n**Status:** Pending review — awaiting team approval.`)
                .join('\n\n'),
        });
    }
    /* v8 ignore stop */
    if (draft.length > 0) {
        sections.push({
            title: 'Drafts',
            level: 2,
            content: draft
                .map((s) => `### ${s.id}: ${s.title}\n\n**Status:** Draft — not yet finalized.`)
                .join('\n\n'),
        });
    }
    return sections;
}
function buildConventionLines(knowledge) {
    const conventions = knowledge.conventions;
    const linters = knowledge.linting.detectedLinters;
    const lines = [];
    for (const [key, value] of Object.entries(conventions)) {
        lines.push(`- **${key}**: ${value}`);
    }
    if (linters.length > 0) {
        const linterNames = linters.map((l) => l.tool).join(', ');
        lines.push(`- **Linters**: ${linterNames}`);
    }
    if (knowledge.packageManager) {
        lines.push(`- **Package manager**: ${knowledge.packageManager}`);
    }
    return lines;
}
function buildContributingConventionsSection(knowledge) {
    const conventionLines = buildConventionLines(knowledge);
    return {
        title: 'Code Conventions',
        level: 2,
        content: conventionLines.length > 0
            ? conventionLines.join('\n')
            : [
                '[EN DESARROLLO] No code conventions detected automatically.',
                '',
                'Configure `.editorconfig` and add linters to the project to auto-populate this section.',
            ].join('\n'),
    };
}
// ── Public generators ────────────────────────────────────────────────────────
/**
 * Generate a navigable Architecture Decision Log from all specs.
 * Groups by status (accepted/in-progress/draft) and builds a cross-linked index.
 */
export function generateArchitectureDecisionLog(specs, _language) {
    const adrs = specs.filter((s) => s.type === 'infra' || s.type === 'docs');
    const accepted = adrs.filter((s) => s.status === 'done');
    const inProgress = adrs.filter((s) => s.status === 'implementing');
    const pending = adrs.filter((s) => s.status === 'approved' || s.status === 'review');
    const draft = adrs.filter((s) => s.status === 'draft');
    const sections = [
        {
            title: 'Overview',
            level: 2,
            content: [
                'This document consolidates all Architecture Decision Records (ADRs) for this project.',
                '',
                `Total ADRs: ${adrs.length}`,
                `- Accepted: ${accepted.length}`,
                `- In Progress: ${inProgress.length}`,
                `- Pending Review: ${pending.length}`,
                `- Draft: ${draft.length}`,
            ].join('\n'),
        },
    ];
    if (adrs.length === 0) {
        sections.push({
            title: 'No ADRs Found',
            level: 2,
            content: [
                '[EN DESARROLLO] No architectural decision records found.',
                '',
                'Create specs of type `infra` or `docs` to document architectural decisions.',
                'Each decision should describe: context, options considered, decision made, and consequences.',
            ].join('\n'),
        });
    }
    else {
        sections.push(buildAdrIndexSection(adrs));
        sections.push(...buildAdrStatusSections(accepted, inProgress, pending, draft));
    }
    const content = `# Architecture Decision Log\n\n` +
        sections.map((s) => `${'#'.repeat(s.level)} ${s.title}\n\n${s.content}`).join('\n\n');
    return {
        type: 'architecture-decision-log',
        title: 'Architecture Decision Log',
        path: 'docs/adr/index.md',
        content,
        audience: 'developer',
        sections,
        diagrams: [],
        relatedSpecs: adrs.map((s) => s.id),
    };
}
/**
 * Generate CONTRIBUTING.md with code conventions, PR process, review criteria,
 * and references to the SDD workflow detected from project configuration.
 */
export function generateContributing(knowledge, _language) {
    const sections = [
        {
            title: 'Welcome',
            level: 2,
            content: [
                'Thank you for contributing! This guide explains how to work on this project effectively.',
                '',
                'This project follows **Spec Driven Development (SDD)**: write the specification before writing code.',
            ].join('\n'),
        },
        buildContributingConventionsSection(knowledge),
        {
            title: 'Development Workflow',
            level: 2,
            content: [
                '### SDD Process',
                '',
                '1. **Create a spec** — Define what you want to build before writing code using `create_spec`.',
                '2. **Get approval** — Review the spec with the team.',
                '3. **Create a branch** — Branch from `main` with the spec ID (e.g., `feat/SPEC-042-auth`).',
                '4. **Implement** — Follow the spec acceptance criteria step by step.',
                '5. **Validate** — Run `validate_spec` to check implementation compliance.',
                '6. **Open a PR** — Reference the spec ID in the PR title and description.',
            ].join('\n'),
        },
        {
            title: 'Pull Request Process',
            level: 2,
            content: [
                `1. Ensure all tests pass: \`${knowledge.testCommand ?? 'npm test'}\``,
                `2. Ensure the build succeeds: \`${knowledge.buildCommand ?? 'npm run build'}\``,
                '3. Include the spec ID in your PR title: `feat(SPEC-042): add user authentication`',
                '4. Link the PR to the spec in the description.',
                '5. Request review from at least one team member.',
                '6. Address all review comments before merging.',
            ].join('\n'),
        },
        {
            title: 'Review Criteria',
            level: 2,
            content: [
                'Pull requests are reviewed for:',
                '',
                '- [ ] All spec acceptance criteria are met',
                '- [ ] Tests cover new functionality (95%+ branch coverage)',
                '- [ ] No linting errors or TypeScript type errors',
                '- [ ] Code follows project conventions (see Code Conventions above)',
                '- [ ] No sensitive data (secrets, PII) committed',
                '- [ ] Documentation updated if public API changed',
            ].join('\n'),
        },
        {
            title: 'Getting Help',
            level: 2,
            content: [
                '- Read the [Architecture Documentation](docs/architecture.md) to understand the codebase.',
                `- Check existing specs in the \`${knowledge.specLocation}\` directory.`,
                '- Ask in the team channel or open a GitHub Discussion.',
            ].join('\n'),
        },
    ];
    const content = `# Contributing Guide\n\n` +
        sections.map((s) => `${'#'.repeat(s.level)} ${s.title}\n\n${s.content}`).join('\n\n');
    return {
        type: 'contributing',
        title: 'Contributing Guide',
        path: 'CONTRIBUTING.md',
        content,
        audience: 'developer',
        sections,
        diagrams: [],
        relatedSpecs: [],
    };
}
//# sourceMappingURL=team-generators.js.map