#ifndef HUSH_MARKDOWN_IO_H
#define HUSH_MARKDOWN_IO_H
#include "document.h"
#include <stdbool.h>
/* Replaces the contents of `doc` with the parsed contents of the file at `path`.
Returns false (and leaves `doc` untouched) if the file could not be read. */
bool document_load_file(Document *doc, const char *path);
/* Serializes `doc` to markdown and writes it to `path`. Returns false on I/O failure. */
bool document_save_file(Document *doc, const char *path);
/* Serializes `doc` to markdown into `out` (cleared first). The single source of truth for
markdown serialization -- both document_save_file and document_compute_stats use it. */
void document_serialize(Document *doc, StrBuf *out);
typedef struct {
long byteSize; /* length of the serialized markdown, in bytes */
int lineCount; /* number of '\n' bytes in the serialized markdown (wc -l semantics) */
} DocStats;
/* Computes size/line-count stats for `doc` via document_serialize, without touching disk. */
void document_compute_stats(Document *doc, DocStats *out);
#endif