use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct ContainerIndex {
pub description: ContainerDescription,
pub documents: Vec<Document>,
pub linkset_files: Vec<LinksetRef>,
}
#[derive(Debug, Clone, Serialize)]
pub struct ContainerDescription {
pub id: String,
pub conformance_indicator: Option<String>,
pub description: Option<String>,
pub creation_date: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct LinksetRef {
pub id: String,
pub filename: Option<String>,
pub name: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Document {
pub id: String,
pub kind: DocumentKind,
pub name: Option<String>,
pub description: Option<String>,
pub filetype: Option<String>,
pub format: Option<String>,
pub checksum: Option<Checksum>,
pub encrypted: bool,
pub requested: bool,
}
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum DocumentKind {
Internal {
filename: String,
},
External {
url: String,
},
Folder {
foldername: String,
},
}
#[derive(Debug, Clone, Serialize)]
pub struct Checksum {
pub algorithm: String,
pub value: String,
}
impl Document {
pub fn is_ifc(&self) -> bool {
let ft = self.filetype.as_deref().unwrap_or("").to_ascii_lowercase();
if ft == "ifc" || ft.starts_with("ifc-") || ft.starts_with("ifc ") {
return true;
}
if let Some(fmt) = &self.format {
if fmt.to_ascii_lowercase().contains("ifc") {
return true;
}
}
self.internal_path()
.map(|p| p.to_ascii_lowercase().ends_with(".ifc"))
.unwrap_or(false)
}
pub fn internal_path(&self) -> Option<&str> {
match &self.kind {
DocumentKind::Internal { filename } => Some(filename),
_ => None,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct LinkSet {
pub filename: String,
pub links: Vec<Link>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Link {
pub id: String,
pub directed: bool,
pub elements: Vec<LinkElement>,
pub from: Vec<String>,
pub to: Vec<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct LinkElement {
pub id: String,
pub document_id: Option<String>,
pub identifier: Option<ElementIdentifier>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ElementIdentifier {
String {
value: String,
field: Option<String>,
},
Uri {
uri: String,
},
Query {
language: Option<String>,
expression: Option<String>,
},
}