function technicalSectionRef(spec) {
    return `${spec.specPath}#technical`;
}
// ---------------------------------------------------------------------------
// Title generation
// ---------------------------------------------------------------------------
/**
 * Generate a PR title from a spec.
 * Uses 'fix' prefix for critical/high risk specs, 'feat' otherwise.
 * Title is truncated to keep the full header under 72 characters.
 */
export function generatePrTitle(spec) {
    const prefix = spec.risk === 'critical' || spec.risk === 'high' ? 'fix' : 'feat';
    const scope = spec.id;
    const maxTitleLen = 72 - prefix.length - scope.length - 4; // "prefix(scope): "
    const title = spec.title.length > maxTitleLen ? `${spec.title.slice(0, maxTitleLen - 1)}…` : spec.title;
    return `${prefix}(${scope}): ${title}`;
}
// ---------------------------------------------------------------------------
// Label generation
// ---------------------------------------------------------------------------
/**
 * Generate GitHub/GitLab-style labels from a spec.
 */
export function generateLabels(spec) {
    const labels = [];
    // Priority label from risk
    labels.push(`priority:${spec.risk}`);
    // Type label
    labels.push(`type:${spec.type}`);
    // Scope label
    labels.push(`scope:${spec.scope}`);
    // Difficulty label
    labels.push(`difficulty:${spec.difficulty}`);
    // Tag-based labels (only first 3 to avoid noise)
    const tagLabels = spec.tags.slice(0, 3).map((t) => `tag:${t}`);
    labels.push(...tagLabels);
    return labels;
}
// ---------------------------------------------------------------------------
// Markdown section builders (platform-specific)
// ---------------------------------------------------------------------------
function buildGithubMarkdown(spec, audience, includeChecklist) {
    const sections = [];
    sections.push(`## Summary`);
    sections.push(audience === 'stakeholder'
        ? `This PR implements **${spec.title}** (${spec.id}).`
        : `Implements **${spec.title}** (${spec.id}).`);
    sections.push('');
    sections.push(`## Changes`);
    sections.push(`- Spec: \`${spec.specPath}\``);
    sections.push(`- Technical design: \`${technicalSectionRef(spec)}\``);
    if (spec.tags.length > 0) {
        sections.push(`- Tags: ${spec.tags.join(', ')}`);
    }
    sections.push('');
    sections.push(`## Acceptance Criteria`);
    sections.push(`See [spec.md](${spec.specPath}) for the full acceptance criteria defined in the Planu spec.`);
    sections.push('');
    sections.push(`## Test Plan`);
    sections.push(`- [ ] All acceptance criteria verified`);
    sections.push(`- [ ] Unit tests passing`);
    sections.push(`- [ ] Integration tests passing`);
    sections.push('');
    if (spec.dependencies.length > 0) {
        sections.push(`## Notes`);
        sections.push(`**Dependencies:** ${spec.dependencies.join(', ')}`);
        sections.push('');
    }
    if (includeChecklist) {
        sections.push(`### Checklist`);
        sections.push(`- [ ] Code follows project conventions`);
        sections.push(`- [ ] Tests added or updated`);
        sections.push(`- [ ] Documentation updated`);
        sections.push(`- [ ] No linting errors`);
        sections.push(`- [ ] Spec validated with \`planu validate\``);
        sections.push('');
    }
    return sections.join('\n');
}
function buildGitlabMarkdown(spec, audience, includeChecklist) {
    const sections = [];
    sections.push(`## What`);
    sections.push(audience === 'stakeholder'
        ? `This MR delivers **${spec.title}** (${spec.id}).`
        : `Implements **${spec.title}** (${spec.id}).`);
    sections.push('');
    sections.push(`## Why`);
    sections.push(`Required by Planu spec ${spec.id}. Risk level: **${spec.risk}**. Difficulty: **${spec.difficulty}/5**.`);
    sections.push('');
    sections.push(`## How`);
    sections.push(`See \`${technicalSectionRef(spec)}\` for implementation details.`);
    if (spec.tags.length > 0) {
        sections.push(`Tags: ${spec.tags.join(', ')}`);
    }
    sections.push('');
    sections.push(`## Testing`);
    sections.push(`- [ ] All acceptance criteria verified`);
    sections.push(`- [ ] Tests pass locally`);
    sections.push('');
    if (includeChecklist) {
        sections.push(`## Checklist`);
        sections.push(`- [ ] Code reviewed`);
        sections.push(`- [ ] Tests added or updated`);
        sections.push(`- [ ] No breaking changes (or documented)`);
        sections.push(`- [ ] Spec validated with \`planu validate\``);
        sections.push('');
    }
    return sections.join('\n');
}
function buildLinearMarkdown(spec, audience, includeChecklist) {
    const sections = [];
    sections.push(`## Summary`);
    sections.push(audience === 'stakeholder'
        ? `Delivers **${spec.title}** (${spec.id}).`
        : `Implements **${spec.title}** (${spec.id}).`);
    sections.push('');
    sections.push(`## Changes`);
    sections.push(`- Risk: ${spec.risk}`);
    sections.push(`- Difficulty: ${spec.difficulty}/5`);
    if (spec.tags.length > 0) {
        sections.push(`- Tags: ${spec.tags.join(', ')}`);
    }
    sections.push('');
    sections.push(`## Testing`);
    sections.push(`- [ ] Acceptance criteria met`);
    sections.push(`- [ ] Tests passing`);
    if (includeChecklist) {
        sections.push('');
        sections.push(`- [ ] Code reviewed`);
        sections.push(`- [ ] Spec validated`);
    }
    sections.push('');
    return sections.join('\n');
}
// ---------------------------------------------------------------------------
// Main generator
// ---------------------------------------------------------------------------
/**
 * Generate a complete PR description for a spec.
 */
export function generatePrDescription(spec, platform, audience, includeChecklist) {
    let markdown;
    if (platform === 'gitlab') {
        markdown = buildGitlabMarkdown(spec, audience, includeChecklist);
    }
    else if (platform === 'linear') {
        markdown = buildLinearMarkdown(spec, audience, includeChecklist);
    }
    else {
        markdown = buildGithubMarkdown(spec, audience, includeChecklist);
    }
    return {
        specId: spec.id,
        specTitle: spec.title,
        markdown,
        titleSuggestion: generatePrTitle(spec),
        labels: generateLabels(spec),
        generatedAt: new Date().toISOString(),
    };
}
//# sourceMappingURL=pr-description-generator.js.map