Skip to main content

printobserver_core/records/
samples.rs

1//! The canonical values of every record this domain declares.
2//!
3//! One value carrying every field, one carrying every optional field absent,
4//! and one per further arm of a union: what the schema set and the round-trip
5//! corpus are walked over. They are here rather than beside each record so
6//! that the records read as the data they are, and so that the fixed
7//! identifiers and instants the samples share are written once.
8
9use std::collections::BTreeMap;
10
11use printobserver_printer_api::{Adjustable, PrinterState};
12use printobserver_types::contract::Sample;
13use printobserver_types::{EventId, FileName, ImageId, PrintId, Range, Timestamp};
14
15use super::action::{
16    AcknowledgementDisposition, ActionKind, ActionRecord, ActionRequest, Actor, ActorClass,
17    ExecutionOutcome, PrintAction,
18};
19use super::charge::{
20    ChargeKey, ChargeMethod, ChargedFilament, FilePosition, PendingCharge, PendingTaken,
21    PrintOutcome, PrintSegmentKey,
22};
23use super::ids::{ActionId, InterventionId, SpoolId};
24use super::image::ImageRecord;
25use super::intervention::{Intervention, InterventionOutcome};
26use super::manifest::JobManifest;
27use super::policy::{
28    EffectiveBounds, PolicyDecision, RejectionReason, SafetyEnvelope, SpoolField, SpoolRefusalCause,
29};
30use super::preflight::{
31    DoubtedSpool, Preflight, PreflightNeed, PreflightObjection, PreflightSpool, PreflightTool,
32    PreflightToolResult, PreflightVerdict, ShortSpool, UnanalysedSpool,
33};
34use super::print::{ManifestNarrowing, PrintRecord};
35use super::spool::{
36    ClearedMark, LoadedSpool, SpoolLifecycle, SpoolRecord, SpoolTrust, UnverifiedMark,
37    UnverifiedMarks, UnverifiedReason,
38};
39use super::spool_command::SpoolCommand;
40
41/// A later fixed instant than the one the type crate's sample carries.
42fn later_instant() -> Timestamp {
43    "2026-03-01T12:30:00Z"
44        .parse()
45        .expect("a fixed RFC 3339 instant")
46}
47
48/// A fixed action identifier.
49fn action_id() -> ActionId {
50    "0191f0a0-0000-7000-8000-000000000004"
51        .parse()
52        .expect("a fixed version 7 identifier")
53}
54
55/// A fixed intervention identifier.
56fn intervention_id() -> InterventionId {
57    "0191f0a0-0000-7000-8000-000000000005"
58        .parse()
59        .expect("a fixed version 7 identifier")
60}
61
62/// A fixed spool identifier.
63fn spool_id() -> SpoolId {
64    "0191f0a0-0000-7000-8000-000000000006"
65        .parse()
66        .expect("a fixed version 7 identifier")
67}
68
69/// A second fixed spool identifier, for the spool a swap replaced.
70fn replaced_spool_id() -> SpoolId {
71    "0191f0a0-0000-7000-8000-000000000007"
72        .parse()
73        .expect("a fixed version 7 identifier")
74}
75
76impl Sample for SpoolId {
77    fn sample_full() -> Self {
78        spool_id()
79    }
80}
81
82impl Sample for ActionId {
83    fn sample_full() -> Self {
84        action_id()
85    }
86}
87
88impl Sample for InterventionId {
89    fn sample_full() -> Self {
90        intervention_id()
91    }
92}
93
94impl Sample for ManifestNarrowing {
95    fn sample_full() -> Self {
96        Self {
97            adjustable: Adjustable::Feedrate,
98            requested: Range::new(0.2, 4.0),
99            applied: Range::new(0.5, 1.5),
100        }
101    }
102}
103
104impl Sample for PrintRecord {
105    fn sample_full() -> Self {
106        Self {
107            id: PrintId::sample_full(),
108            provider_print_id: Some(4211),
109            file_name: Some("benchy.gcode".to_owned()),
110            state: PrinterState::Printing,
111            opened_at: Timestamp::sample_full(),
112            job_started_at: Some(Timestamp::sample_full()),
113            job_print_time_s: Some(3024),
114            ended_at: Some(later_instant()),
115            end_reason: Some("finished".to_owned()),
116            narrowings: vec![ManifestNarrowing::sample_full()],
117        }
118    }
119
120    fn sample_minimal() -> Self {
121        Self {
122            id: PrintId::sample_full(),
123            provider_print_id: None,
124            file_name: None,
125            state: PrinterState::Printing,
126            opened_at: Timestamp::sample_full(),
127            job_started_at: None,
128            job_print_time_s: None,
129            ended_at: None,
130            end_reason: None,
131            narrowings: vec![],
132        }
133    }
134}
135
136impl Sample for ImageRecord {
137    fn sample_full() -> Self {
138        Self {
139            id: ImageId::sample_full(),
140            print_id: PrintId::sample_full(),
141            event_id: EventId::sample_full(),
142            source_url: Some("https://detector.example/snapshots/1.jpg".to_owned()),
143            fetched_at: Timestamp::sample_full(),
144            content_type: "image/jpeg".to_owned(),
145            byte_len: 51_200,
146            sha256: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".to_owned(),
147            relative_path: "images/0191f0a0/1.jpg".to_owned(),
148        }
149    }
150
151    fn sample_minimal() -> Self {
152        Self {
153            source_url: None,
154            ..Self::sample_full()
155        }
156    }
157}
158
159impl Sample for Actor {
160    fn sample_full() -> Self {
161        Self::Agent {
162            session_name: "print-0191f0a0".to_owned(),
163        }
164    }
165}
166
167impl Sample for ActorClass {
168    fn sample_full() -> Self {
169        Self::Agent
170    }
171}
172
173impl Sample for ActionKind {
174    fn sample_full() -> Self {
175        Self::SetFeedrateFactor
176    }
177}
178
179impl Sample for AcknowledgementDisposition {
180    fn sample_full() -> Self {
181        Self::Watch
182    }
183}
184
185impl Sample for ExecutionOutcome {
186    fn sample_full() -> Self {
187        Self::Failed {
188            reason: "the printer refused the command".to_owned(),
189        }
190    }
191}
192
193impl Sample for PrintAction {
194    fn sample_full() -> Self {
195        Self::SetFeedrateFactor {
196            factor: 0.8,
197            duration_s: Some(600),
198            reason: "the first layer is going down fast".to_owned(),
199            actor: Actor::sample_full(),
200        }
201    }
202
203    fn sample_minimal() -> Self {
204        Self::SetFeedrateFactor {
205            factor: 0.8,
206            duration_s: None,
207            reason: "the first layer is going down fast".to_owned(),
208            actor: Actor::sample_full(),
209        }
210    }
211
212    fn sample_alternates() -> Vec<Self> {
213        let reason = || "the print needs it".to_owned();
214        vec![
215            Self::Pause {
216                reason: reason(),
217                actor: Actor::sample_full(),
218            },
219            Self::Resume {
220                reason: reason(),
221                actor: Actor::sample_full(),
222            },
223            Self::Cancel {
224                reason: reason(),
225                actor: Actor::sample_full(),
226            },
227            Self::StartPrint {
228                file_name: FileName::sample_full(),
229                manifest: JobManifest::sample_full(),
230                override_filament_check: true,
231                reason: reason(),
232                actor: Actor::sample_full(),
233            },
234            Self::SetFlowrateFactor {
235                factor: 1.05,
236                duration_s: Some(300),
237                reason: reason(),
238                actor: Actor::sample_full(),
239            },
240            Self::SetToolTargetC {
241                tool: 0,
242                target_c: 215.0,
243                duration_s: Some(300),
244                reason: reason(),
245                actor: Actor::sample_full(),
246            },
247            Self::SetBedTargetC {
248                target_c: 60.0,
249                duration_s: Some(300),
250                reason: reason(),
251                actor: Actor::sample_full(),
252            },
253            Self::SetFanPercent {
254                percent: 80.0,
255                duration_s: Some(300),
256                reason: reason(),
257                actor: Actor::sample_full(),
258            },
259            Self::AcknowledgeFailure {
260                event_id: EventId::sample_full(),
261                disposition: AcknowledgementDisposition::Watch,
262                reason: reason(),
263                actor: Actor::Operator,
264            },
265            Self::ClosePrint {
266                outcome: PrintOutcome::Interrupted,
267                reason: "the printer was switched off mid-print".to_owned(),
268                actor: Actor::Operator,
269            },
270        ]
271    }
272}
273
274impl Sample for ActionRequest {
275    fn sample_full() -> Self {
276        Self {
277            action: PrintAction::sample_full(),
278            actor: Actor::sample_full(),
279            requested_at: Timestamp::sample_full(),
280        }
281    }
282
283    fn sample_minimal() -> Self {
284        Self {
285            action: PrintAction::sample_minimal(),
286            ..Self::sample_full()
287        }
288    }
289}
290
291impl Sample for ActionRecord {
292    fn sample_full() -> Self {
293        Self {
294            id: action_id(),
295            print_id: PrintId::sample_full(),
296            request: ActionRequest::sample_full(),
297            decision: PolicyDecision::Accepted,
298            executed_at: Some(later_instant()),
299            outcome: Some(ExecutionOutcome::Succeeded),
300        }
301    }
302
303    fn sample_minimal() -> Self {
304        Self {
305            request: ActionRequest::sample_minimal(),
306            executed_at: None,
307            outcome: None,
308            ..Self::sample_full()
309        }
310    }
311}
312
313/// The allowed map both the manifest and the envelope carry.
314fn allowed_ranges() -> BTreeMap<Adjustable, Range> {
315    BTreeMap::from([
316        (Adjustable::Feedrate, Range::new(0.5, 1.5)),
317        (Adjustable::ToolTarget { tool: 0 }, Range::new(190.0, 230.0)),
318    ])
319}
320
321impl Sample for JobManifest {
322    fn sample_full() -> Self {
323        Self {
324            file_name: "benchy.gcode".to_owned(),
325            material: "PLA".to_owned(),
326            nozzle_diameter_mm: 0.4,
327            slicer_profile: "0.2mm standard".to_owned(),
328            allowed: allowed_ranges(),
329            metadata: BTreeMap::from([("layer_height_mm".to_owned(), "0.2".to_owned())]),
330        }
331    }
332}
333
334impl Sample for SafetyEnvelope {
335    fn sample_full() -> Self {
336        Self {
337            allowed: allowed_ranges(),
338            actions: BTreeMap::from([(
339                ActorClass::Agent,
340                vec![ActionKind::Pause, ActionKind::SetFeedrateFactor],
341            )]),
342            agent_min_interval_s: 60,
343        }
344    }
345}
346
347impl Sample for EffectiveBounds {
348    fn sample_full() -> Self {
349        Self {
350            allowed: allowed_ranges(),
351        }
352    }
353}
354
355impl Sample for RejectionReason {
356    fn sample_full() -> Self {
357        Self::OutOfBounds {
358            adjustable: Adjustable::Feedrate,
359            requested: 4.0,
360            allowed: Range::new(0.5, 1.5),
361        }
362    }
363
364    fn sample_alternates() -> Vec<Self> {
365        vec![
366            Self::InsufficientFilament {
367                tool: 0,
368                spool_id: spool_id(),
369                spool_name: "Galaxy black".to_owned(),
370                required_g: 120.0,
371                buffer_g: 12.0,
372                remaining_g: 80.0,
373                unverified: Some(UnverifiedReason::sample_full()),
374            },
375            Self::InsufficientFilament {
376                tool: 0,
377                spool_id: spool_id(),
378                spool_name: "Galaxy black".to_owned(),
379                required_g: 120.0,
380                buffer_g: 12.0,
381                remaining_g: 80.0,
382                unverified: None,
383            },
384            Self::UnverifiedSpool {
385                tool: 0,
386                spool_id: spool_id(),
387                spool_name: "Galaxy black".to_owned(),
388                reason: UnverifiedReason::sample_full(),
389            },
390            Self::AnalysisUnavailable {
391                file_name: "benchy.gcode".to_owned(),
392                waited_s: 300,
393            },
394            Self::SpoolRefused {
395                cause: SpoolRefusalCause::sample_full(),
396                message: "spool Galaxy black is retired, so it takes no command".to_owned(),
397            },
398            Self::PrintAlreadyEnded,
399            Self::PrintStillActive {
400                state: PrinterState::Paused,
401            },
402            Self::InterventionStillActive {
403                intervention_id: InterventionId::sample_full(),
404            },
405        ]
406    }
407}
408
409impl Sample for SpoolField {
410    fn sample_full() -> Self {
411        Self::GrossG
412    }
413}
414
415impl Sample for SpoolRefusalCause {
416    fn sample_full() -> Self {
417        Self::RetiredSpool {
418            spool_id: spool_id(),
419        }
420    }
421
422    fn sample_minimal() -> Self {
423        Self::DensityRequired {
424            spool_id: None,
425            material: "PEEK".to_owned(),
426        }
427    }
428
429    fn sample_alternates() -> Vec<Self> {
430        vec![
431            Self::UnknownSpool {
432                spool_id: replaced_spool_id(),
433            },
434            Self::NothingToConfirm { tool: 0 },
435            Self::InvalidAdjustmentFigure {
436                field: SpoolField::GrossG,
437                value: -5.0,
438            },
439            Self::TareRequired {
440                spool_id: spool_id(),
441            },
442            Self::DensityRequired {
443                spool_id: Some(spool_id()),
444                material: "PEEK".to_owned(),
445            },
446            Self::MissingField {
447                field: SpoolField::Name,
448            },
449            Self::ConflictingFields {
450                fields: vec![SpoolField::RemainingG, SpoolField::GrossG],
451            },
452            Self::UnknownTool { tool: -1 },
453            Self::NotLoaded {
454                spool_id: spool_id(),
455            },
456            Self::LedgerRefused,
457        ]
458    }
459}
460
461impl Sample for PolicyDecision {
462    fn sample_full() -> Self {
463        Self::Rejected(RejectionReason::sample_full())
464    }
465}
466
467impl Sample for InterventionOutcome {
468    fn sample_full() -> Self {
469        Self::Superseded {
470            by: intervention_id(),
471        }
472    }
473}
474
475impl Sample for Intervention {
476    fn sample_full() -> Self {
477        Self {
478            id: intervention_id(),
479            print_id: PrintId::sample_full(),
480            action_id: action_id(),
481            adjustable: Adjustable::Feedrate,
482            prior_value: Some(1.0),
483            applied_value: 0.8,
484            applied_at: Timestamp::sample_full(),
485            expires_at: later_instant(),
486            restored_at: Some(later_instant()),
487            outcome: InterventionOutcome::Restored,
488        }
489    }
490
491    fn sample_minimal() -> Self {
492        Self {
493            prior_value: None,
494            restored_at: None,
495            outcome: InterventionOutcome::StillActive,
496            ..Self::sample_full()
497        }
498    }
499}
500
501impl Sample for UnverifiedReason {
502    fn sample_full() -> Self {
503        Self::UnchargedPrint {
504            print_id: PrintId::sample_full(),
505        }
506    }
507
508    fn sample_alternates() -> Vec<Self> {
509        vec![
510            Self::UnaccountedPrint {
511                file_name: "benchy.gcode".to_owned(),
512                printed_at: Timestamp::sample_full(),
513            },
514            Self::FilamentChangeUnconfirmed {
515                print_id: PrintId::sample_full(),
516            },
517            Self::FilamentChangeUnconfirmedPosition {
518                print_id: PrintId::sample_full(),
519            },
520            Self::TallyReset {
521                file_name: "benchy.gcode".to_owned(),
522                origin: "local".to_owned(),
523            },
524        ]
525    }
526}
527
528impl Sample for UnverifiedMark {
529    fn sample_full() -> Self {
530        Self {
531            reason: UnverifiedReason::sample_full(),
532            since: Timestamp::sample_full(),
533        }
534    }
535}
536
537impl Sample for UnverifiedMarks {
538    fn sample_full() -> Self {
539        Self::new(vec![
540            UnverifiedMark::sample_full(),
541            UnverifiedMark {
542                reason: UnverifiedReason::FilamentChangeUnconfirmed {
543                    print_id: PrintId::sample_full(),
544                },
545                since: later_instant(),
546            },
547        ])
548        .expect("two marks")
549    }
550}
551
552impl Sample for SpoolTrust {
553    fn sample_full() -> Self {
554        Self::Unverified {
555            marks: UnverifiedMarks::sample_full(),
556        }
557    }
558
559    fn sample_alternates() -> Vec<Self> {
560        vec![Self::Verified]
561    }
562}
563
564impl Sample for SpoolRecord {
565    fn sample_full() -> Self {
566        Self {
567            id: spool_id(),
568            name: "Galaxy black".to_owned(),
569            material: "PLA".to_owned(),
570            color: Some("black".to_owned()),
571            diameter_mm: 1.75,
572            density_g_cm3: 1.24,
573            initial_g: 1_000.0,
574            remaining_g: 742.5,
575            tare_g: Some(250.0),
576            lifecycle: SpoolLifecycle::sample_full(),
577            trust: SpoolTrust::sample_full(),
578            registered_at: Timestamp::sample_full(),
579            updated_at: later_instant(),
580        }
581    }
582
583    fn sample_minimal() -> Self {
584        Self {
585            color: None,
586            tare_g: None,
587            lifecycle: SpoolLifecycle::Shelved,
588            trust: SpoolTrust::Verified,
589            ..Self::sample_full()
590        }
591    }
592
593    fn sample_alternates() -> Vec<Self> {
594        vec![Self {
595            remaining_g: 12.5,
596            lifecycle: SpoolLifecycle::Retired {
597                at: later_instant(),
598            },
599            ..Self::sample_full()
600        }]
601    }
602}
603
604impl Sample for SpoolLifecycle {
605    fn sample_full() -> Self {
606        Self::Loaded { tool: 0 }
607    }
608
609    fn sample_alternates() -> Vec<Self> {
610        vec![
611            Self::Shelved,
612            Self::Retired {
613                at: later_instant(),
614            },
615        ]
616    }
617}
618
619impl Sample for ClearedMark {
620    fn sample_full() -> Self {
621        Self {
622            spool_id: replaced_spool_id(),
623            reason: UnverifiedReason::FilamentChangeUnconfirmed {
624                print_id: PrintId::sample_full(),
625            },
626        }
627    }
628}
629
630impl Sample for LoadedSpool {
631    fn sample_full() -> Self {
632        Self {
633            tool: 0,
634            spool_id: spool_id(),
635        }
636    }
637}
638
639impl Sample for PrintOutcome {
640    fn sample_full() -> Self {
641        Self::Completed
642    }
643
644    fn sample_alternates() -> Vec<Self> {
645        vec![Self::Cancelled, Self::Failed, Self::Interrupted]
646    }
647}
648
649impl Sample for ChargeMethod {
650    fn sample_full() -> Self {
651        Self::GcodeExtrusion
652    }
653}
654
655impl Sample for ChargeKey {
656    fn sample_full() -> Self {
657        Self::Print {
658            print_id: PrintId::sample_full(),
659            tool: 0,
660            segment: 1,
661        }
662    }
663
664    fn sample_alternates() -> Vec<Self> {
665        vec![Self::Unobserved {
666            origin: "local".to_owned(),
667            file_name: "benchy.gcode".to_owned(),
668            generation: 2,
669            print_number: 7,
670            tool: 0,
671        }]
672    }
673}
674
675impl Sample for FilePosition {
676    fn sample_full() -> Self {
677        Self {
678            bytes: 1_761_607,
679            size_bytes: Some(4_194_304),
680            observed_at: Timestamp::sample_full(),
681        }
682    }
683
684    fn sample_minimal() -> Self {
685        Self {
686            size_bytes: None,
687            ..Self::sample_full()
688        }
689    }
690}
691
692impl Sample for PrintSegmentKey {
693    fn sample_full() -> Self {
694        Self {
695            print_id: PrintId::sample_full(),
696            tool: 0,
697            segment: 1,
698        }
699    }
700}
701
702impl Sample for ChargedFilament {
703    fn sample_full() -> Self {
704        Self {
705            spool_id: spool_id(),
706            grams: 2.98,
707            diameter_mm: 1.75,
708            density_g_cm3: 1.24,
709            remaining_before_g: 745.48,
710            remaining_after_g: 742.5,
711        }
712    }
713}
714
715impl Sample for PendingCharge {
716    fn sample_full() -> Self {
717        Self {
718            charge_key: PrintSegmentKey::sample_full(),
719            length_mm: 1_204.5,
720            method: ChargeMethod::GcodeExtrusion,
721            analysed_length_mm: Some(5_120.0),
722            position: Some(FilePosition::sample_full()),
723            note: Some("fed after the filament change at layer 12".to_owned()),
724            pended_at: later_instant(),
725        }
726    }
727
728    fn sample_minimal() -> Self {
729        Self {
730            method: ChargeMethod::FileFraction,
731            analysed_length_mm: None,
732            position: None,
733            note: None,
734            ..Self::sample_full()
735        }
736    }
737}
738
739impl Sample for PendingTaken {
740    fn sample_full() -> Self {
741        Self {
742            charge_key: ChargeKey::sample_full(),
743            print_id: PrintId::sample_full(),
744        }
745    }
746}
747
748impl Sample for PreflightVerdict {
749    fn sample_full() -> Self {
750        Self::Insufficient
751    }
752}
753
754impl Sample for PreflightSpool {
755    fn sample_full() -> Self {
756        Self {
757            id: spool_id(),
758            name: "Galaxy black".to_owned(),
759        }
760    }
761}
762
763impl Sample for PreflightNeed {
764    fn sample_full() -> Self {
765        Self {
766            required_g: 120.0,
767            buffer_g: 12.0,
768        }
769    }
770}
771
772impl Sample for ShortSpool {
773    fn sample_full() -> Self {
774        Self {
775            spool: PreflightSpool::sample_full(),
776            remaining_g: 80.0,
777            need: PreflightNeed::sample_full(),
778            marks: vec![UnverifiedMark::sample_full()],
779        }
780    }
781
782    fn sample_minimal() -> Self {
783        Self {
784            marks: Vec::new(),
785            ..Self::sample_full()
786        }
787    }
788}
789
790impl Sample for DoubtedSpool {
791    fn sample_full() -> Self {
792        Self {
793            spool: PreflightSpool::sample_full(),
794            remaining_g: 742.5,
795            need: Some(PreflightNeed::sample_full()),
796            marks: UnverifiedMarks::sample_full(),
797        }
798    }
799
800    fn sample_minimal() -> Self {
801        Self {
802            need: None,
803            ..Self::sample_full()
804        }
805    }
806}
807
808impl Sample for UnanalysedSpool {
809    fn sample_full() -> Self {
810        Self {
811            spool: PreflightSpool::sample_full(),
812            remaining_g: 742.5,
813        }
814    }
815}
816
817impl Sample for PreflightObjection {
818    fn sample_full() -> Self {
819        Self::Insufficient(ShortSpool::sample_full())
820    }
821
822    fn sample_minimal() -> Self {
823        Self::NoAnalysis(UnanalysedSpool::sample_full())
824    }
825
826    fn sample_alternates() -> Vec<Self> {
827        vec![
828            Self::Insufficient(ShortSpool::sample_minimal()),
829            Self::UnverifiedSpool(DoubtedSpool::sample_full()),
830        ]
831    }
832}
833
834impl Sample for PreflightToolResult {
835    fn sample_full() -> Self {
836        Self::Insufficient(ShortSpool::sample_full())
837    }
838
839    fn sample_minimal() -> Self {
840        Self::Unchecked
841    }
842
843    fn sample_alternates() -> Vec<Self> {
844        vec![
845            Self::Passed {
846                spool: PreflightSpool::sample_full(),
847                remaining_g: 742.5,
848                need: PreflightNeed::sample_full(),
849            },
850            Self::UnverifiedSpool(DoubtedSpool::sample_minimal()),
851            Self::NoAnalysis(UnanalysedSpool::sample_full()),
852            Self::Overridden {
853                objection: PreflightObjection::sample_full(),
854            },
855            Self::Warned {
856                objection: PreflightObjection::NoAnalysis(UnanalysedSpool::sample_full()),
857            },
858        ]
859    }
860}
861
862impl Sample for PreflightTool {
863    fn sample_full() -> Self {
864        Self {
865            tool: 0,
866            result: PreflightToolResult::sample_full(),
867        }
868    }
869
870    fn sample_minimal() -> Self {
871        Self {
872            tool: 1,
873            result: PreflightToolResult::Unchecked,
874        }
875    }
876}
877
878impl Sample for Preflight {
879    fn sample_full() -> Self {
880        Self {
881            file_name: "benchy.gcode".to_owned(),
882            tools: vec![
883                PreflightTool::sample_full(),
884                PreflightTool::sample_minimal(),
885            ],
886            verdict: PreflightVerdict::Insufficient,
887            checked_at: Timestamp::sample_full(),
888        }
889    }
890}
891
892impl Sample for SpoolCommand {
893    fn sample_full() -> Self {
894        Self::RegisterSpool {
895            name: "Galaxy black".to_owned(),
896            material: "PLA".to_owned(),
897            color: Some("black".to_owned()),
898            diameter_mm: Some(1.75),
899            density_g_cm3: Some(1.24),
900            initial_g: 1_000.0,
901            remaining_g: Some(742.5),
902            tare_g: Some(250.0),
903            reason: "a new spool went on the shelf".to_owned(),
904            actor: Actor::Operator,
905        }
906    }
907
908    fn sample_minimal() -> Self {
909        Self::RegisterSpool {
910            name: "Galaxy black".to_owned(),
911            material: "PLA".to_owned(),
912            color: None,
913            diameter_mm: None,
914            density_g_cm3: None,
915            initial_g: 1_000.0,
916            remaining_g: None,
917            tare_g: None,
918            reason: "a new spool went on the shelf".to_owned(),
919            actor: Actor::Operator,
920        }
921    }
922
923    fn sample_alternates() -> Vec<Self> {
924        let reason = || "the spool on the shelf changed".to_owned();
925        vec![
926            Self::LoadSpool {
927                spool_id: spool_id(),
928                tool: 0,
929                reason: reason(),
930                actor: Actor::Operator,
931            },
932            Self::UnloadSpool {
933                spool_id: spool_id(),
934                reason: reason(),
935                actor: Actor::Operator,
936            },
937            Self::AdjustSpool {
938                spool_id: spool_id(),
939                remaining_g: Some(700.0),
940                gross_g: None,
941                reason: reason(),
942                actor: Actor::Operator,
943            },
944            Self::AdjustSpool {
945                spool_id: spool_id(),
946                remaining_g: None,
947                gross_g: Some(950.0),
948                reason: reason(),
949                actor: Actor::sample_full(),
950            },
951            Self::RetireSpool {
952                spool_id: spool_id(),
953                reason: reason(),
954                actor: Actor::Operator,
955            },
956        ]
957    }
958}