Skip to main content

systemprompt_models/artifacts/table/
column.rs

1//! Table-artifact column definitions.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use crate::artifacts::types::{Alignment, ColumnType};
7use schemars::JsonSchema;
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
11pub struct Column {
12    pub name: String,
13    #[serde(rename = "column_type")]
14    pub kind: ColumnType,
15    #[serde(skip_serializing_if = "Option::is_none")]
16    pub label: Option<String>,
17    #[serde(skip_serializing_if = "Option::is_none")]
18    pub width: Option<usize>,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub align: Option<Alignment>,
21}
22
23impl Column {
24    pub fn new(name: impl Into<String>, kind: ColumnType) -> Self {
25        Self {
26            name: name.into(),
27            kind,
28            label: None,
29            width: None,
30            align: None,
31        }
32    }
33
34    pub fn with_header(mut self, header: impl Into<String>) -> Self {
35        self.label = Some(header.into());
36        self
37    }
38
39    pub fn with_label(self, label: impl Into<String>) -> Self {
40        self.with_header(label)
41    }
42
43    pub const fn with_width(mut self, width: usize) -> Self {
44        self.width = Some(width);
45        self
46    }
47
48    pub const fn with_alignment(mut self, align: Alignment) -> Self {
49        self.align = Some(align);
50        self
51    }
52
53    pub fn name(&self) -> &str {
54        &self.name
55    }
56
57    pub const fn column_type(&self) -> ColumnType {
58        self.kind
59    }
60}