rs95 0.2.0

A Rust library implementing the ISA-95 domain models
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
//! Operations: from ISA-95.00.04, it is the operations management object model. This covers the
//! full lifecycle of manufacturing work — from defining how something should be made, through
//! scheduling and dispatching it, to recording what was actually done and what the site is
//! capable of.
//!
//! Reference: https://reference.opcfoundation.org/ISA-95/v100/docs/4.2.6
//!
//! The model is organised into four areas:
//!
//! - **Operations Definition** ([`WorkMaster`], [`OperationsDefinition`], [`OperationsSegment`]):
//!   structured descriptions of how work should be performed, referencing [`ProcessSegment`]s and
//!   specifying resource requirements.
//! - **Operations Scheduling** ([`OperationsSchedule`], [`OperationsRequest`],
//!   [`SegmentRequirement`]): planned work to be executed, referencing operations definitions and
//!   carrying timing and priority information.
//! - **Operations Performance** ([`JobOrder`], [`JobResponse`], [`SegmentResponse`],
//!   [`OperationsResponse`], [`OperationsPerformance`]): the transactional record of what was
//!   dispatched and what actually happened.
//! - **Operations Capability** ([`OperationsCapability`], [`OperationsCapabilityElement`]): what
//!   a site or area is currently able to produce.
//!
//! Timing fields use [`Option<String>`] to allow any ISO 8601 duration or datetime format without
//! prescribing a specific time library.
//!
//! [`ProcessSegment`]: super::process_segment::ProcessSegment

use super::process_segment::{
    EquipmentSegmentSpecification, MaterialSegmentSpecification,
    PersonnelSegmentSpecification, PhysicalAssetSegmentSpecification,
    ProcessSegmentDependencyType,
};

// ── Shared enumerations ───────────────────────────────────────────────────────

/// The category of manufacturing operation.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum OperationType {
    Production,
    Maintenance,
    Quality,
    Inventory,
    Mixed,
}

/// The action requested of a [`JobOrder`].
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum JobOrderCommandType {
    Start,
    Stop,
    Hold,
    Restart,
    Abort,
}

/// The execution status of a [`JobOrder`].
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum JobOrderStatus {
    Waiting,
    Ready,
    Running,
    Completed,
    Aborted,
}

/// The outcome recorded in a [`JobResponse`], [`SegmentResponse`], or [`OperationsResponse`].
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum OperationsResponseResult {
    Completed,
    PartCompleted,
    Aborted,
}

// ── Work master ───────────────────────────────────────────────────────────────

/// A named value attached to a [`WorkMaster`], such as a target cycle time or batch size.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct WorkMasterParameter<ID> {
    pub id: ID,
    pub name: String,
    pub value: String,
    pub unit: String,
}

/// A general, reusable description of how a category of work should be performed. One or more
/// [`OperationsDefinition`]s may reference a WorkMaster to inherit its structure.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct WorkMaster<ID> {
    pub id: ID,
    pub name: String,
    pub version: String,
    pub parameters: Vec<WorkMasterParameter<ID>>,
    /// IDs of other WorkMasters that this one is assembled from.
    pub assembled_from: Vec<ID>,
}

// ── Operations definition ─────────────────────────────────────────────────────

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsDefinitionProperty<ID> {
    pub id: ID,
    pub name: String,
    pub nested_properties: Vec<OperationsDefinitionProperty<ID>>,
}

/// A named value attached to an [`OperationsSegment`], such as a process parameter override.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsSegmentParameter<ID> {
    pub id: ID,
    pub name: String,
    pub value: String,
    pub unit: String,
}

/// A sequencing constraint between two [`OperationsSegment`]s within the same
/// [`OperationsDefinition`].
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsSegmentDependency<ID> {
    pub id: ID,
    pub dependency_type: ProcessSegmentDependencyType,
    pub from_operations_segment_id: ID,
    pub to_operations_segment_id: ID,
}

