espocrm_rs/
espocrm_types.rs

1use std::fmt;
2
3#[derive(Clone, Debug, Eq, PartialEq)]
4#[allow(unused)]
5pub enum Value {
6    String(Option<String>),
7    Array(Option<Vec<Value>>),
8    Integer(Option<i64>),
9    Boolean(Option<bool>),
10}
11
12#[allow(unused)]
13impl Value {
14    pub fn eq(&self, b: &Value) -> bool {
15        std::mem::discriminant(self) == std::mem::discriminant(b)
16    }
17
18    pub fn string(v: String) -> Self {
19        Value::String(Some(v))
20    }
21
22    pub fn str(v: &str) -> Self {
23        Value::String(Some(v.to_string()))
24    }
25
26    pub fn array(v: Vec<Value>) -> Self {
27        Value::Array(Some(v))
28    }
29
30    pub fn int(v: i64) -> Self {
31        Value::Integer(Some(v))
32    }
33
34    pub fn bool(v: bool) -> Self {
35        Value::Boolean(Some(v))
36    }
37}
38
39#[derive(Clone, Debug, Eq, PartialEq)]
40#[allow(unused)]
41pub struct Params {
42    pub offset: Option<i64>,
43    pub max_size: Option<i64>,
44    pub select: Option<String>,
45    pub r#where: Option<Vec<Where>>,
46    pub primary_filter: Option<String>,
47    pub bool_filter_list: Option<Vec<String>>,
48    pub order: Option<Order>,
49    pub order_by: Option<String>,
50}
51
52impl Default for Params {
53    fn default() -> Self {
54        Self::new()
55    }
56}
57
58#[allow(unused)]
59impl Params {
60    pub fn new() -> Self {
61        Self {
62            offset: None,
63            max_size: None,
64            select: None,
65            r#where: None,
66            primary_filter: None,
67            bool_filter_list: None,
68            order_by: None,
69            order: None,
70        }
71    }
72
73    pub fn set_offset(&mut self, offset: i64) -> &mut Self {
74        self.offset = Some(offset);
75        self
76    }
77
78    pub fn set_max_size(&mut self, max_size: i64) -> &mut Self {
79        self.max_size = Some(max_size);
80        self
81    }
82
83    pub fn set_select(&mut self, select: &str) -> &mut Self {
84        self.select = Some(select.to_string());
85        self
86    }
87
88    pub fn set_where(&mut self, r#where: Vec<Where>) -> &mut Self {
89        self.r#where = Some(r#where);
90        self
91    }
92
93    pub fn set_primary_filter(&mut self, primary_filter: &str) -> &mut Self {
94        self.primary_filter = Some(primary_filter.to_string());
95        self
96    }
97
98    pub fn set_bool_filter_list(&mut self, bool_filter_list: Vec<String>) -> &mut Self {
99        self.bool_filter_list = Some(bool_filter_list);
100        self
101    }
102
103    pub fn set_order(&mut self, order: Order) -> &mut Self {
104        self.order = Some(order);
105        self
106    }
107
108    pub fn set_order_by(&mut self, order_by: &str) -> &mut Self {
109        self.order_by = Some(order_by.to_string());
110        self
111    }
112
113    pub fn build(&self) -> Self {
114        self.clone()
115    }
116}
117
118#[derive(Clone, Debug, Eq, PartialEq)]
119#[allow(unused)]
120pub enum Order {
121    Asc,
122    Desc,
123}
124
125impl fmt::Display for Order {
126    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
127        write!(f, "{:?}", self)
128    }
129}
130
131#[derive(Clone, Debug, Eq, PartialEq)]
132#[allow(unused)]
133pub struct Where {
134    pub r#type: FilterType,
135    pub attribute: String,
136    pub value: Option<Value>,
137}
138
139#[allow(unused)]
140impl Where {
141    pub fn new(filter_type: FilterType, attribute: &str, value: Option<Value>) -> Self {
142        Where {
143            r#type: filter_type,
144            attribute: attribute.to_string(),
145            value,
146        }
147    }
148}
149
150#[derive(Clone, Debug, Eq, PartialEq)]
151#[allow(unused)]
152pub enum FilterType {
153    Equals,
154    NotEquals,
155    GreaterThan,
156    LessThan,
157    GreaterThanOrEquals,
158    LessThanOrEquals,
159    IsNull,
160    IsNotNull,
161    IsTrue,
162    IsFalse,
163    LinkedWith,
164    NotLinkedWith,
165    IsLinked,
166    IsNotLinked,
167    In,
168    NotIn,
169    Contains,
170    NotContains,
171    StartsWith,
172    EndsWith,
173    Like,
174    NotLike,
175    Or,
176    AndToday,
177    Past,
178    Future,
179    LastSevenDays,
180    CurrentMonth,
181    LastMonth,
182    NextMonth,
183    CurrentQuarter,
184    LastQuarter,
185    CurrentYear,
186    LastYear,
187    CurrentFiscalYear,
188    LastFiscalYear,
189    CurrentFiscalQuarter,
190    LastFiscalQuarter,
191    LastXDays,
192    NextXDays,
193    OlderThanXDays,
194    AfterXDays,
195    Between,
196    ArrayAnyOf,
197    ArrayNoneOf,
198    ArrayAllOf,
199    ArrayIsEmpty,
200    ArrayIsNotEmpty,
201}
202
203impl fmt::Display for FilterType {
204    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
205        write!(f, "{:?}", self)
206    }
207}