1use chrono::NaiveDate;
7use rust_decimal::Decimal;
8use serde::{Deserialize, Serialize};
9use std::collections::HashMap;
10
11use super::graph_properties::{GraphPropertyValue, ToNodeProperties};
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
15#[serde(rename_all = "snake_case")]
16pub enum InspectionResult {
17 #[default]
19 Accepted,
20 Rejected,
22 Conditionally,
24 Pending,
26}
27
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
30#[serde(rename_all = "snake_case")]
31pub enum InspectionType {
32 #[default]
34 Incoming,
35 InProcess,
37 Final,
39 Random,
41 Periodic,
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47pub struct QualityInspection {
48 pub inspection_id: String,
50 pub company_code: String,
52 pub reference_type: String,
54 pub reference_id: String,
56 pub material_id: String,
58 pub material_description: String,
60 pub inspection_type: InspectionType,
62 pub inspection_date: NaiveDate,
64 pub inspector_id: Option<String>,
66 #[serde(with = "rust_decimal::serde::str")]
68 pub lot_size: Decimal,
69 #[serde(with = "rust_decimal::serde::str")]
71 pub sample_size: Decimal,
72 pub defect_count: u32,
74 pub defect_rate: f64,
76 pub result: InspectionResult,
78 pub characteristics: Vec<InspectionCharacteristic>,
80 pub disposition: Option<String>,
82 pub notes: Option<String>,
84}
85
86impl ToNodeProperties for QualityInspection {
87 fn node_type_name(&self) -> &'static str {
88 "quality_inspection"
89 }
90 fn node_type_code(&self) -> u16 {
91 341
92 }
93 fn to_node_properties(&self) -> HashMap<String, GraphPropertyValue> {
94 let mut p = HashMap::new();
95 p.insert(
96 "inspectionId".into(),
97 GraphPropertyValue::String(self.inspection_id.clone()),
98 );
99 p.insert(
100 "entityCode".into(),
101 GraphPropertyValue::String(self.company_code.clone()),
102 );
103 p.insert(
104 "referenceType".into(),
105 GraphPropertyValue::String(self.reference_type.clone()),
106 );
107 p.insert(
108 "referenceId".into(),
109 GraphPropertyValue::String(self.reference_id.clone()),
110 );
111 p.insert(
112 "materialId".into(),
113 GraphPropertyValue::String(self.material_id.clone()),
114 );
115 p.insert(
116 "materialDescription".into(),
117 GraphPropertyValue::String(self.material_description.clone()),
118 );
119 p.insert(
120 "inspectionType".into(),
121 GraphPropertyValue::String(format!("{:?}", self.inspection_type)),
122 );
123 p.insert(
124 "inspectionDate".into(),
125 GraphPropertyValue::Date(self.inspection_date),
126 );
127 p.insert("lotSize".into(), GraphPropertyValue::Decimal(self.lot_size));
128 p.insert(
129 "inspectedQuantity".into(),
130 GraphPropertyValue::Decimal(self.sample_size),
131 );
132 p.insert(
133 "defectQuantity".into(),
134 GraphPropertyValue::Int(self.defect_count as i64),
135 );
136 p.insert(
137 "defectRate".into(),
138 GraphPropertyValue::Float(self.defect_rate),
139 );
140 p.insert(
141 "result".into(),
142 GraphPropertyValue::String(format!("{:?}", self.result)),
143 );
144 p.insert(
145 "isPassed".into(),
146 GraphPropertyValue::Bool(matches!(
147 self.result,
148 InspectionResult::Accepted | InspectionResult::Conditionally
149 )),
150 );
151 p
152 }
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize)]
157pub struct InspectionCharacteristic {
158 pub name: String,
160 pub target_value: f64,
162 pub actual_value: f64,
164 pub lower_limit: f64,
166 pub upper_limit: f64,
168 pub passed: bool,
170}