import { SECTION_HEADERS } from '../constants/compaction/index.js';
const PLAN_STATUS_ICONS = {
    pending: '\u25CB',
    active: '\u25C9',
    done: '\u2713',
    skipped: '\u2717',
};
function renderPlan(plan) {
    return plan.map((slot) => `- ${PLAN_STATUS_ICONS[slot.status]} ${slot.label}`).join('\n');
}
function renderFiles(files) {
    const lines = [];
    for (const [, slot] of files) {
        lines.push(`- \`${slot.path}\``);
        for (const action of slot.actions) {
            if (action.type === 'delete') {
                lines.push('  - deleted');
            }
            else {
                const desc = 'detail' in action ? action.detail : action.summary;
                lines.push(`  - ${action.type}: ${desc ?? ''}`);
            }
        }
    }
    return lines.join('\n');
}
function renderList(items) {
    return items.map((item) => `- ${item}`).join('\n');
}
function renderToolResults(results) {
    return results.map((r) => `- **${r.tool}**: ${r.summary}`).join('\n');
}
export function serializeState(state) {
    const sections = [];
    if (state.task) {
        sections.push(`${SECTION_HEADERS.task}\n\n${state.task}`);
    }
    if (state.userRequirements.length > 0) {
        sections.push(`${SECTION_HEADERS.userRequirements}\n\n${renderList(state.userRequirements)}`);
    }
    if (state.plan.length > 0) {
        sections.push(`${SECTION_HEADERS.plan}\n\n${renderPlan(state.plan)}`);
    }
    if (state.environment.length > 0) {
        sections.push(`${SECTION_HEADERS.environment}\n\n${renderList(state.environment)}`);
    }
    if (state.files.size > 0) {
        sections.push(`${SECTION_HEADERS.files}\n\n${renderFiles(state.files)}`);
    }
    if (state.decisions.length > 0) {
        sections.push(`${SECTION_HEADERS.decisions}\n\n${renderList(state.decisions)}`);
    }
    if (state.assistantNotes.length > 0) {
        sections.push(`${SECTION_HEADERS.assistantNotes}\n\n${renderList(state.assistantNotes)}`);
    }
    if (state.toolResults.length > 0) {
        sections.push(`${SECTION_HEADERS.toolResults}\n\n${renderToolResults(state.toolResults)}`);
    }
    if (state.failures.length > 0) {
        sections.push(`${SECTION_HEADERS.failures}\n\n${renderList(state.failures)}`);
    }
    if (state.discoveries.length > 0) {
        sections.push(`${SECTION_HEADERS.discoveries}\n\n${renderList(state.discoveries)}`);
    }
    return sections.join('\n\n');
}
//# sourceMappingURL=serializer.js.map