use std::borrow::Cow;
use minarrow::Field;
use crate::models::interfaces::json::ValueSource;
#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[non_exhaustive]
pub enum ReadAs {
#[default]
Verbatim,
Number,
Bool,
Datetime,
Dictionary(Vec<String>),
}
#[derive(Debug, Clone, Default)]
pub struct JsonSchema {
fields: Vec<Field>,
sources: Vec<ValueSource>,
read_as: Vec<ReadAs>,
record_path: Option<Cow<'static, str>>,
}
impl JsonSchema {
pub fn new() -> Self {
Self::default()
}
pub fn column(mut self, field: Field, source: ValueSource, read_as: ReadAs) -> Self {
self.fields.push(field);
self.sources.push(source);
self.read_as.push(read_as);
self
}
pub fn with_record_path(mut self, path: impl Into<Cow<'static, str>>) -> Self {
self.record_path = Some(path.into());
self
}
pub fn fields(&self) -> &[Field] {
&self.fields
}
pub fn sources(&self) -> &[ValueSource] {
&self.sources
}
pub fn read_as(&self) -> &[ReadAs] {
&self.read_as
}
pub fn record_path(&self) -> Option<&str> {
self.record_path.as_deref()
}
}