use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::Record;
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct PipelineMetadata {
pub data_source: DataSource,
pub content_type: Option<String>,
#[serde(default)]
pub custom: Record,
}
impl PipelineMetadata {
pub fn with_data_source(self, data_source: DataSource) -> Self {
Self {
data_source,
..self
}
}
pub fn with_content_type(self, content_type: Option<String>) -> Self {
Self {
content_type,
..self
}
}
pub fn for_collect(self) -> Option<Self> {
let Self {
data_source,
content_type,
custom,
} = self;
let data_source = match data_source {
DataSource::FilePath(_) => DataSource::None,
other => other,
};
if matches!(data_source, DataSource::None) && content_type.is_none() && custom.is_empty() {
None
} else {
Some(Self {
data_source,
content_type,
custom,
})
}
}
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub enum DataSource {
Ls,
HtmlThemes,
FilePath(PathBuf),
#[default]
None,
}