/// A step within an [`OperationsDefinition`]. References an underlying [`ProcessSegment`] and
/// carries resource specifications and parameter values specific to this operation.
///
/// [`ProcessSegment`]: super::process_segment::ProcessSegment
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsSegment<ID> {
    pub id: ID,
    pub name: String,
    /// ID of the [`ProcessSegment`] this operations segment is an instance of, if any.
    ///
    /// [`ProcessSegment`]: super::process_segment::ProcessSegment
    pub process_segment_id: Option<ID>,
    pub equipment_segment_specifications: Vec<EquipmentSegmentSpecification<ID>>,
    pub personnel_segment_specifications: Vec<PersonnelSegmentSpecification<ID>>,
    pub material_segment_specifications: Vec<MaterialSegmentSpecification<ID>>,
    pub physical_asset_segment_specifications: Vec<PhysicalAssetSegmentSpecification<ID>>,
    pub parameters: Vec<OperationsSegmentParameter<ID>>,
    pub sub_segments: Vec<OperationsSegment<ID>>,
    pub dependencies: Vec<OperationsSegmentDependency<ID>>,
}

/// A versioned, operation-type-specific description of how work should be performed. Optionally
/// derived from a [`WorkMaster`] and decomposed into [`OperationsSegment`]s.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsDefinition<ID> {
    pub id: ID,
    pub name: String,
    pub version: String,
    pub operation_type: OperationType,
    /// ID of the [`WorkMaster`] this definition is based on, if any.
    pub work_master_id: Option<ID>,
    pub properties: Vec<OperationsDefinitionProperty<ID>>,
    pub operations_segments: Vec<OperationsSegment<ID>>,
}

// ── Operations scheduling ─────────────────────────────────────────────────────

/// A named value attached to a [`SegmentRequirement`], used to supply or override parameter
/// values at scheduling time.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct SegmentRequirementParameter<ID> {
    pub id: ID,
    pub name: String,
    pub value: String,
    pub unit: String,
}

/// The scheduled execution of a specific [`OperationsSegment`] within an
/// [`OperationsRequest`], with timing constraints and parameter values.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct SegmentRequirement<ID> {
    pub id: ID,
    /// ID of the [`OperationsSegment`] to be executed.
    pub operations_segment_id: ID,
    pub earliest_start_time: Option<String>,
    pub latest_end_time: Option<String>,
    pub duration: Option<String>,
    pub parameters: Vec<SegmentRequirementParameter<ID>>,
}

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsRequestProperty<ID> {
    pub id: ID,
    pub name: String,
    pub nested_properties: Vec<OperationsRequestProperty<ID>>,
}

/// A request for a specific quantity of work to be performed, referencing an
/// [`OperationsDefinition`] and carrying a set of [`SegmentRequirement`]s.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsRequest<ID> {
    pub id: ID,
    pub operation_type: OperationType,
    /// ID of the [`OperationsDefinition`] to be executed.
    pub operations_definition_id: Option<ID>,
    pub start_time: Option<String>,
    pub end_time: Option<String>,
    pub priority: Option<i32>,
    pub properties: Vec<OperationsRequestProperty<ID>>,
    pub segment_requirements: Vec<SegmentRequirement<ID>>,
}

/// A time-bounded collection of [`OperationsRequest`]s for a given operation type.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsSchedule<ID> {
    pub id: ID,
    pub operation_type: OperationType,
    pub start_time: Option<String>,
    pub end_time: Option<String>,
    pub operations_requests: Vec<OperationsRequest<ID>>,
}

// ── Job orders ────────────────────────────────────────────────────────────────

/// A named value attached to a [`JobOrder`].
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct JobOrderParameter<ID> {
    pub id: ID,
    pub name: String,
    pub value: String,
    pub unit: String,
}

/// A dispatched unit of work. References an [`OperationsRequest`] and/or an
/// [`OperationsDefinition`], carries an execution command and a status, and may have
/// timing and parameter information attached.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct JobOrder<ID> {
    pub id: ID,
    pub work_type: OperationType,
    pub command: JobOrderCommandType,
    pub status: JobOrderStatus,
    pub priority: Option<i32>,
    /// ID of the [`OperationsRequest`] this job order fulfils, if any.
    pub operations_request_id: Option<ID>,
    /// ID of the [`OperationsDefinition`] to be executed, if not derived from the request.
    pub operations_definition_id: Option<ID>,
    pub start_time: Option<String>,
    pub end_time: Option<String>,
    pub parameters: Vec<JobOrderParameter<ID>>,
}

// ── Operations performance ────────────────────────────────────────────────────

/// A named value recorded as part of a [`JobResponse`].
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct JobResponseParameter<ID> {
    pub id: ID,
    pub name: String,
    pub value: String,
    pub unit: String,
}

