use serde::{Deserialize, Serialize};
use super::{ArtifactType, Author, License};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ResearchArtifact {
pub id: String,
pub title: String,
pub authors: Vec<Author>,
pub artifact_type: ArtifactType,
pub license: License,
pub doi: Option<String>,
pub version: String,
pub description: Option<String>,
pub keywords: Vec<String>,
pub created_at: chrono::DateTime<chrono::Utc>,
}
impl ResearchArtifact {
pub fn new(
id: impl Into<String>,
title: impl Into<String>,
artifact_type: ArtifactType,
license: License,
) -> Self {
Self {
id: id.into(),
title: title.into(),
authors: Vec::new(),
artifact_type,
license,
doi: None,
version: "1.0.0".to_string(),
description: None,
keywords: Vec::new(),
created_at: chrono::Utc::now(),
}
}
pub fn with_author(mut self, author: Author) -> Self {
self.authors.push(author);
self
}
pub fn with_authors(mut self, authors: impl IntoIterator<Item = Author>) -> Self {
self.authors.extend(authors);
self
}
pub fn with_doi(mut self, doi: impl Into<String>) -> Self {
self.doi = Some(doi.into());
self
}
pub fn with_version(mut self, version: impl Into<String>) -> Self {
self.version = version.into();
self
}
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn with_keywords(mut self, keywords: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.keywords.extend(keywords.into_iter().map(Into::into));
self
}
pub fn first_author(&self) -> Option<&Author> {
self.authors.first()
}
}