1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use serde::Serialize;

use crate::documents::BuildXML;
use crate::xml_builder::*;

#[derive(Debug, Clone, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct CommentExtended {
    pub paragraph_id: String,
    pub done: bool,
    pub parent_paragraph_id: Option<String>,
}

impl CommentExtended {
    pub fn new(paragraph_id: impl Into<String>) -> CommentExtended {
        Self {
            paragraph_id: paragraph_id.into(),
            done: false,
            parent_paragraph_id: None,
        }
    }

    pub fn done(mut self) -> CommentExtended {
        self.done = true;
        self
    }

    pub fn parent_paragraph_id(mut self, id: impl Into<String>) -> CommentExtended {
        self.parent_paragraph_id = Some(id.into());
        self
    }
}

impl BuildXML for CommentExtended {
    fn build(&self) -> Vec<u8> {
        XMLBuilder::new()
            .comment_extended(&self.paragraph_id, self.done, &self.parent_paragraph_id)
            .build()
    }
}

#[cfg(test)]
mod tests {

    use super::*;
    #[cfg(test)]
    use pretty_assertions::assert_eq;
    #[test]
    fn test_comment_extended_json() {
        let ex = CommentExtended {
            paragraph_id: "00002".to_owned(),
            done: false,
            parent_paragraph_id: Some("0004".to_owned()),
        };
        assert_eq!(
            serde_json::to_string(&ex).unwrap(),
            r#"{"paragraphId":"00002","done":false,"parentParagraphId":"0004"}"#
        );
    }
}