/// The actual outcome of a [`JobOrder`]: when it ran, what the result was, and any recorded
/// parameter values.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct JobResponse<ID> {
    pub id: ID,
    /// ID of the [`JobOrder`] this response is for.
    pub job_order_id: ID,
    pub actual_start_time: Option<String>,
    pub actual_end_time: Option<String>,
    pub result: OperationsResponseResult,
    pub parameters: Vec<JobResponseParameter<ID>>,
}

/// The actual execution of a single [`OperationsSegment`], recording timing, result, and the
/// specific resources that were consumed or used.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct SegmentResponse<ID> {
    pub id: ID,
    /// ID of the [`OperationsSegment`] that was executed.
    pub operations_segment_id: ID,
    pub actual_start_time: Option<String>,
    pub actual_end_time: Option<String>,
    pub result: OperationsResponseResult,
    pub actual_equipment_ids: Vec<ID>,   // IDs of Equipment
    pub actual_person_ids: Vec<ID>,      // IDs of Person
    pub actual_material_lot_ids: Vec<ID>, // IDs of MaterialLot
    pub actual_physical_asset_ids: Vec<ID>, // IDs of PhysicalAsset
}

/// The actual outcome of an [`OperationsRequest`], aggregating [`SegmentResponse`]s and
/// [`JobResponse`]s.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsResponse<ID> {
    pub id: ID,
    /// ID of the [`OperationsRequest`] this response fulfils.
    pub operations_request_id: ID,
    pub actual_start_time: Option<String>,
    pub actual_end_time: Option<String>,
    pub result: OperationsResponseResult,
    pub segment_responses: Vec<SegmentResponse<ID>>,
    pub job_responses: Vec<JobResponse<ID>>,
}

/// A time-bounded record of what was actually performed, grouping [`OperationsResponse`]s for a
/// given operation type.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsPerformance<ID> {
    pub id: ID,
    pub operation_type: OperationType,
    pub start_time: Option<String>,
    pub end_time: Option<String>,
    pub operations_responses: Vec<OperationsResponse<ID>>,
}

// ── Operations capability ─────────────────────────────────────────────────────

#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsCapabilityProperty<ID> {
    pub id: ID,
    pub name: String,
    pub nested_properties: Vec<OperationsCapabilityProperty<ID>>,
}

/// A single capability entry, indicating that a given [`OperationsDefinition`] can be executed
/// within a stated time window.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsCapabilityElement<ID> {
    pub id: ID,
    pub operation_type: OperationType,
    /// ID of the [`OperationsDefinition`] this element describes capability for.
    pub operations_definition_id: Option<ID>,
    pub available_start_time: Option<String>,
    pub available_end_time: Option<String>,
    pub properties: Vec<OperationsCapabilityProperty<ID>>,
}

/// A time-bounded declaration of what a site or area can produce or perform.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(
    feature = "serde",
    serde(bound(
        serialize = "ID: serde::Serialize",
        deserialize = "ID: serde::Deserialize<'de>"
    ))
)]
pub struct OperationsCapability<ID> {
    pub id: ID,
    pub operation_type: OperationType,
    pub start_time: Option<String>,
    pub end_time: Option<String>,
    pub elements: Vec<OperationsCapabilityElement<ID>>,
}

#[cfg(test)]
mod tests {
    use super::*;
    use uuid::Uuid;

