package com.correx.core.journal

import com.correx.core.journal.model.DecisionJournalState

class DecisionJournalRenderer(private val keepLast: Int = 40) {
    fun render(state: DecisionJournalState, summaryText: String? = null): String {
        if (state.records.isEmpty() && summaryText == null) return ""
        return buildString {
            appendLine("## Decision history (chronological — ground truth)")
            if (summaryText != null) {
                appendLine(summaryText)
                if (state.lowSalienceOmittedCount > 0) {
                    appendLine("+${state.lowSalienceOmittedCount} routine transitions/retries omitted")
                }
            }
            state.records.takeLast(keepLast).forEach { appendLine("- [${it.kind}] ${it.summary}") }
        }.trimEnd()
    }
}
