use serde::{Deserialize, Serialize};
pub const CLASS_PATH: &str = "catalog";
use super::MOD_PATH;
use crate::{
DateTime, HasDescription, HasId, HasLastUpdate, HasName, HasValidity, IsAddressable,
TimePeriod, Uri,
};
use tmflib_derive::{HasDescription, HasId, HasLastUpdate, HasName, HasValidity};
#[derive(
Clone,
Default,
Debug,
Deserialize,
HasId,
HasName,
HasLastUpdate,
HasDescription,
HasValidity,
Serialize,
)]
pub struct Catalog {
pub catalog_type: Option<String>,
pub description: Option<String>,
pub href: Option<Uri>,
pub id: Option<String>,
pub last_update: Option<DateTime>,
pub lifecycle_status: Option<String>,
pub name: Option<String>,
pub valid_for: Option<TimePeriod>,
pub version: Option<String>,
}
impl Catalog {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: Some(name.into()),
..Self::create()
}
}
}
impl IsAddressable for Catalog {
fn get_objects() -> Vec<&'static str> {
super::get_objects()
}
}
#[cfg(test)]
mod test {
use super::Catalog;
use crate::HasDescription;
const CATALOG_NAME: &str = "CatalogueName";
const CATALOG_DESC: &str = "CatalogueDescription";
#[test]
fn test_catalog_description() {
let catalog = Catalog::new(CATALOG_NAME).description(CATALOG_DESC);
assert_eq!(catalog.description.is_some(), true);
assert_eq!(catalog.get_description().as_str(), CATALOG_DESC);
}
}