use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TibetEnvelope {
pub erin: Erin,
pub eraan: Vec<String>,
pub eromheen: Eromheen,
pub erachter: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Erin {
pub content_hash: String,
pub block_type: String,
pub mime_type: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Eromheen {
pub created: String,
pub origin: String,
pub tbz_version: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub source_repo: Option<String>,
}
impl TibetEnvelope {
pub fn new(
content_hash: String,
block_type: &str,
mime_type: &str,
origin: &str,
intent: &str,
dependencies: Vec<String>,
) -> Self {
Self {
erin: Erin {
content_hash,
block_type: block_type.to_string(),
mime_type: mime_type.to_string(),
},
eraan: dependencies,
eromheen: Eromheen {
created: chrono_now(),
origin: origin.to_string(),
tbz_version: format!("{}", crate::VERSION),
source_repo: None,
},
erachter: intent.to_string(),
}
}
pub fn with_source_repo(mut self, repo: &str) -> Self {
self.eromheen.source_repo = Some(repo.to_string());
self
}
}
fn chrono_now() -> String {
use std::time::SystemTime;
let duration = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default();
format!("{}Z", duration.as_secs())
}