1use serde::{Deserialize, Serialize};
2
3use crate::flags;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Column {
12 pub name: String,
13 pub original_type: String,
14 #[serde(default, skip_serializing_if = "Vec::is_empty")]
15 pub flags: Vec<String>,
16}
17
18impl Column {
19 pub fn new(name: impl Into<String>, original_type: impl Into<String>) -> Self {
20 Self {
21 name: name.into(),
22 original_type: original_type.into(),
23 flags: Vec::new(),
24 }
25 }
26
27 pub fn with_flag(mut self, flag: impl Into<String>) -> Self {
28 self.flags.push(flag.into());
29 self
30 }
31
32 pub fn hidden(self) -> Self {
33 self.with_flag(flags::HIDDEN)
34 }
35
36 pub fn has_flag(&self, flag: &str) -> bool {
37 self.flags.iter().any(|f| f == flag)
38 }
39
40 pub fn is_hidden(&self) -> bool {
41 self.has_flag(flags::HIDDEN)
42 }
43
44 pub fn is_id(&self) -> bool {
45 self.has_flag(flags::ID)
46 }
47
48 pub fn is_title(&self) -> bool {
49 self.has_flag(flags::TITLE)
50 }
51}