1use crate::core::Adr;
4use crate::export::{ExportResult, Exporter};
5use crate::Error;
6use std::path::Path;
7
8#[derive(Debug, Default)]
10pub struct DocxExporter {
11 pub include_frontmatter: bool,
13}
14
15impl DocxExporter {
16 #[must_use]
18 pub fn new() -> Self {
19 Self::default()
20 }
21
22 #[must_use]
24 pub fn with_frontmatter(mut self) -> Self {
25 self.include_frontmatter = true;
26 self
27 }
28}
29
30impl Exporter for DocxExporter {
31 fn export(&self, adr: &Adr, path: &Path) -> Result<(), Error> {
32 let _ = adr;
34 let _ = path;
35 Err(Error::ExportError {
36 message: "DOCX export not yet implemented".to_string(),
37 })
38 }
39
40 fn export_all(&self, adrs: &[Adr], dir: &Path) -> Result<ExportResult, Error> {
41 std::fs::create_dir_all(dir).map_err(|e| Error::IoError {
42 message: format!("Failed to create directory {}: {e}", dir.display()),
43 })?;
44
45 let mut result = ExportResult::default();
46
47 for adr in adrs {
48 let path = dir.join(format!("{}.docx", adr.id));
49 match self.export(adr, &path) {
50 Ok(()) => {
51 result.exported += 1;
52 result.files.push(path.display().to_string());
53 },
54 Err(e) => {
55 result.errors.push(format!("{}: {e}", adr.id));
56 },
57 }
58 }
59
60 Ok(result)
61 }
62}