1use crate::client::{Client, ParamType};
2use std::collections::HashMap;
3use crate::services::AppwriteException;
4use crate::models;
5use serde_json::json;
6use std::io::Read;
7
8#[derive(Clone)]
9pub struct Health {
10 client: Client
11}
12
13impl Health {
14 pub fn new(client: &Client) -> Self {
15 Self {
16 client: client.clone()
17 }
18 }
19
20 pub fn get(&self) -> Result<models::HealthStatus, AppwriteException> {
22 let path = "/health";
23 let headers: HashMap<String, String> = [
24 ("content-type".to_string(), "application/json".to_string()),
25 ].iter().cloned().collect();
26
27 let params: HashMap<String, ParamType> = [
28 ].iter().cloned().collect();
29
30 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
31
32 let processedResponse:models::HealthStatus = match response {
33 Ok(r) => {
34 match r.json() {
35 Ok(json) => json,
36 Err(e) => {
37 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
38 }
39 }
40 }
41 Err(e) => {
42 return Err(e);
43 }
44 };
45
46 Ok(processedResponse)
47 }
48
49 pub fn get_antivirus(&self) -> Result<models::HealthAntivirus, AppwriteException> {
51 let path = "/health/anti-virus";
52 let headers: HashMap<String, String> = [
53 ("content-type".to_string(), "application/json".to_string()),
54 ].iter().cloned().collect();
55
56 let params: HashMap<String, ParamType> = [
57 ].iter().cloned().collect();
58
59 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
60
61 let processedResponse:models::HealthAntivirus = match response {
62 Ok(r) => {
63 match r.json() {
64 Ok(json) => json,
65 Err(e) => {
66 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
67 }
68 }
69 }
70 Err(e) => {
71 return Err(e);
72 }
73 };
74
75 Ok(processedResponse)
76 }
77
78 pub fn get_cache(&self) -> Result<models::HealthStatus, AppwriteException> {
81 let path = "/health/cache";
82 let headers: HashMap<String, String> = [
83 ("content-type".to_string(), "application/json".to_string()),
84 ].iter().cloned().collect();
85
86 let params: HashMap<String, ParamType> = [
87 ].iter().cloned().collect();
88
89 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
90
91 let processedResponse:models::HealthStatus = match response {
92 Ok(r) => {
93 match r.json() {
94 Ok(json) => json,
95 Err(e) => {
96 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
97 }
98 }
99 }
100 Err(e) => {
101 return Err(e);
102 }
103 };
104
105 Ok(processedResponse)
106 }
107
108 pub fn get_db(&self) -> Result<models::HealthStatus, AppwriteException> {
110 let path = "/health/db";
111 let headers: HashMap<String, String> = [
112 ("content-type".to_string(), "application/json".to_string()),
113 ].iter().cloned().collect();
114
115 let params: HashMap<String, ParamType> = [
116 ].iter().cloned().collect();
117
118 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
119
120 let processedResponse:models::HealthStatus = match response {
121 Ok(r) => {
122 match r.json() {
123 Ok(json) => json,
124 Err(e) => {
125 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
126 }
127 }
128 }
129 Err(e) => {
130 return Err(e);
131 }
132 };
133
134 Ok(processedResponse)
135 }
136
137 pub fn get_queue_certificates(&self) -> Result<models::HealthQueue, AppwriteException> {
141 let path = "/health/queue/certificates";
142 let headers: HashMap<String, String> = [
143 ("content-type".to_string(), "application/json".to_string()),
144 ].iter().cloned().collect();
145
146 let params: HashMap<String, ParamType> = [
147 ].iter().cloned().collect();
148
149 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
150
151 let processedResponse:models::HealthQueue = match response {
152 Ok(r) => {
153 match r.json() {
154 Ok(json) => json,
155 Err(e) => {
156 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
157 }
158 }
159 }
160 Err(e) => {
161 return Err(e);
162 }
163 };
164
165 Ok(processedResponse)
166 }
167
168 pub fn get_queue_functions(&self) -> Result<models::HealthQueue, AppwriteException> {
169 let path = "/health/queue/functions";
170 let headers: HashMap<String, String> = [
171 ("content-type".to_string(), "application/json".to_string()),
172 ].iter().cloned().collect();
173
174 let params: HashMap<String, ParamType> = [
175 ].iter().cloned().collect();
176
177 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
178
179 let processedResponse:models::HealthQueue = match response {
180 Ok(r) => {
181 match r.json() {
182 Ok(json) => json,
183 Err(e) => {
184 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
185 }
186 }
187 }
188 Err(e) => {
189 return Err(e);
190 }
191 };
192
193 Ok(processedResponse)
194 }
195
196 pub fn get_queue_logs(&self) -> Result<models::HealthQueue, AppwriteException> {
199 let path = "/health/queue/logs";
200 let headers: HashMap<String, String> = [
201 ("content-type".to_string(), "application/json".to_string()),
202 ].iter().cloned().collect();
203
204 let params: HashMap<String, ParamType> = [
205 ].iter().cloned().collect();
206
207 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
208
209 let processedResponse:models::HealthQueue = match response {
210 Ok(r) => {
211 match r.json() {
212 Ok(json) => json,
213 Err(e) => {
214 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
215 }
216 }
217 }
218 Err(e) => {
219 return Err(e);
220 }
221 };
222
223 Ok(processedResponse)
224 }
225
226 pub fn get_queue_usage(&self) -> Result<models::HealthQueue, AppwriteException> {
229 let path = "/health/queue/usage";
230 let headers: HashMap<String, String> = [
231 ("content-type".to_string(), "application/json".to_string()),
232 ].iter().cloned().collect();
233
234 let params: HashMap<String, ParamType> = [
235 ].iter().cloned().collect();
236
237 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
238
239 let processedResponse:models::HealthQueue = match response {
240 Ok(r) => {
241 match r.json() {
242 Ok(json) => json,
243 Err(e) => {
244 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
245 }
246 }
247 }
248 Err(e) => {
249 return Err(e);
250 }
251 };
252
253 Ok(processedResponse)
254 }
255
256 pub fn get_queue_webhooks(&self) -> Result<models::HealthQueue, AppwriteException> {
259 let path = "/health/queue/webhooks";
260 let headers: HashMap<String, String> = [
261 ("content-type".to_string(), "application/json".to_string()),
262 ].iter().cloned().collect();
263
264 let params: HashMap<String, ParamType> = [
265 ].iter().cloned().collect();
266
267 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
268
269 let processedResponse:models::HealthQueue = match response {
270 Ok(r) => {
271 match r.json() {
272 Ok(json) => json,
273 Err(e) => {
274 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
275 }
276 }
277 }
278 Err(e) => {
279 return Err(e);
280 }
281 };
282
283 Ok(processedResponse)
284 }
285
286 pub fn get_storage_local(&self) -> Result<models::HealthStatus, AppwriteException> {
288 let path = "/health/storage/local";
289 let headers: HashMap<String, String> = [
290 ("content-type".to_string(), "application/json".to_string()),
291 ].iter().cloned().collect();
292
293 let params: HashMap<String, ParamType> = [
294 ].iter().cloned().collect();
295
296 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
297
298 let processedResponse:models::HealthStatus = match response {
299 Ok(r) => {
300 match r.json() {
301 Ok(json) => json,
302 Err(e) => {
303 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
304 }
305 }
306 }
307 Err(e) => {
308 return Err(e);
309 }
310 };
311
312 Ok(processedResponse)
313 }
314
315 pub fn get_time(&self) -> Result<models::HealthTime, AppwriteException> {
323 let path = "/health/time";
324 let headers: HashMap<String, String> = [
325 ("content-type".to_string(), "application/json".to_string()),
326 ].iter().cloned().collect();
327
328 let params: HashMap<String, ParamType> = [
329 ].iter().cloned().collect();
330
331 let response = self.client.clone().call("GET", &path, Some(headers), Some(params) );
332
333 let processedResponse:models::HealthTime = match response {
334 Ok(r) => {
335 match r.json() {
336 Ok(json) => json,
337 Err(e) => {
338 return Err(AppwriteException::new(format!("Error parsing response json: {}", e), 0, "".to_string()));
339 }
340 }
341 }
342 Err(e) => {
343 return Err(e);
344 }
345 };
346
347 Ok(processedResponse)
348 }
349}