1use chrono::{DateTime, Utc};
2use gluex_core::{parsers::parse_timestamp, Id, RunNumber};
3
4use crate::RCDBResult;
5
6#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
8pub enum ValueType {
9 #[default]
11 String,
12 Int,
14 Bool,
16 Float,
18 Json,
20 Blob,
22 Time,
24}
25impl ValueType {
26 #[must_use]
28 pub fn as_str(&self) -> &'static str {
29 match self {
30 ValueType::String => "string",
31 ValueType::Int => "int",
32 ValueType::Bool => "bool",
33 ValueType::Float => "float",
34 ValueType::Json => "json",
35 ValueType::Blob => "blob",
36 ValueType::Time => "time",
37 }
38 }
39
40 #[must_use]
42 pub fn from_identifier(value: &str) -> Option<Self> {
43 match value {
44 "string" => Some(ValueType::String),
45 "int" => Some(ValueType::Int),
46 "bool" => Some(ValueType::Bool),
47 "float" => Some(ValueType::Float),
48 "json" => Some(ValueType::Json),
49 "blob" => Some(ValueType::Blob),
50 "time" => Some(ValueType::Time),
51 _ => None,
52 }
53 }
54
55 #[must_use]
57 pub fn is_textual(&self) -> bool {
58 matches!(self, ValueType::String | ValueType::Json | ValueType::Blob)
59 }
60
61 #[must_use]
63 pub fn column_name(&self) -> &'static str {
64 match self {
65 ValueType::String | ValueType::Json | ValueType::Blob => "text_value",
66 ValueType::Int => "int_value",
67 ValueType::Bool => "bool_value",
68 ValueType::Float => "float_value",
69 ValueType::Time => "time_value",
70 }
71 }
72}
73#[derive(Debug, Clone)]
75pub struct ConditionTypeMeta {
76 pub(crate) id: Id,
77 pub(crate) name: String,
78 pub(crate) value_type: ValueType,
79 pub(crate) created: String,
80 pub(crate) description: String,
81}
82impl ConditionTypeMeta {
83 #[must_use]
85 pub fn id(&self) -> Id {
86 self.id
87 }
88 #[must_use]
90 pub fn name(&self) -> &str {
91 &self.name
92 }
93 #[must_use]
95 pub fn value_type(&self) -> ValueType {
96 self.value_type
97 }
98 #[must_use]
100 pub fn created(&self) -> String {
101 self.created.clone()
102 }
103 #[must_use]
105 pub fn description(&self) -> &str {
106 &self.description
107 }
108}
109
110#[derive(Debug, Clone)]
112pub struct ConditionMeta {
113 pub(crate) id: Id,
114 pub(crate) text_value: String,
115 pub(crate) int_value: i64,
116 pub(crate) float_value: f64,
117 pub(crate) bool_value: i64,
118 pub(crate) run_number: RunNumber,
119 pub(crate) condition_type_id: Id,
120 pub(crate) created: String,
121 pub(crate) time_value: String,
122}
123impl ConditionMeta {
124 #[must_use]
126 pub fn id(&self) -> Id {
127 self.id
128 }
129 #[must_use]
131 pub fn text_value(&self) -> &str {
132 &self.text_value
133 }
134 #[must_use]
136 pub fn int_value(&self) -> i64 {
137 self.int_value
138 }
139 #[must_use]
141 pub fn float_value(&self) -> f64 {
142 self.float_value
143 }
144 #[must_use]
146 pub fn bool_value(&self) -> i64 {
147 self.bool_value
148 }
149 #[must_use]
151 pub fn run_number(&self) -> i64 {
152 self.run_number
153 }
154 #[must_use]
156 pub fn condition_type_id(&self) -> Id {
157 self.condition_type_id
158 }
159 pub fn created(&self) -> RCDBResult<DateTime<Utc>> {
165 Ok(parse_timestamp(&self.created)?)
166 }
167 pub fn time_value(&self) -> RCDBResult<DateTime<Utc>> {
173 Ok(parse_timestamp(&self.time_value)?)
174 }
175}
176
177#[derive(Debug, Clone)]
179pub struct RunPeriodMeta {
180 pub(crate) id: Id,
181 pub(crate) name: String,
182 pub(crate) description: String,
183 pub(crate) run_min: RunNumber,
184 pub(crate) run_max: RunNumber,
185 pub(crate) start_date: String,
186 pub(crate) end_date: String,
187}
188impl RunPeriodMeta {
189 #[must_use]
191 pub fn id(&self) -> Id {
192 self.id
193 }
194 #[must_use]
196 pub fn name(&self) -> &str {
197 &self.name
198 }
199 #[must_use]
201 pub fn description(&self) -> &str {
202 &self.description
203 }
204 #[must_use]
206 pub fn run_min(&self) -> RunNumber {
207 self.run_min
208 }
209 #[must_use]
211 pub fn run_max(&self) -> RunNumber {
212 self.run_max
213 }
214 pub fn start_date(&self) -> RCDBResult<DateTime<Utc>> {
220 Ok(parse_timestamp(&self.start_date)?)
221 }
222 pub fn end_date(&self) -> RCDBResult<DateTime<Utc>> {
228 Ok(parse_timestamp(&self.end_date)?)
229 }
230}
231
232#[derive(Debug, Clone)]
234pub struct RunMeta {
235 pub(crate) number: RunNumber,
236 pub(crate) started: String,
237 pub(crate) finished: String,
238}
239impl RunMeta {
240 #[must_use]
242 pub fn number(&self) -> RunNumber {
243 self.number
244 }
245 pub fn started(&self) -> RCDBResult<DateTime<Utc>> {
251 Ok(parse_timestamp(&self.started)?)
252 }
253 pub fn finished(&self) -> RCDBResult<DateTime<Utc>> {
259 Ok(parse_timestamp(&self.finished)?)
260 }
261}