#![deny(missing_docs)]
#![deny(unsafe_code)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};
use crate::events::EPCISEvent;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EPCISDocument {
#[serde(rename = "@context")]
pub context: serde_json::Value,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
#[serde(rename = "type")]
pub r#type: String,
pub schema_version: String,
pub creation_date: DateTime<Utc>,
#[serde(skip_serializing_if = "Option::is_none")]
pub epcis_header: Option<EPCISHeader>,
pub epcis_body: EPCISBody,
#[serde(flatten)]
pub extensions: serde_json::Map<String, serde_json::Value>,
}
impl EPCISDocument {
#[must_use]
pub fn new(event_list: Vec<EPCISEvent>) -> Self {
Self {
context: serde_json::json!([
"https://ref.gs1.org/standards/epcis/2.0.0/epcis-context.jsonld"
]),
id: None,
r#type: "EPCISDocument".to_string(),
schema_version: "2.0".to_string(),
creation_date: Utc::now(),
epcis_header: None,
epcis_body: EPCISBody { event_list },
extensions: serde_json::Map::new(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EPCISHeader {
#[serde(skip_serializing_if = "Option::is_none")]
pub epcis_master_data: Option<EPCISMasterData>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EPCISMasterData {
pub vocabulary_list: Vec<VocabularyElement>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VocabularyElement {
#[serde(rename = "type")]
pub r#type: String,
pub element_list: Vec<VocabularyElementList>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VocabularyElementList {
pub id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub attributes: Option<Vec<VocabularyAttribute>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub children: Option<Vec<String>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct VocabularyAttribute {
pub id: String,
pub value: serde_json::Value,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EPCISBody {
pub event_list: Vec<EPCISEvent>,
}