    #[test]
    fn test_operations_model() {
        // Build a WorkMaster and OperationsDefinition
        let work_master = WorkMaster::<Uuid> {
            id: Uuid::new_v4(),
            name: "Bottling".to_string(),
            version: "1.0".to_string(),
            parameters: vec![WorkMasterParameter {
                id: Uuid::new_v4(),
                name: "BatchSize".to_string(),
                value: "500".to_string(),
                unit: "units".to_string(),
            }],
            assembled_from: vec![],
        };

        let ops_segment_id = Uuid::new_v4();
        let ops_def = OperationsDefinition::<Uuid> {
            id: Uuid::new_v4(),
            name: "Bottling Run".to_string(),
            version: "1.0".to_string(),
            operation_type: OperationType::Production,
            work_master_id: Some(work_master.id),
            properties: vec![],
            operations_segments: vec![OperationsSegment {
                id: ops_segment_id,
                name: "Fill".to_string(),
                process_segment_id: None,
                equipment_segment_specifications: vec![],
                personnel_segment_specifications: vec![],
                material_segment_specifications: vec![],
                physical_asset_segment_specifications: vec![],
                parameters: vec![OperationsSegmentParameter {
                    id: Uuid::new_v4(),
                    name: "FillVolume".to_string(),
                    value: "330".to_string(),
                    unit: "ml".to_string(),
                }],
                sub_segments: vec![],
                dependencies: vec![],
            }],
        };

        // Schedule it
        let request_id = Uuid::new_v4();
        let schedule = OperationsSchedule::<Uuid> {
            id: Uuid::new_v4(),
            operation_type: OperationType::Production,
            start_time: Some("2026-04-14T06:00:00Z".to_string()),
            end_time: Some("2026-04-14T14:00:00Z".to_string()),
            operations_requests: vec![OperationsRequest {
                id: request_id,
                operation_type: OperationType::Production,
                operations_definition_id: Some(ops_def.id),
                start_time: Some("2026-04-14T08:00:00Z".to_string()),
                end_time: Some("2026-04-14T10:00:00Z".to_string()),
                priority: Some(1),
                properties: vec![],
                segment_requirements: vec![SegmentRequirement {
                    id: Uuid::new_v4(),
                    operations_segment_id: ops_segment_id,
                    earliest_start_time: Some("2026-04-14T08:00:00Z".to_string()),
                    latest_end_time: Some("2026-04-14T10:00:00Z".to_string()),
                    duration: Some("PT2H".to_string()),
                    parameters: vec![],
                }],
            }],
        };

        // Dispatch a job order
        let job_order = JobOrder::<Uuid> {
            id: Uuid::new_v4(),
            work_type: OperationType::Production,
            command: JobOrderCommandType::Start,
            status: JobOrderStatus::Waiting,
            priority: Some(1),
            operations_request_id: Some(request_id),
            operations_definition_id: Some(ops_def.id),
            start_time: Some("2026-04-14T08:00:00Z".to_string()),
            end_time: None,
            parameters: vec![],
        };

        // Record performance
        let performance = OperationsPerformance::<Uuid> {
            id: Uuid::new_v4(),
            operation_type: OperationType::Production,
            start_time: Some("2026-04-14T08:00:00Z".to_string()),
            end_time: Some("2026-04-14T09:45:00Z".to_string()),
            operations_responses: vec![OperationsResponse {
                id: Uuid::new_v4(),
                operations_request_id: request_id,
                actual_start_time: Some("2026-04-14T08:00:00Z".to_string()),
                actual_end_time: Some("2026-04-14T09:45:00Z".to_string()),
                result: OperationsResponseResult::Completed,
                segment_responses: vec![SegmentResponse {
                    id: Uuid::new_v4(),
                    operations_segment_id: ops_segment_id,
                    actual_start_time: Some("2026-04-14T08:00:00Z".to_string()),
                    actual_end_time: Some("2026-04-14T09:45:00Z".to_string()),
                    result: OperationsResponseResult::Completed,
                    actual_equipment_ids: vec![],
                    actual_person_ids: vec![],
                    actual_material_lot_ids: vec![],
                    actual_physical_asset_ids: vec![],
                }],
                job_responses: vec![JobResponse {
                    id: Uuid::new_v4(),
                    job_order_id: job_order.id,
                    actual_start_time: Some("2026-04-14T08:00:00Z".to_string()),
                    actual_end_time: Some("2026-04-14T09:45:00Z".to_string()),
                    result: OperationsResponseResult::Completed,
                    parameters: vec![],
                }],
            }],
        };

        // Declare capability
        let capability = OperationsCapability::<Uuid> {
            id: Uuid::new_v4(),
            operation_type: OperationType::Production,
            start_time: Some("2026-04-14T00:00:00Z".to_string()),
            end_time: Some("2026-04-15T00:00:00Z".to_string()),
            elements: vec![OperationsCapabilityElement {
                id: Uuid::new_v4(),
                operation_type: OperationType::Production,
                operations_definition_id: Some(ops_def.id),
                available_start_time: Some("2026-04-14T06:00:00Z".to_string()),
                available_end_time: Some("2026-04-14T22:00:00Z".to_string()),
                properties: vec![],
            }],
        };

        assert_eq!(work_master.name, "Bottling");
        assert_eq!(ops_def.operations_segments[0].name, "Fill");
        assert_eq!(schedule.operations_requests[0].priority, Some(1));
        assert_eq!(job_order.command, JobOrderCommandType::Start);
        assert_eq!(
            performance.operations_responses[0].result,
            OperationsResponseResult::Completed
        );
        assert_eq!(capability.elements[0].operation_type, OperationType::Production);
    }
}