1use std::str::FromStr;
2
3use serde::{Deserialize, Serialize};
4use strum::Display;
5use tardis::basic::error::TardisError;
6use tardis::basic::result::TardisResult;
7
8use tardis::db::sea_orm;
9
10use tardis::db::sea_orm::{DbErr, QueryResult, TryGetError, TryGetable};
11
12use tardis::web::poem_openapi;
13
14#[derive(Display, Clone, Debug, PartialEq, Eq, Serialize, poem_openapi::Enum)]
18pub enum RbumScopeLevelKind {
19 Private,
27 Root,
31 L1,
39 L2,
45 L3,
51}
52
53impl<'de> Deserialize<'de> for RbumScopeLevelKind {
54 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55 where
56 D: serde::Deserializer<'de>,
57 {
58 String::deserialize(deserializer).and_then(|s| match s.to_lowercase().as_str() {
59 "private" => Ok(RbumScopeLevelKind::Private),
60 "root" => Ok(RbumScopeLevelKind::Root),
61 "l1" => Ok(RbumScopeLevelKind::L1),
62 "l2" => Ok(RbumScopeLevelKind::L2),
63 "l3" => Ok(RbumScopeLevelKind::L3),
64 _ => Err(serde::de::Error::custom(format!("invalid RbumScopeLevelKind: {s}"))),
65 })
66 }
67}
68
69impl RbumScopeLevelKind {
70 pub fn from_int(s: i16) -> TardisResult<RbumScopeLevelKind> {
71 match s {
72 -1 => Ok(RbumScopeLevelKind::Private),
73 0 => Ok(RbumScopeLevelKind::Root),
74 1 => Ok(RbumScopeLevelKind::L1),
75 2 => Ok(RbumScopeLevelKind::L2),
76 3 => Ok(RbumScopeLevelKind::L3),
77 _ => Err(TardisError::format_error(&format!("invalid RbumScopeLevelKind: {s}"), "406-rbum-*-enum-init-error")),
78 }
79 }
80
81 pub fn to_int(&self) -> i16 {
82 match self {
83 RbumScopeLevelKind::Private => -1,
84 RbumScopeLevelKind::Root => 0,
85 RbumScopeLevelKind::L1 => 1,
86 RbumScopeLevelKind::L2 => 2,
87 RbumScopeLevelKind::L3 => 3,
88 }
89 }
90}
91
92impl TryGetable for RbumScopeLevelKind {
93 fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
94 let s = i16::try_get(res, pre, col)?;
95 RbumScopeLevelKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
96 }
97
98 fn try_get_by<I: sea_orm::ColIdx>(res: &QueryResult, index: I) -> Result<Self, TryGetError> {
99 i16::try_get_by(res, index).map(RbumScopeLevelKind::from_int)?.map_err(|e| TryGetError::DbErr(DbErr::Custom(format!("invalid scope level: {e}"))))
100 }
101}
102
103#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
108pub enum RbumCertRelKind {
109 Item,
113 Set,
117 Rel,
121}
122
123impl RbumCertRelKind {
124 pub fn from_int(s: i16) -> TardisResult<RbumCertRelKind> {
125 match s {
126 0 => Ok(RbumCertRelKind::Item),
127 1 => Ok(RbumCertRelKind::Set),
128 2 => Ok(RbumCertRelKind::Rel),
129 _ => Err(TardisError::format_error(&format!("invalid RbumCertRelKind: {s}"), "406-rbum-*-enum-init-error")),
130 }
131 }
132
133 pub fn to_int(&self) -> i16 {
134 match self {
135 RbumCertRelKind::Item => 0,
136 RbumCertRelKind::Set => 1,
137 RbumCertRelKind::Rel => 2,
138 }
139 }
140}
141
142impl TryGetable for RbumCertRelKind {
143 fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
144 let s = i16::try_get(res, pre, col)?;
145 RbumCertRelKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
146 }
147
148 fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
149 panic!("not implemented")
150 }
151}
152
153#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
157pub enum RbumCertConfStatusKind {
158 Disabled,
162 Enabled,
166}
167
168impl RbumCertConfStatusKind {
169 pub fn from_int(s: i16) -> TardisResult<RbumCertConfStatusKind> {
170 match s {
171 0 => Ok(RbumCertConfStatusKind::Disabled),
172 1 => Ok(RbumCertConfStatusKind::Enabled),
173 _ => Err(TardisError::format_error(&format!("invalid RbumCertConfStatusKind: {s}"), "406-rbum-*-enum-init-error")),
174 }
175 }
176
177 pub fn to_int(&self) -> i16 {
178 match self {
179 RbumCertConfStatusKind::Disabled => 0,
180 RbumCertConfStatusKind::Enabled => 1,
181 }
182 }
183}
184
185#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
189pub enum RbumCertStatusKind {
190 Disabled,
194 Enabled,
198 Pending,
202}
203
204impl RbumCertStatusKind {
205 pub fn from_int(s: i16) -> TardisResult<RbumCertStatusKind> {
206 match s {
207 0 => Ok(RbumCertStatusKind::Disabled),
208 1 => Ok(RbumCertStatusKind::Enabled),
209 2 => Ok(RbumCertStatusKind::Pending),
210 _ => Err(TardisError::format_error(&format!("invalid RbumCertStatusKind: {s}"), "406-rbum-*-enum-init-error")),
211 }
212 }
213
214 pub fn to_int(&self) -> i16 {
215 match self {
216 RbumCertStatusKind::Disabled => 0,
217 RbumCertStatusKind::Enabled => 1,
218 RbumCertStatusKind::Pending => 2,
219 }
220 }
221}
222
223impl TryGetable for RbumCertStatusKind {
224 fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
225 let s = i16::try_get(res, pre, col)?;
226 RbumCertStatusKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
227 }
228
229 fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
230 panic!("not implemented")
231 }
232}
233
234#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
238pub enum RbumRelFromKind {
239 Item,
243 Set,
247 SetCate,
251 Cert,
255}
256
257impl RbumRelFromKind {
258 pub fn from_int(s: i16) -> TardisResult<RbumRelFromKind> {
259 match s {
260 0 => Ok(RbumRelFromKind::Item),
261 1 => Ok(RbumRelFromKind::Set),
262 2 => Ok(RbumRelFromKind::SetCate),
263 3 => Ok(RbumRelFromKind::Cert),
264 _ => Err(TardisError::format_error(&format!("invalid RbumRelFromKind: {s}"), "406-rbum-*-enum-init-error")),
265 }
266 }
267
268 pub fn to_int(&self) -> i16 {
269 match self {
270 RbumRelFromKind::Item => 0,
271 RbumRelFromKind::Set => 1,
272 RbumRelFromKind::SetCate => 2,
273 RbumRelFromKind::Cert => 3,
274 }
275 }
276}
277
278impl TryGetable for RbumRelFromKind {
279 fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
280 let s = i16::try_get(res, pre, col)?;
281 RbumRelFromKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
282 }
283
284 fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
285 panic!("not implemented")
286 }
287}
288
289#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
297pub enum RbumRelEnvKind {
298 DatetimeRange,
304 TimeRange,
314 Ips,
320 CallFrequency,
328 CallCount,
336}
337
338impl RbumRelEnvKind {
339 pub fn from_int(s: i16) -> TardisResult<RbumRelEnvKind> {
340 match s {
341 0 => Ok(RbumRelEnvKind::DatetimeRange),
342 1 => Ok(RbumRelEnvKind::TimeRange),
343 2 => Ok(RbumRelEnvKind::Ips),
344 3 => Ok(RbumRelEnvKind::CallFrequency),
345 4 => Ok(RbumRelEnvKind::CallCount),
346 _ => Err(TardisError::format_error(&format!("invalid RbumRelEnvKind: {s}"), "406-rbum-*-enum-init-error")),
347 }
348 }
349
350 pub fn to_int(&self) -> i16 {
351 match self {
352 RbumRelEnvKind::DatetimeRange => 0,
353 RbumRelEnvKind::TimeRange => 1,
354 RbumRelEnvKind::Ips => 2,
355 RbumRelEnvKind::CallFrequency => 3,
356 RbumRelEnvKind::CallCount => 4,
357 }
358 }
359}
360
361impl TryGetable for RbumRelEnvKind {
362 fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
363 let s = i16::try_get(res, pre, col)?;
364 RbumRelEnvKind::from_int(s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
365 }
366
367 fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
368 panic!("not implemented")
369 }
370}
371
372#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum)]
376pub enum RbumSetCateLevelQueryKind {
377 CurrentAndSub,
381 CurrentAndParent,
385 Sub,
389 Parent,
393 Current,
397}
398
399#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, strum::EnumString)]
403pub enum RbumDataTypeKind {
404 String,
405 Number,
406 Boolean,
407 Date,
408 DateTime,
409 Json,
410 Strings,
411 Numbers,
412 Booleans,
413 Dates,
414 DateTimes,
415 Array,
416 Label,
417}
418
419impl TryGetable for RbumDataTypeKind {
420 fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
421 let s = String::try_get(res, pre, col)?;
422 RbumDataTypeKind::from_str(&s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
423 }
424
425 fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
426 panic!("not implemented")
427 }
428}
429
430#[derive(Display, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, poem_openapi::Enum, strum::EnumString)]
434pub enum RbumWidgetTypeKind {
435 Input,
436 InputTxt,
437 InputNum,
438 Textarea,
439 Number,
440 Date,
441 DateTime,
442 Upload,
443 Radio,
444 Button,
445 Checkbox,
446 Switch,
447 Select,
448 MultiSelect,
449 Link,
450 CodeEditor,
451 Container,
455 Control,
459 Group,
463}
464
465impl TryGetable for RbumWidgetTypeKind {
466 fn try_get(res: &QueryResult, pre: &str, col: &str) -> Result<Self, TryGetError> {
467 let s = String::try_get(res, pre, col)?;
468 RbumWidgetTypeKind::from_str(&s).map_err(|_| TryGetError::DbErr(DbErr::RecordNotFound(format!("{pre}:{col}"))))
469 }
470
471 fn try_get_by<I: sea_orm::ColIdx>(_res: &QueryResult, _index: I) -> Result<Self, TryGetError> {
472 panic!("not implemented")
473 }
474}