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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#[derive(Debug, Clone)]
pub struct QueryParamsBuilder {
    skip_count: Option<(String, String)>,
    omit_total_items: Option<(String, String)>, // bool
    order_by: Option<(String, String)>,
    max_items: Option<(String, String)>,
    where_filter: Option<(String, String)>,
    include: Option<(String, String)>,
    fields: Option<(String, String)>,
    relative_path: Option<(String, String)>,
}

impl QueryParamsBuilder {
    pub fn new() -> Self {
        QueryParamsBuilder {
            skip_count: None,
            omit_total_items: None,
            order_by: None,
            max_items: None,
            where_filter: None,
            include: None,
            fields: None,
            relative_path: None,
        }
    }

    pub fn set_skip_count(mut self, value: Option<&u32>) -> Self {
        if let Some(skip) = value {
            self.skip_count = Some(("skipCount".to_string(), skip.to_string()));
        }

        self
    }

    pub fn set_omit_total_items(mut self, value: Option<&bool>) -> Self {
        if let Some(omit) = value {
            self.omit_total_items = Some(("omitTotalItems".to_string(), omit.to_string()));
        }

        self
    }

    pub fn push_order_by(mut self, value: Option<&str>) -> Self {
        if let Some(order_val) = value {
            match self.order_by {
                Some(orders) => {
                    let mut order_fields = orders.1.clone();
                    order_fields.push_str(&format!(",{}", order_val));
                    self.order_by = Some(("orderBy".to_string(), order_fields));
                },
                None => self.order_by = Some(("orderBy".to_string(), order_val.to_string()))
            }
        }

        self
    }

    pub fn set_max_items(mut self, value: Option<&u32>) -> Self {
        if let Some(max) = value {
            self.max_items = Some(("maxItems".to_string(), max.to_string()));
        }

        self
    }

    pub fn set_where_filter(mut self, value: Option<&String>) -> Self {
        if let Some(filter) = value {
            self.where_filter = Some(("where".to_string(), filter.to_string()));
        }

        self
    }

    pub fn push_field(mut self, value: Option<&str>) -> Self {
        if let Some(field_val) = value {
            match self.fields {
                Some(fields) => {
                    let mut field_fields = fields.1.clone();
                    field_fields.push_str(&format!(",{}", field_val));
                    self.fields = Some(("fields".to_string(), field_fields));
                },
                None => self.fields = Some(("fields".to_string(), field_val.to_string()))
            }
        }

        self
    }

    pub fn push_include(mut self, value: Option<&str>) -> Self {
        if let Some(include_val) = value {
            match self.include {
                Some(include) => {
                    let mut include_fields = include.1.clone();
                    include_fields.push_str(&format!(",{}", include_val));
                    self.include = Some(("include".to_string(), include_fields));
                },
                None => self.include = Some(("include".to_string(), include_val.to_string()))
            }
        }

        self
    }

    pub fn set_relative_path(mut self, value: Option<&String>) -> Self {
        if let Some(filter) = value {
            self.relative_path = Some(("relativePath".to_string(), filter.to_string()));
        }

        self
    }

    pub fn get_skip_count(&mut self) -> &Option<(String, String)> { &self.skip_count }

    pub fn get_omit_total_items(&mut self) -> &Option<(String, String)> { &self.omit_total_items }

    pub fn get_order_by(&mut self) -> &Option<(String, String)> { &self.order_by }

    pub fn get_max_items(&mut self) -> &Option<(String, String)> { &self.max_items }

    pub fn get_where_filter(&mut self) -> &Option<(String, String)> { &self.where_filter }

    pub fn get_fields(&mut self) -> &Option<(String,String)> { &self.fields }

    pub fn get_include(&mut self) -> &Option<(String, String)> { &self.include }

    pub fn get_relative_path(&mut self) -> &Option<(String, String)> { &self.relative_path }



    pub fn build(&mut self) -> Vec<(String, String)> {
        let mut vector = Vec::new();

        if let Some(skip_count) = &self.skip_count {
            vector.push(skip_count.clone());
        };

        if let Some(omit_total_items) = &self.omit_total_items {
            vector.push(omit_total_items.clone());
        }

        if let Some(order) = &self.order_by {
            vector.push(order.clone());
        };

        if let Some(max_items) = &self.max_items {
            vector.push(max_items.clone());
        };

        if let Some(where_filter) = &self.where_filter {
            vector.push(where_filter.clone());
        };

        if let Some(fields) = &self.fields {
            vector.push(fields.clone());
        };

        if let Some(include) = &self.include {
            vector.push(include.clone());
        };

        if let Some(relative_path) = &self.relative_path {
            vector.push(relative_path.clone());
        };

        vector
    }
}