rust_woocommerce/controllers/
order_notes.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3#[skip_serializing_none]
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct OrderNotesCreate {
6    note: String,
7    customer_note: bool,
8    added_by_user: Option<bool>,
9}
10#[derive(Default)]
11pub struct NoNote;
12pub struct WithNote(String);
13#[derive(Default)]
14pub struct OrderNotesCreateBuilder<T> {
15    note: T,
16    customer_note: Option<bool>,
17    added_by_user: Option<bool>,
18}
19impl<T> OrderNotesCreateBuilder<T> {
20    pub fn new() -> OrderNotesCreateBuilder<NoNote> {
21        OrderNotesCreateBuilder::default()
22    }
23    /// Order note content.
24    pub fn note(self, note: impl Into<String>) -> OrderNotesCreateBuilder<WithNote> {
25        OrderNotesCreateBuilder {
26            note: WithNote(note.into()),
27            customer_note: self.customer_note,
28            added_by_user: self.customer_note,
29        }
30    }
31    /// If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only. Default is false.    
32    pub fn customer_note(mut self) -> Self {
33        let _ = self.customer_note.insert(true);
34        self
35    }
36    /// If true, this note will be attributed to the current user. If false, the note will be attributed to the system. Default is false.    
37    pub fn added_by_user(mut self) -> Self {
38        let _ = self.added_by_user.insert(true);
39        self
40    }
41}
42impl OrderNotesCreateBuilder<WithNote> {
43    pub fn build(self) -> OrderNotesCreate {
44        OrderNotesCreate {
45            note: self.note.0,
46            customer_note: self.customer_note.unwrap_or_default(),
47            added_by_user: self.added_by_user,
48        }
49    }
50}
51#[skip_serializing_none]
52#[derive(Debug, Clone, Serialize, Deserialize, Default)]
53pub struct OrderNotesUpdate {
54    id: i32,
55    note: Option<String>,
56    customer_note: Option<bool>,
57    added_by_user: Option<bool>,
58}
59#[derive(Default)]
60pub struct NoId;
61pub struct WithId(i32);
62#[derive(Default)]
63pub struct OrderNotesUpdateBuilder<I> {
64    id: I,
65    note: Option<String>,
66    customer_note: Option<bool>,
67    added_by_user: Option<bool>,
68}
69impl<I> OrderNotesUpdateBuilder<I> {
70    pub fn new() -> OrderNotesUpdateBuilder<NoId> {
71        OrderNotesUpdateBuilder::default()
72    }
73    /// Unique identifier for the resource.
74    pub fn id(self, id: i32) -> OrderNotesUpdateBuilder<WithId> {
75        OrderNotesUpdateBuilder {
76            id: WithId(id),
77            note: self.note,
78            customer_note: self.customer_note,
79            added_by_user: self.added_by_user,
80        }
81    }
82    /// Order note content.
83    pub fn note(mut self, note: impl Into<String>) -> Self {
84        let _ = self.note.insert(note.into());
85        self
86    }
87    /// If true, the note will be shown to customers and they will be notified. If false, the note will be for admin reference only. Default is false.    
88    pub fn customer_note(mut self) -> Self {
89        let _ = self.customer_note.insert(true);
90        self
91    }
92    /// If true, this note will be attributed to the current user. If false, the note will be attributed to the system. Default is false.    
93    pub fn added_by_user(mut self) -> Self {
94        let _ = self.added_by_user.insert(true);
95        self
96    }
97}
98impl OrderNotesUpdateBuilder<WithId> {
99    pub fn build(self) -> OrderNotesUpdate {
100        OrderNotesUpdate {
101            id: self.id.0,
102            note: self.note,
103            customer_note: self.customer_note,
104            added_by_user: self.added_by_user,
105        }
106    }
107}