openconfiguration/
product.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    impl_visitable_noop, measurement::MeasurementLine, preview::Preview, status::Status,
7    AttachPoint, Commercial, Component, MasterData, TopView, Transform,
8};
9
10#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
11#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
12pub enum ProductKind {
13    /// regular product
14    Product,
15    /// a commercial container for multiple products
16    Set,
17    Placeholder,
18}
19
20#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
21#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
22#[cfg_attr(feature = "schema", schemars(deny_unknown_fields))]
23#[serde(rename_all = "camelCase")]
24/// An initial or incremental product representation.
25pub struct Product {
26    pub kind: Option<ProductKind>,
27    /// Optional state information for a product. Even if the state object
28    /// exists, not all attributes may be set.
29    /// The state information always entirely updates an existing state
30    /// information.
31    pub state: Option<ProductState>,
32    /// Optional world transform of the product representation.
33    /// If the transform is not null, it entirely replaces the existing transform.
34    pub transform: Option<Transform>,
35    /// The mandatory attribute maps material categories to materials.
36    /// Both, material categories and materials should be compatible with a
37    /// three-level technical namespace.
38    /// Implicit material categories consist of prefix '@' and a material,
39    /// and should be included too, even if this is kind of redundant.
40    ///
41    /// IGXC Compatibility: In IGXC this attribute was named Categories.
42    #[serde(
43        deserialize_with = "crate::utils::deserialize_optional_map_without_null_values",
44        default
45    )]
46    pub material_categories: Option<HashMap<String, String>>,
47    /// Product categories for the client-side implementation of planning
48    /// behavior.
49    /// If Categories is not null, it entirely replaces the existing categories.
50    ///
51    /// IGXC Compatibility: In IGXC, categories were considered from the
52    /// structure's root entry. Now they can be updated, even if the
53    /// structure does not change.
54    pub categories: Option<Vec<String>>,
55    /// The tree structure that describes the product in 3D.
56    /// If the structure is not null, it entirely replaces the existing
57    /// structure.
58    pub structure: Option<Vec<Component>>,
59    /// An optional product representation from top-view perspective.
60    /// Version: OC 1.2
61    ///
62    pub top_view: Option<TopView>,
63    /// An optional product preview image.
64    /// Version: OC 1.2
65    pub preview: Option<Preview>,
66    /// Attachment points for the client-side creation of neighbor and
67    /// parent-child relationships.
68    /// If Points is not null, it entirely replaces the existing points.
69    ///
70    /// IGXC Compatibility: In IGXC, points were considered from the
71    /// structure's root entry. Now they can be updated, even if the
72    /// structure does not change.
73    pub points: Option<Vec<AttachPoint>>,
74    /// Commercial data related to this product
75    pub commercial: Option<Commercial>,
76    /// Contains product related status information.
77    pub status: Option<Status>,
78    /// Master data related to this product
79    /// Version: OC 1.3
80    pub master_data: Option<MasterData>,
81    /// Additional measurements for this product
82    /// Version: OC 1.7
83    pub measurements: Option<Vec<MeasurementLine>>,
84}
85
86impl_visitable_noop!(Product);
87
88#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
89#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
90#[cfg_attr(feature = "schema", schemars(deny_unknown_fields))]
91#[serde(rename_all = "camelCase")]
92/// State information of a product.
93///
94/// IGXC Compatibility: The PBR hash has been removed for now.
95pub struct ProductState {
96    /// Optional commercial instance id. Will be sent from client to server
97    /// (and retour) to identify the object in the configurator/basket.
98    ///
99    /// Note. comId should match to Commercial.Id if Commercial exists.
100    pub com_id: Option<String>,
101
102    /// Optional graphical instance it. Will typically be sent from client
103    /// (where this id is created and managed) to the server and returned
104    /// from it, for clear assignment of product representation.
105    pub gfx_id: Option<String>,
106
107    /// The geometric hash may be created from a configurator service. It
108    /// will be sent to the client, which may return it during upcoming
109    /// update requests. The service may then detect a non-geometric update
110    /// of the product representation and send a corresponding update.
111    pub geometric_hash: Option<String>,
112
113    /// The visual hash may be created from a configurator service. It
114    /// will be sent to the client, which may return it during upcoming
115    /// update requests. The service may then detect a non-visual update
116    /// of the product representation and send a corresponding update.
117    pub visual_hash: Option<String>,
118}