1use crate::statement::RequestResource;
2use ic_cdk::export::Principal;
3use std::collections::LinkedList;
4
5pub struct RequestResourceBuilder {
6 data: LinkedList<String>,
7}
8
9impl RequestResourceBuilder {
10 pub fn new(node: &str) -> RequestResourceBuilder {
11 let mut data = LinkedList::new();
12 data.push_front(node.to_string());
13 RequestResourceBuilder { data }
14 }
15
16 pub fn add(mut self, node: &str) -> RequestResourceBuilder {
17 self.data.push_front(node.to_string());
18 return RequestResourceBuilder { data: self.data };
19 }
20
21 pub fn build(mut self) -> RequestResource {
22 let mut output = RequestResource::Resource(self.data.pop_front().unwrap());
23
24 while let Some(data) = self.data.pop_front() {
25 let tmp = output;
26 output = RequestResource::Nested {
27 node: data,
28 next: Some(Box::new(tmp)),
29 }
30 }
31 return output;
32 }
33}
34
35pub struct Request {
36 action: String,
37 resource: RequestResource,
38 caller: Principal,
39}
40
41impl Request {
42 pub fn new(action: String, resource: RequestResource, caller: Principal) -> Self {
43 Request {
44 action,
45 resource,
46 caller,
47 }
48 }
49 pub fn action(&self) -> &String {
50 &self.action
51 }
52 pub fn resource(&self) -> &RequestResource {
53 &self.resource
54 }
55 pub fn caller(&self) -> Principal {
56 self.caller
57 }
58}