1#![warn(missing_docs)]
2
3use super::openiap::{
4    Envelope, GetDocumentVersionRequest, CustomCommandRequest, ListCollectionsRequest, DropCollectionRequest, CreateCollectionRequest,
5    GetIndexesRequest, CreateIndexRequest, DropIndexRequest, EnsureCustomerRequest, InvokeOpenRpaRequest, CreateWorkflowInstanceRequest,
6    Customer, StripeCustomer
7};
8
9impl GetDocumentVersionRequest {
10    pub fn byid(collectionname: &str, documentid: &str) -> Self {
12        Self {
13            collectionname: collectionname.to_string(),
14            id: documentid.to_string(),
15            decrypt: true,
16            version: 0,
17        }
18    }
19    pub fn byversion(collectionname: &str, documentid: &str, version : i32) -> Self {
21        Self {
22            collectionname: collectionname.to_string(),
23            id: documentid.to_string(),
24            decrypt: true,
25            version,
26        }
27    }
28    pub fn to_envelope(&self) -> Envelope {
30        let any_message = prost_types::Any {
31            type_url: "type.googleapis.com/openiap.GetDocumentVersionRequest".to_string(),
32            value: {
33                let mut buf = Vec::new();
34                prost::Message::encode(self, &mut buf).unwrap_or(());
35                buf
36            },
37        };
38        Envelope {
39            command: "getdocumentversion".into(),
40            data: Some(any_message.clone()),
41            ..Default::default() 
42        }
43    }
44}
45
46impl CustomCommandRequest {
47    pub fn bycommand(command: &str) -> Self {
49        Self {
50            command: command.to_string(),
51            data: "".to_string(),
52            id: "".to_string(),
53            name: "".to_string(), 
54        }
55    }
56    pub fn bydata(command: &str, data: &str) -> Self {
58        Self {
59            command: command.to_string(),
60            data: data.to_string(),
61            id: "".to_string(),
62            name: "".to_string(), 
63        }
64    }
65    pub fn to_envelope(&self) -> Envelope {
67        let any_message = prost_types::Any {
68            type_url: "type.googleapis.com/openiap.CustomCommandRequest".to_string(),
69            value: {
70                let mut buf = Vec::new();
71                prost::Message::encode(self, &mut buf).unwrap_or(());
72                buf
73            },
74        };
75        Envelope {
76            command: "customcommand".into(),
77            data: Some(any_message.clone()),
78            ..Default::default() 
79        }
80    }
81}
82impl ListCollectionsRequest {
83    pub fn new(includehist: bool) -> Self {
85        Self {
86            includehist,
87        }
88    }
89    pub fn to_envelope(&self) -> Envelope {
91        let any_message = prost_types::Any {
92            type_url: "type.googleapis.com/openiap.ListCollectionsRequest".to_string(),
93            value: {
94                let mut buf = Vec::new();
95                prost::Message::encode(self, &mut buf).unwrap_or(());
96                buf
97            },
98        };
99        Envelope {
100            command: "listcollections".into(),
101            data: Some(any_message.clone()),
102            ..Default::default() 
103        }
104    }
105}
106impl DropCollectionRequest {
107    pub fn byname(collectionname: &str) -> Self {
109        Self {
110            collectionname: collectionname.to_string(),
111        }
112    }
113    pub fn to_envelope(&self) -> Envelope {
115        let any_message = prost_types::Any {
116            type_url: "type.googleapis.com/openiap.DropCollectionRequest".to_string(),
117            value: {
118                let mut buf = Vec::new();
119                prost::Message::encode(self, &mut buf).unwrap_or(());
120                buf
121            },
122        };
123        Envelope {
124            command: "dropcollection".into(),
125            data: Some(any_message.clone()),
126            ..Default::default() 
127        }
128    }
129}
130impl CreateCollectionRequest {
131    pub fn byname(collectionname: &str) -> Self {
133        Self {
134            collectionname: collectionname.to_string(),
135            ..Default::default()
136        }
137    }
138    pub fn with_ttl(collectionname: &str, ttl: i32) -> Self {
140        Self {
141            collectionname: collectionname.to_string(),
142            expire_after_seconds: ttl,
143            ..Default::default()
144        }
145    }
146    pub fn timeseries(collectionname: &str, timefield: &str, granularity: &str) -> Self {
148        Self {
149            collectionname: collectionname.to_string(),
150            timeseries: Some(
151                crate::openiap::ColTimeseries {
152                    time_field: timefield.to_string(),
153                    granularity: granularity.to_string(),
154                    meta_field: "".to_string(),
155                },                                
156            ),            
157            ..Default::default()
158        }
159    }
160    pub fn timeseries_with_meta(collectionname: &str, timefield: &str, meta_field: &str, granularity: &str) -> Self {
162        Self {
163            collectionname: collectionname.to_string(),
164            timeseries: Some(
165                crate::openiap::ColTimeseries {
166                    time_field: timefield.to_string(),
167                    granularity: granularity.to_string(),
168                    meta_field: meta_field.to_string(),
169                },                                
170            ),            
171            ..Default::default()
172        }
173    }
174    pub fn to_envelope(&self) -> Envelope {
176        let any_message = prost_types::Any {
177            type_url: "type.googleapis.com/openiap.CreateCollectionRequest".to_string(),
178            value: {
179                let mut buf = Vec::new();
180                prost::Message::encode(self, &mut buf).unwrap_or(());
181                buf
182            },
183        };
184        Envelope {
185            command: "createcollection".into(),
186            data: Some(any_message.clone()),
187            ..Default::default() 
188        }
189    }
190}
191impl GetIndexesRequest {
192    pub fn bycollectionname(collectionname: &str) -> Self {
194        Self {
195            collectionname: collectionname.to_string(),
196        }
197    }
198    pub fn to_envelope(&self) -> Envelope {
200        let any_message = prost_types::Any {
201            type_url: "type.googleapis.com/openiap.GetIndexesRequest".to_string(),
202            value: {
203                let mut buf = Vec::new();
204                prost::Message::encode(self, &mut buf).unwrap_or(());
205                buf
206            },
207        };
208        Envelope {
209            command: "getindexes".into(),
210            data: Some(any_message.clone()),
211            ..Default::default() 
212        }
213    }
214}
215impl CreateIndexRequest {
216    pub fn bycollectionname(collectionname: &str, index_def: &str) -> Self {
218        Self {
219            collectionname: collectionname.to_string(),
220            index: index_def.to_string(),
221            options: "".to_string(),
222            name: "".to_string(),
223        }
224    }
225    pub fn to_envelope(&self) -> Envelope {
227        let any_message = prost_types::Any {
228            type_url: "type.googleapis.com/openiap.CreateIndexRequest".to_string(),
229            value: {
230                let mut buf = Vec::new();
231                prost::Message::encode(self, &mut buf).unwrap_or(());
232                buf
233            },
234        };
235        Envelope {
236            command: "createindex".into(),
237            data: Some(any_message.clone()),
238            ..Default::default() 
239        }
240    }
241}
242impl DropIndexRequest {
243    pub fn bycollectionname(collectionname: &str, indexname: &str) -> Self {
245        Self {
246            collectionname: collectionname.to_string(),
247            name: indexname.to_string(),
248        }
249    }
250    pub fn to_envelope(&self) -> Envelope {
252        let any_message = prost_types::Any {
253            type_url: "type.googleapis.com/openiap.DropIndexRequest".to_string(),
254            value: {
255                let mut buf = Vec::new();
256                prost::Message::encode(self, &mut buf).unwrap_or(());
257                buf
258            },
259        };
260        Envelope {
261            command: "dropindex".into(),
262            data: Some(any_message.clone()),
263            ..Default::default() 
264        }
265    }
266}
267impl Customer {
268    pub fn byname(name: &str) -> Self {
270        Self {
271            name: name.to_string(),
272            ..Default::default()
273        }
274    }
275    pub fn byuserid(name: &str, userid: &str) -> Self {
277        Self {
278            name: name.to_string(),
279            userid: userid.to_string(),
280            ..Default::default()
281        }
282    }
283    pub fn to_envelope(&self) -> Envelope {
285        let any_message = prost_types::Any {
286            type_url: "type.googleapis.com/openiap.Customer".to_string(),
287            value: {
288                let mut buf = Vec::new();
289                prost::Message::encode(self, &mut buf).unwrap_or(());
290                buf
291            },
292        };
293        Envelope {
294            command: "customer".into(),
295            data: Some(any_message.clone()),
296            ..Default::default() 
297        }
298    }
299    
300}
301impl StripeCustomer {
302    pub fn byname(name: &str, email: &str) -> Self {
304        Self {
305            name: name.to_string(),
306            email: email.to_string(),
307            ..Default::default()
308        }
309    }
310    pub fn to_envelope(&self) -> Envelope {
312        let any_message = prost_types::Any {
313            type_url: "type.googleapis.com/openiap.StripeCustomer".to_string(),
314            value: {
315                let mut buf = Vec::new();
316                prost::Message::encode(self, &mut buf).unwrap_or(());
317                buf
318            },
319        };
320        Envelope {
321            command: "stripecustomer".into(),
322            data: Some(any_message.clone()),
323            ..Default::default() 
324        }
325    }
326    
327}
328impl EnsureCustomerRequest {
329    pub fn new(customer: Option<Customer>, ensureas: &str, stripe: Option<StripeCustomer>) -> Self {
331        Self {
332            customer,
333            ensureas: ensureas.to_string(),
334            stripe
335        }
336    }
337    pub fn to_envelope(&self) -> Envelope {
339        let any_message = prost_types::Any {
340            type_url: "type.googleapis.com/openiap.EnsureCustomerRequest".to_string(),
341            value: {
342                let mut buf = Vec::new();
343                prost::Message::encode(self, &mut buf).unwrap_or(());
344                buf
345            },
346        };
347        Envelope {
348            command: "ensurecustomer".into(),
349            data: Some(any_message.clone()),
350            ..Default::default() 
351        }
352    }
353    
354}
355
356impl InvokeOpenRpaRequest {
357    pub fn new(robotid: &str, workflowid: &str, payload: &str, rpc: bool) -> Self {
360        Self {
361            robotid: robotid.to_string(),
362            workflowid: workflowid.to_string(),
363            payload: payload.to_string(),
364            rpc
365        }
366    }
367    pub fn to_envelope(&self) -> Envelope {
369        let any_message = prost_types::Any {
370            type_url: "type.googleapis.com/openiap.InvokeOpenRpaRequest".to_string(),
371            value: {
372                let mut buf = Vec::new();
373                prost::Message::encode(self, &mut buf).unwrap_or(());
374                buf
375            },
376        };
377        Envelope {
378            command: "invokeopenrpa".into(),
379            data: Some(any_message.clone()),
380            ..Default::default() 
381        }
382    }
383    
384}
385impl  CreateWorkflowInstanceRequest {
386    pub fn to_envelope(&self) -> Envelope {
388        let any_message = prost_types::Any {
389            type_url: "type.googleapis.com/openiap.CreateWorkflowInstanceRequest".to_string(),
390            value: {
391                let mut buf = Vec::new();
392                prost::Message::encode(self, &mut buf).unwrap_or(());
393                buf
394            },
395        };
396        Envelope {
397            command: "createworkflowinstance".into(),
398            data: Some(any_message.clone()),
399            ..Default::default() 
400        }
401    }
402    
403}