use crate::core::macros::{tmf_entity, tmf_patch_body, tmf_struct};
use crate::core::{Ref, RelatedParty, TimePeriod, Timestamp};
use super::ProductOffering;
tmf_struct! {
@name = "ProductCatalog";
pub struct ProductCatalog {
id: String,
href: String,
name: String,
description: String,
version: String,
catalog_type: String,
last_update: Timestamp,
lifecycle_status: String,
valid_for: TimePeriod,
category: Vec<Ref<Category>>,
related_party: Vec<RelatedParty>,
}
}
tmf_struct! {
@name = "ProductCatalog";
pub struct ProductCatalogCreate {
@required {
name: String,
}
id: String,
description: String,
version: String,
catalog_type: String,
last_update: Timestamp,
lifecycle_status: String,
valid_for: TimePeriod,
category: Vec<Ref<Category>>,
related_party: Vec<RelatedParty>,
}
}
tmf_struct! {
@name = "ProductCatalog";
pub struct ProductCatalogUpdate {
name: String,
description: String,
version: String,
catalog_type: String,
last_update: Timestamp,
lifecycle_status: String,
valid_for: TimePeriod,
category: Vec<Ref<Category>>,
related_party: Vec<RelatedParty>,
}
}
tmf_struct! {
@name = "Category", @ref = "CategoryRef";
pub struct Category {
id: String,
href: String,
name: String,
description: String,
version: String,
last_update: Timestamp,
lifecycle_status: String,
is_root: bool,
parent: Ref<Category>,
valid_for: TimePeriod,
sub_category: Vec<Ref<Category>>,
product_offering: Vec<Ref<ProductOffering>>,
}
}
tmf_entity!(ProductCatalog, Category);
tmf_struct! {
@name = "Category";
pub struct CategoryCreate {
@required {
name: String,
}
id: String,
description: String,
version: String,
last_update: Timestamp,
lifecycle_status: String,
is_root: bool,
parent: Ref<Category>,
valid_for: TimePeriod,
sub_category: Vec<Ref<Category>>,
product_offering: Vec<Ref<ProductOffering>>,
}
}
tmf_struct! {
@name = "Category";
pub struct CategoryUpdate {
name: String,
description: String,
version: String,
lifecycle_status: String,
is_root: bool,
parent: Ref<Category>,
valid_for: TimePeriod,
sub_category: Vec<Ref<Category>>,
product_offering: Vec<Ref<ProductOffering>>,
}
}
tmf_patch_body!(ProductCatalogUpdate, CategoryUpdate);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_v5_parent_is_a_reference_not_an_id() {
let json = r#"{"@type":"Category","parent":{"id":"12","@type":"CategoryRef"}}"#;
let category: Category = serde_json::from_str(json).unwrap();
assert_eq!(category.parent.as_ref().unwrap().id, "12");
assert!(
category.extensions.is_empty(),
"v4's parentId is gone; `parent` must be typed"
);
}
}