/**
 * Generate initial progress.md content for a newly created spec.
 */
export function generateProgressContent(spec) {
    const sections = [
        { title: 'Progress', content: buildHeader(spec) },
        { title: 'Status History', content: buildStatusHistory(spec) },
        { title: 'Metrics', content: buildMetrics(spec) },
    ];
    return sections.map((s) => `## ${s.title}\n\n${s.content}`).join('\n\n---\n\n');
}
/**
 * Generate an updated progress.md reflecting a status change.
 */
export function generateProgressUpdate(spec, previousStatus, existingContent) {
    const timestamp = new Date().toISOString();
    const entry = `| ${timestamp} | ${previousStatus} → ${spec.status} |`;
    if (existingContent.includes('| Timestamp')) {
        return existingContent.replace(/((?:\|[^\n]*\n)+)/, `$1${entry}\n`);
    }
    return generateProgressContent(spec);
}
function buildHeader(spec) {
    const lines = [
        `**Spec:** ${spec.id}`,
        `**Title:** ${spec.title}`,
        `**Status:** ${spec.status}`,
        `**Created:** ${spec.createdAt}`,
        `**Last Updated:** ${spec.updatedAt}`,
        '',
        `**Difficulty:** ${spec.difficulty} | **Risk:** ${spec.risk}`,
        `**Target:** ${spec.target} | **Scope:** ${spec.scope}`,
    ];
    if (spec.gitBranch) {
        lines.push(`**Branch:** \`${spec.gitBranch}\``);
    }
    return lines.join('\n');
}
function buildStatusHistory(spec) {
    return [
        '| Timestamp | Transition |',
        '|-----------|-----------|',
        `| ${spec.createdAt} | → ${spec.status} |`,
    ].join('\n');
}
function buildMetrics(spec) {
    const est = spec.estimation;
    const lines = [
        '| Metric | Estimated | Actual |',
        '|--------|-----------|--------|',
        `| Dev Hours | ${String(est.devHours)} | - |`,
        `| Review Hours | ${String(est.reviewHours)} | - |`,
        `| Total Cost (USD) | $${String(est.totalCostUsd)} | - |`,
    ];
    if (spec.actuals) {
        const act = spec.actuals;
        lines[2] = `| Dev Hours | ${String(est.devHours)} | ${String(act.devHours)} |`;
        lines[3] = `| Review Hours | ${String(est.reviewHours)} | ${String(act.reviewHours)} |`;
        lines[4] = `| Total Cost (USD) | $${String(est.totalCostUsd)} | $${String(act.totalCostUsd)} |`;
    }
    return lines.join('\n');
}
//# sourceMappingURL=progress-writer.js.map