Skip to main content

ifc_cost/mutation/
draft.rs

1//! Domain-shaped drafts for the bounded IFC4 cost authoring slice.
2
3use ifc_model::EntityId;
4
5use crate::ArithmeticOperator;
6
7/// Supported `IfcCostItemTypeEnum` values.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum CostItemType {
10    /// A user-defined kind; `ObjectType` is then required.
11    UserDefined,
12    /// No more specific predefined kind is asserted.
13    NotDefined,
14}
15impl CostItemType {
16    pub(crate) const fn token(self) -> &'static str {
17        match self {
18            Self::UserDefined => "USERDEFINED",
19            Self::NotDefined => "NOTDEFINED",
20        }
21    }
22}
23
24/// Supported `IfcCostScheduleTypeEnum` values.
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum CostScheduleType {
27    /// A budget.
28    Budget,
29    /// A cost plan.
30    CostPlan,
31    /// An estimate.
32    Estimate,
33    /// A tender.
34    Tender,
35    /// A priced bill of quantities.
36    PricedBillOfQuantities,
37    /// An unpriced bill of quantities.
38    UnpricedBillOfQuantities,
39    /// A schedule of rates.
40    ScheduleOfRates,
41    /// A user-defined kind; `ObjectType` is then required.
42    UserDefined,
43    /// No more specific predefined kind is asserted.
44    NotDefined,
45}
46impl CostScheduleType {
47    pub(crate) const fn token(self) -> &'static str {
48        match self {
49            Self::Budget => "BUDGET",
50            Self::CostPlan => "COSTPLAN",
51            Self::Estimate => "ESTIMATE",
52            Self::Tender => "TENDER",
53            Self::PricedBillOfQuantities => "PRICEDBILLOFQUANTITIES",
54            Self::UnpricedBillOfQuantities => "UNPRICEDBILLOFQUANTITIES",
55            Self::ScheduleOfRates => "SCHEDULEOFRATES",
56            Self::UserDefined => "USERDEFINED",
57            Self::NotDefined => "NOTDEFINED",
58        }
59    }
60}
61
62/// The unambiguous applied-value shape supported by bounded authoring.
63#[derive(Debug, Clone, Copy)]
64pub enum CostValueKind<'a> {
65    /// One finite `IfcMonetaryMeasure`.
66    Monetary(f64),
67    /// An ordered composition of already existing or staged cost values.
68    Components {
69        /// Arithmetic operation applied by consumers.
70        operator: ArithmeticOperator,
71        /// Ordered `IfcCostValue` references; at least one is required.
72        components: &'a [EntityId],
73    },
74}
75
76#[derive(Debug, Clone, Copy)]
77/// Draft for one supported `IfcCostValue`.
78pub struct CostValueDraft<'a> {
79    /// Optional display name.
80    pub name: Option<&'a str>,
81    /// Optional description.
82    pub description: Option<&'a str>,
83    /// Optional IFC date lexical value from which the value applies.
84    pub applicable_date: Option<&'a str>,
85    /// Optional IFC date lexical value through which the value is fixed.
86    pub fixed_until_date: Option<&'a str>,
87    /// Optional cost category.
88    pub category: Option<&'a str>,
89    /// Optional applicability condition.
90    pub condition: Option<&'a str>,
91    /// Supported scalar or composed value shape.
92    pub kind: CostValueKind<'a>,
93}
94impl CostValueDraft<'_> {
95    #[must_use]
96    /// Create a scalar monetary draft with no optional metadata.
97    pub fn monetary(amount: f64) -> Self {
98        Self {
99            kind: CostValueKind::Monetary(amount),
100            ..Self::default()
101        }
102    }
103}
104impl Default for CostValueDraft<'_> {
105    fn default() -> Self {
106        Self {
107            name: None,
108            description: None,
109            applicable_date: None,
110            fixed_until_date: None,
111            category: None,
112            condition: None,
113            kind: CostValueKind::Monetary(0.0),
114        }
115    }
116}
117
118#[derive(Debug, Clone, Copy, Default)]
119/// Draft for a selected IFC4 `IfcCostItem`.
120pub struct CostItemDraft<'a> {
121    /// Compressed IFC `GlobalId`; validated before staging.
122    pub global_id: &'a str,
123    /// Optional display name.
124    pub name: Option<&'a str>,
125    /// Optional description.
126    pub description: Option<&'a str>,
127    /// Optional user-defined object type.
128    pub object_type: Option<&'a str>,
129    /// Optional domain identifier.
130    pub identification: Option<&'a str>,
131    /// Optional bounded item type.
132    pub predefined_type: Option<CostItemType>,
133    /// Ordered existing or earlier-staged `IfcCostValue` references.
134    pub cost_values: &'a [EntityId],
135}
136#[derive(Debug, Clone, Copy, Default)]
137/// Draft for an IFC4 `IfcCostSchedule`.
138pub struct CostScheduleDraft<'a> {
139    /// Compressed IFC `GlobalId`; validated before staging.
140    pub global_id: &'a str,
141    /// Optional display name.
142    pub name: Option<&'a str>,
143    /// Optional description.
144    pub description: Option<&'a str>,
145    /// Optional user-defined object type.
146    pub object_type: Option<&'a str>,
147    /// Optional domain identifier.
148    pub identification: Option<&'a str>,
149    /// Optional bounded schedule type.
150    pub predefined_type: Option<CostScheduleType>,
151    /// Optional schedule status.
152    pub status: Option<&'a str>,
153    /// Optional IFC date-time lexical submission value.
154    pub submitted_on: Option<&'a str>,
155    /// Optional IFC date-time lexical update value.
156    pub update_date: Option<&'a str>,
157}
158#[derive(Debug, Clone, Copy)]
159/// Draft for ordered cost-item nesting through `IfcRelNests`.
160pub struct NestingDraft<'a> {
161    /// Compressed IFC `GlobalId`; validated before staging.
162    pub global_id: &'a str,
163    /// Parent `IfcCostItem`.
164    pub parent: EntityId,
165    /// Non-empty, duplicate-free ordered child list.
166    pub children: &'a [EntityId],
167}
168#[derive(Debug, Clone, Copy)]
169/// Draft assigning cost items to a cost schedule.
170pub struct ScheduleAssignmentDraft<'a> {
171    /// Compressed IFC `GlobalId`; validated before staging.
172    pub global_id: &'a str,
173    /// Relating `IfcCostSchedule`.
174    pub schedule: EntityId,
175    /// Non-empty, duplicate-free related `IfcCostItem` set.
176    pub items: &'a [EntityId],
177}