tmflib/tmf764/
projected_cost.rs

1//! Projected Cost Module
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6    common::{attachment::AttachmentRefOrValue, note::Note, related_party::RelatedParty},
7    vec_insert, HasAttachment, HasDescription, HasId, HasLastUpdate, HasName, HasNote,
8    HasRelatedParty, TMFError, Uri,
9};
10
11use super::MOD_PATH;
12use tmflib_derive::{
13    HasAttachment, HasDescription, HasId, HasLastUpdate, HasName, HasNote, HasRelatedParty,
14};
15
16const CLASS_PATH: &str = "ProjectedCost";
17
18/// Projected Cost Item
19#[derive(Debug, Default, Clone, Serialize, Deserialize)]
20pub struct ProjectedCostItem {
21    /// Unique identifier
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub id: Option<String>,
24    /// Name
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub name: Option<String>,
27    /// Description
28    #[serde(skip_serializing_if = "Option::is_none")]
29    pub description: Option<String>,
30}
31
32/// Projected Cost
33#[derive(
34    Debug,
35    Default,
36    Clone,
37    HasId,
38    HasName,
39    HasAttachment,
40    HasDescription,
41    HasLastUpdate,
42    HasNote,
43    HasRelatedParty,
44    Serialize,
45    Deserialize,
46)]
47#[serde(rename_all = "camelCase")]
48pub struct ProjectedCost {
49    /// Unique identifier
50    pub id: Option<String>,
51    /// Hyperlink reference
52    pub href: Option<Uri>,
53    /// Name
54    #[serde(skip_serializing_if = "Option::is_none")]
55    pub name: Option<String>,
56    /// Description
57    #[serde(skip_serializing_if = "Option::is_none")]
58    pub description: Option<String>,
59    /// Cost Items
60    pub cost_item: Option<Vec<ProjectedCostItem>>,
61
62    /// Notes
63    #[serde(skip_serializing_if = "Option::is_none")]
64    pub note: Option<Vec<Note>>,
65
66    /// Related Parties
67    #[serde(skip_serializing_if = "Option::is_none")]
68    pub related_party: Option<Vec<RelatedParty>>,
69
70    /// Last Update
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub last_update: Option<crate::DateTime>,
73    /// Attachments
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub attachment: Option<Vec<AttachmentRefOrValue>>,
76}
77
78impl ProjectedCost {
79    /// Create a new Actual Cost
80    pub fn new(name: impl Into<String>) -> Self {
81        Self::create_with_time().name(name.into())
82    }
83
84    /// Add an Actual Cost Item
85    ///
86    /// # Arguments
87    /// * `item` - The Actual Cost Item to add
88    /// # Returns
89    /// * `Self` - The updated Actual Cost
90    /// # Example
91    /// ```rust
92    /// use tmflib::tmf764::actual_cost::{ActualCost, ActualCostItem};
93    /// let cost = ActualCost::new("Example Cost")
94    ///     .item(ActualCostItem::new("Item 1"));
95    /// ```
96    pub fn item(mut self, item: ProjectedCostItem) -> Self {
97        vec_insert(&mut self.cost_item, item);
98        self
99    }
100}
101
102impl From<ProjectedCost> for super::CostRef {
103    fn from(cost: ProjectedCost) -> Self {
104        crate::tmf764::CostRef {
105            id: cost.get_id(),
106            href: cost.get_href(),
107            name: cost.name.clone(),
108            base_type: None,
109            referred_type: None,
110            schema_location: None,
111            r#type: Some(String::from("ProjectedCost")),
112        }
113    }
114}