1use crate::CCDBResult;
2use chrono::{DateTime, Utc};
3use gluex_core::{parsers::parse_timestamp, Id, RunNumber};
4use std::fmt::Display;
5
6#[derive(Debug, Copy, Clone, Default)]
8pub enum ColumnType {
9 Int,
11 UInt,
13 Long,
15 ULong,
17 #[default]
19 Double,
20 String,
22 Bool,
24}
25impl ColumnType {
26 #[must_use]
28 pub fn type_from_str(s: &str) -> Option<Self> {
29 match s {
30 "int" => Some(Self::Int),
31 "uint" => Some(Self::UInt),
32 "long" => Some(Self::Long),
33 "ulong" => Some(Self::ULong),
34 "double" => Some(Self::Double),
35 "bool" => Some(Self::Bool),
36 "string" => Some(Self::String),
37 _ => None,
38 }
39 }
40
41 #[must_use]
43 pub fn as_str(&self) -> &'static str {
44 match self {
45 Self::Int => "int",
46 Self::UInt => "uint",
47 Self::Long => "long",
48 Self::ULong => "ulong",
49 Self::Double => "double",
50 Self::Bool => "bool",
51 Self::String => "string",
52 }
53 }
54}
55impl Display for ColumnType {
56 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
57 write!(f, "{}", self.as_str())
58 }
59}
60
61#[derive(Debug, Clone, Default)]
63pub struct ColumnMeta {
64 pub(crate) id: Id,
65 pub(crate) created: String,
66 pub(crate) modified: String,
67 pub(crate) name: String,
68 pub(crate) type_id: Id,
69 pub(crate) column_type: ColumnType,
70 pub(crate) order: i64,
71 pub(crate) comment: String,
72}
73impl ColumnMeta {
74 #[must_use]
76 pub fn id(&self) -> Id {
77 self.id
78 }
79 #[must_use]
81 pub fn name(&self) -> &str {
82 &self.name
83 }
84 #[must_use]
86 pub fn type_id(&self) -> Id {
87 self.type_id
88 }
89 #[must_use]
91 pub fn column_type(&self) -> ColumnType {
92 self.column_type
93 }
94 #[must_use]
96 pub fn order(&self) -> i64 {
97 self.order
98 }
99 #[must_use]
101 pub fn comment(&self) -> &str {
102 &self.comment
103 }
104 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
110 Ok(parse_timestamp(&self.created)?)
111 }
112 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
118 Ok(parse_timestamp(&self.modified)?)
119 }
120}
121
122#[derive(Debug, Clone, Default)]
124pub struct DirectoryMeta {
125 pub(crate) id: Id,
126 pub(crate) created: String,
127 pub(crate) modified: String,
128 pub(crate) name: String,
129 pub(crate) parent_id: Id,
130 pub(crate) author_id: Id,
131 pub(crate) comment: String,
132 pub(crate) is_deprecated: bool,
133 pub(crate) deprecated_by_user_id: Id,
134 pub(crate) is_locked: bool,
135 pub(crate) locked_by_user_id: Id,
136}
137impl DirectoryMeta {
138 #[must_use]
140 pub fn id(&self) -> Id {
141 self.id
142 }
143 #[must_use]
145 pub fn name(&self) -> &str {
146 &self.name
147 }
148 #[must_use]
150 pub fn parent_id(&self) -> Id {
151 self.parent_id
152 }
153 #[must_use]
155 pub fn author_id(&self) -> Id {
156 self.author_id
157 }
158 #[must_use]
160 pub fn comment(&self) -> &str {
161 &self.comment
162 }
163 #[must_use]
165 pub fn is_deprecated(&self) -> bool {
166 self.is_deprecated
167 }
168 #[must_use]
170 pub fn deprecated_by_user_id(&self) -> Id {
171 self.deprecated_by_user_id
172 }
173 #[must_use]
175 pub fn is_locked(&self) -> bool {
176 self.is_locked
177 }
178 #[must_use]
180 pub fn locked_by_user_id(&self) -> Id {
181 self.locked_by_user_id
182 }
183 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
189 Ok(parse_timestamp(&self.created)?)
190 }
191 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
197 Ok(parse_timestamp(&self.modified)?)
198 }
199}
200
201#[derive(Debug, Clone, Default)]
203pub struct TypeTableMeta {
204 pub(crate) id: Id,
205 pub(crate) created: String,
206 pub(crate) modified: String,
207 pub(crate) directory_id: Id,
208 pub(crate) name: String,
209 pub(crate) n_rows: i64,
210 pub(crate) n_columns: i64,
211 pub(crate) n_assignments: i64,
212 pub(crate) author_id: Id,
213 pub(crate) comment: String,
214 pub(crate) is_deprecated: bool,
215 pub(crate) deprecated_by_user_id: Id,
216 pub(crate) is_locked: bool,
217 pub(crate) locked_by_user_id: Id,
218 pub(crate) lock_time: String,
219}
220
221impl TypeTableMeta {
222 #[must_use]
224 pub fn id(&self) -> Id {
225 self.id
226 }
227 #[must_use]
229 pub fn directory_id(&self) -> Id {
230 self.directory_id
231 }
232 #[must_use]
234 pub fn name(&self) -> &str {
235 &self.name
236 }
237 #[must_use]
239 pub fn n_rows(&self) -> i64 {
240 self.n_rows
241 }
242 #[must_use]
244 pub fn n_columns(&self) -> i64 {
245 self.n_columns
246 }
247 #[must_use]
249 pub fn n_assignments(&self) -> i64 {
250 self.n_assignments
251 }
252 #[must_use]
254 pub fn author_id(&self) -> Id {
255 self.author_id
256 }
257 #[must_use]
259 pub fn comment(&self) -> &str {
260 &self.comment
261 }
262 #[must_use]
264 pub fn is_deprecated(&self) -> bool {
265 self.is_deprecated
266 }
267 #[must_use]
269 pub fn deprecated_by_user_id(&self) -> Id {
270 self.deprecated_by_user_id
271 }
272 #[must_use]
274 pub fn is_locked(&self) -> bool {
275 self.is_locked
276 }
277 #[must_use]
279 pub fn locked_by_user_id(&self) -> Id {
280 self.locked_by_user_id
281 }
282 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
288 Ok(parse_timestamp(&self.created)?)
289 }
290 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
296 Ok(parse_timestamp(&self.modified)?)
297 }
298 pub fn lock_time(&self) -> CCDBResult<DateTime<Utc>> {
304 Ok(parse_timestamp(&self.lock_time)?)
305 }
306}
307
308#[derive(Debug, Clone, Default)]
310pub struct ConstantSetMeta {
311 pub(crate) id: Id,
312 pub(crate) created: String,
313 pub(crate) modified: String,
314 pub(crate) vault: String,
315 pub(crate) constant_type_id: Id,
316}
317
318impl ConstantSetMeta {
319 #[must_use]
321 pub fn id(&self) -> Id {
322 self.id
323 }
324 #[must_use]
326 pub fn vault(&self) -> &str {
327 &self.vault
328 }
329 #[must_use]
331 pub fn constant_type_id(&self) -> Id {
332 self.constant_type_id
333 }
334 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
340 Ok(parse_timestamp(&self.created)?)
341 }
342 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
348 Ok(parse_timestamp(&self.modified)?)
349 }
350}
351
352#[derive(Debug, Clone, Default)]
354pub struct AssignmentMeta {
355 pub(crate) id: Id,
356 pub(crate) created: String,
357 pub(crate) modified: String,
358 pub(crate) variation_id: Id,
359 pub(crate) run_range_id: Id,
360 pub(crate) event_range_id: Id,
361 pub(crate) author_id: Id,
362 pub(crate) comment: String,
363 pub(crate) constant_set_id: Id,
364}
365impl AssignmentMeta {
366 #[must_use]
368 pub fn id(&self) -> Id {
369 self.id
370 }
371 #[must_use]
373 pub fn variation_id(&self) -> Id {
374 self.variation_id
375 }
376 #[must_use]
378 pub fn run_range_id(&self) -> Id {
379 self.run_range_id
380 }
381 #[must_use]
383 pub fn event_range_id(&self) -> Id {
384 self.event_range_id
385 }
386 #[must_use]
388 pub fn author_id(&self) -> Id {
389 self.author_id
390 }
391 #[must_use]
393 pub fn comment(&self) -> &str {
394 &self.comment
395 }
396 #[must_use]
398 pub fn constant_set_id(&self) -> Id {
399 self.constant_set_id
400 }
401 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
407 Ok(parse_timestamp(&self.created)?)
408 }
409 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
415 Ok(parse_timestamp(&self.modified)?)
416 }
417}
418
419#[derive(Debug, Clone, Default)]
421pub struct AssignmentMetaLite {
422 pub(crate) id: Id,
423 pub(crate) created: String,
424 pub(crate) constant_set_id: Id,
425}
426impl AssignmentMetaLite {
427 #[must_use]
429 pub fn id(&self) -> Id {
430 self.id
431 }
432 #[must_use]
434 pub fn constant_set_id(&self) -> Id {
435 self.constant_set_id
436 }
437 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
443 Ok(parse_timestamp(&self.created)?)
444 }
445}
446
447#[derive(Debug, Clone, Default)]
449pub struct VariationMeta {
450 pub(crate) id: Id,
451 pub(crate) created: String,
452 pub(crate) modified: String,
453 pub(crate) name: String,
454 pub(crate) description: String,
455 pub(crate) author_id: Id,
456 pub(crate) comment: String,
457 pub(crate) parent_id: Id,
458 pub(crate) is_locked: bool,
459 pub(crate) lock_time: String,
460 pub(crate) locked_by_user_id: Id,
461 pub(crate) go_back_behavior: i64,
462 pub(crate) go_back_time: String,
463 pub(crate) is_deprecated: bool,
464 pub(crate) deprecated_by_user_id: Id,
465}
466impl VariationMeta {
467 #[must_use]
469 pub fn id(&self) -> Id {
470 self.id
471 }
472 #[must_use]
474 pub fn name(&self) -> &str {
475 &self.name
476 }
477 #[must_use]
479 pub fn description(&self) -> &str {
480 &self.description
481 }
482 #[must_use]
484 pub fn author_id(&self) -> Id {
485 self.author_id
486 }
487 #[must_use]
489 pub fn comment(&self) -> &str {
490 &self.comment
491 }
492 #[must_use]
494 pub fn parent_id(&self) -> Id {
495 self.parent_id
496 }
497 #[must_use]
499 pub fn is_locked(&self) -> bool {
500 self.is_locked
501 }
502 #[must_use]
504 pub fn locked_by_user_id(&self) -> Id {
505 self.locked_by_user_id
506 }
507 #[must_use]
509 pub fn go_back_behavior(&self) -> i64 {
510 self.go_back_behavior
511 }
512 #[must_use]
514 pub fn is_deprecated(&self) -> bool {
515 self.is_deprecated
516 }
517 #[must_use]
519 pub fn deprecated_by_user_id(&self) -> Id {
520 self.deprecated_by_user_id
521 }
522 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
528 Ok(parse_timestamp(&self.created)?)
529 }
530 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
536 Ok(parse_timestamp(&self.modified)?)
537 }
538 pub fn lock_time(&self) -> CCDBResult<DateTime<Utc>> {
544 Ok(parse_timestamp(&self.lock_time)?)
545 }
546 pub fn go_back_time(&self) -> CCDBResult<DateTime<Utc>> {
552 Ok(parse_timestamp(&self.go_back_time)?)
553 }
554}
555
556#[derive(Debug, Clone, Default)]
558pub struct RunRangeMeta {
559 pub(crate) id: Id,
560 pub(crate) created: String,
561 pub(crate) modified: String,
562 pub(crate) name: String,
563 pub(crate) run_min: RunNumber,
564 pub(crate) run_max: RunNumber,
565 pub(crate) comment: String,
566}
567
568impl RunRangeMeta {
569 #[must_use]
571 pub fn id(&self) -> Id {
572 self.id
573 }
574 #[must_use]
576 pub fn name(&self) -> &str {
577 &self.name
578 }
579 #[must_use]
581 pub fn run_min(&self) -> RunNumber {
582 self.run_min
583 }
584 #[must_use]
586 pub fn run_max(&self) -> RunNumber {
587 self.run_max
588 }
589 #[must_use]
591 pub fn comment(&self) -> &str {
592 &self.comment
593 }
594 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
600 Ok(parse_timestamp(&self.created)?)
601 }
602 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
608 Ok(parse_timestamp(&self.modified)?)
609 }
610}
611
612#[derive(Debug, Clone, Default)]
614pub struct EventRangeMeta {
615 pub(crate) id: Id,
616 pub(crate) created: String,
617 pub(crate) modified: String,
618 pub(crate) run_number: RunNumber,
619 pub(crate) event_min: i64,
620 pub(crate) event_max: i64,
621 pub(crate) comment: String,
622}
623
624impl EventRangeMeta {
625 #[must_use]
627 pub fn id(&self) -> Id {
628 self.id
629 }
630 #[must_use]
632 pub fn run_number(&self) -> RunNumber {
633 self.run_number
634 }
635 #[must_use]
637 pub fn event_min(&self) -> i64 {
638 self.event_min
639 }
640 #[must_use]
642 pub fn event_max(&self) -> i64 {
643 self.event_max
644 }
645 #[must_use]
647 pub fn comment(&self) -> &str {
648 &self.comment
649 }
650 pub fn created(&self) -> CCDBResult<DateTime<Utc>> {
656 Ok(parse_timestamp(&self.created)?)
657 }
658 pub fn modified(&self) -> CCDBResult<DateTime<Utc>> {
664 Ok(parse_timestamp(&self.modified)?)
665 }
666}