1use crate::gcode_index::PlannedChange;
26use crate::records::{
27 AcknowledgementDisposition, ActionId, Actor, CAMERA_CHECKED_KIND, CameraCheckId, ChargeKey,
28 ChargeMethod, ChargedFilament, ClearedMark, FilePosition, InterventionId, InterventionOutcome,
29 LoadedSpool, PendingCharge, PendingTaken, PolicyDecision, Preflight, PrintAction, PrintOutcome,
30 RecoveryAction, RecoveryRejection, SpoolCommand, SpoolId, SpoolRecord, UnverifiedReason,
31};
32use printobserver_printer_api::{Adjustable, JobSnapshot, PrinterSnapshot, PrinterState};
33use printobserver_supervisor_api::{AgentAssessment, ImageFallback, ImageKind};
34use printobserver_types::contract::Sample;
35use printobserver_types::schemars::JsonSchema;
36use printobserver_types::serde::{Deserialize, Serialize};
37use printobserver_types::{
38 EventId, EventKind, EventPayload, EventSource, FileName, PrintId, Timestamp,
39};
40
41pub const SYSTEM_SOURCE: &str = "system";
43
44pub const OPERATOR_SOURCE: &str = "operator";
46
47pub const AGENT_SOURCE: &str = "agent";
49
50#[must_use]
52pub fn system_source() -> EventSource {
53 EventSource::new(SYSTEM_SOURCE)
54}
55
56#[must_use]
58pub fn operator_source() -> EventSource {
59 EventSource::new(OPERATOR_SOURCE)
60}
61
62#[must_use]
64pub fn agent_source() -> EventSource {
65 EventSource::new(AGENT_SOURCE)
66}
67
68#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
70#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
71#[schemars(crate = "printobserver_types::schemars")]
72pub struct ActionRequestedPayload {
73 pub action_id: ActionId,
75 pub action: PrintAction,
77 pub actor: Actor,
79}
80
81impl EventPayload for ActionRequestedPayload {
82 const KIND: &'static str = "action_requested";
83}
84
85impl Sample for ActionRequestedPayload {
86 fn sample_full() -> Self {
87 Self {
88 action_id: ActionId::sample_full(),
89 action: PrintAction::sample_full(),
90 actor: Actor::sample_full(),
91 }
92 }
93
94 fn sample_minimal() -> Self {
95 Self {
96 action: PrintAction::sample_minimal(),
97 ..Self::sample_full()
98 }
99 }
100}
101
102#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
104#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
105#[schemars(crate = "printobserver_types::schemars")]
106pub struct ActionExecutedPayload {
107 pub action_id: ActionId,
109 #[serde(default, skip_serializing_if = "Option::is_none")]
111 pub intervention_id: Option<InterventionId>,
112 #[serde(default, skip_serializing_if = "Option::is_none")]
116 pub file_position_bytes: Option<i64>,
117}
118
119impl EventPayload for ActionExecutedPayload {
120 const KIND: &'static str = "action_executed";
121}
122
123impl Sample for ActionExecutedPayload {
124 fn sample_full() -> Self {
125 Self {
126 action_id: ActionId::sample_full(),
127 intervention_id: Some(InterventionId::sample_full()),
128 file_position_bytes: Some(4_096),
129 }
130 }
131
132 fn sample_minimal() -> Self {
133 Self {
134 action_id: ActionId::sample_full(),
135 intervention_id: None,
136 file_position_bytes: None,
137 }
138 }
139}
140
141#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
143#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
144#[schemars(crate = "printobserver_types::schemars")]
145pub struct ActionRejectedPayload {
146 pub action_id: ActionId,
148 pub decision: PolicyDecision,
150}
151
152impl EventPayload for ActionRejectedPayload {
153 const KIND: &'static str = "action_rejected";
154}
155
156impl Sample for ActionRejectedPayload {
157 fn sample_full() -> Self {
158 Self {
159 action_id: ActionId::sample_full(),
160 decision: PolicyDecision::sample_full(),
161 }
162 }
163}
164
165#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
167#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
168#[schemars(crate = "printobserver_types::schemars")]
169pub struct InterventionExpiredPayload {
170 pub intervention_id: InterventionId,
172 pub adjustable: Adjustable,
174 pub outcome: InterventionOutcome,
176}
177
178impl EventPayload for InterventionExpiredPayload {
179 const KIND: &'static str = "intervention_expired";
180}
181
182impl Sample for InterventionExpiredPayload {
183 fn sample_full() -> Self {
184 Self {
185 intervention_id: InterventionId::sample_full(),
186 adjustable: Adjustable::Feedrate,
187 outcome: InterventionOutcome::Restored,
188 }
189 }
190}
191
192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
194#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
195#[schemars(crate = "printobserver_types::schemars")]
196pub struct AgentAssessmentPayload {
197 pub session_name: String,
199 pub assessment: AgentAssessment,
201 #[serde(default, skip_serializing_if = "Option::is_none")]
209 pub check_image: Option<TurnCheckImage>,
210}
211
212impl EventPayload for AgentAssessmentPayload {
213 const KIND: &'static str = "agent_assessment";
214}
215
216impl Sample for AgentAssessmentPayload {
217 fn sample_full() -> Self {
218 Self {
219 session_name: "print-0191f0a0".to_owned(),
220 assessment: AgentAssessment::sample_full(),
221 check_image: Some(TurnCheckImage::sample_full()),
222 }
223 }
224
225 fn sample_minimal() -> Self {
226 Self {
227 session_name: "print-0191f0a0".to_owned(),
228 assessment: AgentAssessment::sample_full(),
229 check_image: None,
230 }
231 }
232}
233
234#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
237#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
238#[schemars(crate = "printobserver_types::schemars")]
239pub struct TurnCheckImage {
240 pub event_id: EventId,
243 pub path: std::path::PathBuf,
245 #[serde(default, skip_serializing_if = "Option::is_none")]
248 pub note: Option<String>,
249 #[serde(default, skip_serializing_if = "Option::is_none")]
251 pub kind: Option<ImageKind>,
252 #[serde(default, skip_serializing_if = "Option::is_none")]
255 pub fallback: Option<ImageFallback>,
256 #[serde(default, skip_serializing_if = "Option::is_none")]
258 pub frame_captured_at: Option<Timestamp>,
259}
260
261impl Sample for TurnCheckImage {
262 fn sample_full() -> Self {
263 Self {
264 event_id: EventId::sample_full(),
265 path: std::path::PathBuf::from(
266 "/var/lib/printobserver/check-images/frame-composite-after-first.jpg",
267 ),
268 note: Some(
269 "the whole camera frame, scaled to fit 1280x720 and uncropped: the printer \
270 reports the print paused"
271 .to_owned(),
272 ),
273 kind: Some(ImageKind::WholeFrame),
274 fallback: Some(ImageFallback::sample_minimal()),
275 frame_captured_at: Some(Timestamp::sample_full()),
276 }
277 }
278
279 fn sample_minimal() -> Self {
280 Self {
281 event_id: EventId::sample_full(),
282 path: std::path::PathBuf::from("/var/lib/printobserver/images/frame.jpg"),
283 note: None,
284 kind: None,
285 fallback: None,
286 frame_captured_at: None,
287 }
288 }
289}
290
291#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
299#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
300#[schemars(crate = "printobserver_types::schemars")]
301pub struct AgentStopUnactedPayload {
302 pub event_id: EventId,
304 pub session_name: String,
306 pub summary: String,
308}
309
310impl EventPayload for AgentStopUnactedPayload {
311 const KIND: &'static str = "agent_stop_unacted";
312}
313
314impl Sample for AgentStopUnactedPayload {
315 fn sample_full() -> Self {
316 Self {
317 event_id: EventId::sample_full(),
318 session_name: "print-0191f0a0".to_owned(),
319 summary: "The part has moved off its planned place.".to_owned(),
320 }
321 }
322}
323
324#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
326#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
327#[schemars(crate = "printobserver_types::schemars")]
328pub struct OperatorAcknowledgementPayload {
329 pub acknowledged_event_id: EventId,
331 pub disposition: AcknowledgementDisposition,
333}
334
335impl EventPayload for OperatorAcknowledgementPayload {
336 const KIND: &'static str = "operator_acknowledgement";
337}
338
339impl Sample for OperatorAcknowledgementPayload {
340 fn sample_full() -> Self {
341 Self {
342 acknowledged_event_id: EventId::sample_full(),
343 disposition: AcknowledgementDisposition::Watch,
344 }
345 }
346}
347
348#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
358#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
359#[schemars(crate = "printobserver_types::schemars")]
360pub struct CameraLookPayload {
361 pub waited_s: u32,
364 #[serde(default)]
367 pub delivered: Vec<EventId>,
368 #[serde(default, skip_serializing_if = "Option::is_none")]
372 pub frame_captured_at: Option<Timestamp>,
373}
374
375impl EventPayload for CameraLookPayload {
376 const KIND: &'static str = "camera_look";
377}
378
379impl Sample for CameraLookPayload {
380 fn sample_full() -> Self {
381 Self {
382 waited_s: 60,
383 delivered: vec![EventId::sample_full()],
384 frame_captured_at: Some(Timestamp::sample_full()),
385 }
386 }
387
388 fn sample_minimal() -> Self {
389 Self {
390 waited_s: 0,
391 delivered: Vec::new(),
392 frame_captured_at: None,
393 }
394 }
395}
396
397#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
407#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
408#[schemars(crate = "printobserver_types::schemars")]
409pub struct PeriodicObservationPayload {
410 pub interval_s: u64,
412 #[serde(default, skip_serializing_if = "Option::is_none")]
415 pub printer: Option<PrinterSnapshot>,
416 #[serde(default, skip_serializing_if = "Option::is_none")]
419 pub job: Option<JobSnapshot>,
420 #[serde(default, skip_serializing_if = "Option::is_none")]
423 pub frame_captured_at: Option<Timestamp>,
424}
425
426impl EventPayload for PeriodicObservationPayload {
427 const KIND: &'static str = "periodic_observation";
428}
429
430impl Sample for PeriodicObservationPayload {
431 fn sample_full() -> Self {
432 Self {
433 interval_s: 120,
434 printer: Some(PrinterSnapshot::sample_full()),
435 job: Some(JobSnapshot::sample_full()),
436 frame_captured_at: Some(Timestamp::sample_full()),
437 }
438 }
439
440 fn sample_minimal() -> Self {
441 Self {
442 interval_s: 120,
443 printer: None,
444 job: None,
445 frame_captured_at: None,
446 }
447 }
448}
449
450#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
460#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
461#[schemars(crate = "printobserver_types::schemars")]
462pub struct CameraRetryPayload {
463 pub attempt: u32,
465 pub attempts: u32,
467 pub status: u16,
469 pub excerpt: String,
471 pub backoff_ms: u64,
473}
474
475impl EventPayload for CameraRetryPayload {
476 const KIND: &'static str = "camera_retry";
477}
478
479impl Sample for CameraRetryPayload {
480 fn sample_full() -> Self {
481 Self {
482 attempt: 1,
483 attempts: 4,
484 status: 500,
485 excerpt: "exit status 69".to_owned(),
486 backoff_ms: 500,
487 }
488 }
489
490 fn sample_minimal() -> Self {
491 Self {
492 excerpt: String::new(),
493 ..Self::sample_full()
494 }
495 }
496}
497
498#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
500#[serde(
501 crate = "printobserver_types::serde",
502 rename_all = "snake_case",
503 deny_unknown_fields
504)]
505#[schemars(crate = "printobserver_types::schemars")]
506pub enum FrameCause {
507 Blank,
510 Undecodable,
512}
513
514impl Sample for FrameCause {
515 fn sample_full() -> Self {
516 Self::Blank
517 }
518
519 fn sample_alternates() -> Vec<Self> {
520 vec![Self::Undecodable]
521 }
522}
523
524#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
530#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
531#[schemars(crate = "printobserver_types::schemars")]
532pub struct CameraDegradedPayload {
533 pub attempts: u32,
535 pub cause: FrameCause,
537 pub detail: String,
539}
540
541impl EventPayload for CameraDegradedPayload {
542 const KIND: &'static str = "camera_degraded";
543}
544
545impl Sample for CameraDegradedPayload {
546 fn sample_full() -> Self {
547 Self {
548 attempts: 3,
549 cause: FrameCause::Blank,
550 detail: "every frame was near-uniform grey (grey-level spread 2.1 below 36.5)"
551 .to_owned(),
552 }
553 }
554
555 fn sample_alternates() -> Vec<Self> {
556 vec![Self {
557 cause: FrameCause::Undecodable,
558 detail: "every frame failed a strict decode: the image ends early".to_owned(),
559 ..Self::sample_full()
560 }]
561 }
562}
563
564#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
570#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
571#[schemars(crate = "printobserver_types::schemars")]
572pub struct GcodeIndexedPayload {
573 pub file_name: FileName,
575 pub bytes: u64,
577 pub layers: u64,
579}
580
581impl EventPayload for GcodeIndexedPayload {
582 const KIND: &'static str = "gcode_indexed";
583}
584
585impl Sample for GcodeIndexedPayload {
586 fn sample_full() -> Self {
587 Self {
588 file_name: FileName::sample_full(),
589 bytes: 440_608,
590 layers: 150,
591 }
592 }
593}
594
595#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
604#[serde(
605 crate = "printobserver_types::serde",
606 rename_all = "snake_case",
607 deny_unknown_fields
608)]
609#[schemars(crate = "printobserver_types::schemars")]
610pub enum PortFailureSite {
611 PrinterSnapshot,
613 PrinterJob,
615 ImageWrite,
617 SupervisionTurn,
619 CameraLook,
622 DetectorAcknowledgement,
624 DetectorHealthCheck,
627 DetectorScoringRead,
630}
631
632impl Sample for PortFailureSite {
633 fn sample_full() -> Self {
634 Self::PrinterSnapshot
635 }
636}
637
638#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
646#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
647#[schemars(crate = "printobserver_types::schemars")]
648pub struct PortFailurePayload {
649 pub event_id: EventId,
651 pub site: PortFailureSite,
653 pub detail: String,
655}
656
657impl EventPayload for PortFailurePayload {
658 const KIND: &'static str = "port_failure";
659}
660
661impl Sample for PortFailurePayload {
662 fn sample_full() -> Self {
663 Self {
664 event_id: EventId::sample_full(),
665 site: PortFailureSite::sample_full(),
666 detail: "the printer is unreachable: connection refused".to_owned(),
667 }
668 }
669}
670
671pub const TIMELINE_KINDS: [&str; 25] = [
677 PrintStartedPayload::KIND,
678 PrintEndedPayload::KIND,
679 FilamentConsumedPayload::KIND,
680 SpoolRegisteredPayload::KIND,
681 SpoolLoadedPayload::KIND,
682 SpoolUnloadedPayload::KIND,
683 SpoolAdjustedPayload::KIND,
684 SpoolRetiredPayload::KIND,
685 SpoolCommandRejectedPayload::KIND,
686 SpoolUnverifiedPayload::KIND,
687 FilamentChangeSignalledPayload::KIND,
688 UnaccountedPrintPayload::KIND,
689 PreflightCheckedPayload::KIND,
690 ChargePendedPayload::KIND,
691 PrintUntrackedPayload::KIND,
692 FileTallyRebaselinedPayload::KIND,
693 PrinterConnectionChangedPayload::KIND,
694 PrinterResetPayload::KIND,
695 UnattendedPrinterActivityPayload::KIND,
696 DetectorHealthChangedPayload::KIND,
697 RecoveryRequestedPayload::KIND,
698 RecoveryExecutedPayload::KIND,
699 RecoveryRejectedPayload::KIND,
700 BedClearAssertedPayload::KIND,
701 CAMERA_CHECKED_KIND,
702];
703
704fn sample_spool_id() -> SpoolId {
706 SpoolId::sample_full()
707}
708
709fn sample_reason() -> String {
711 "the spool on the shelf changed".to_owned()
712}
713
714#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
716#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
717#[schemars(crate = "printobserver_types::schemars")]
718pub struct PrintStartedPayload {
719 #[serde(default, skip_serializing_if = "Option::is_none")]
721 pub file_name: Option<String>,
722 #[serde(default, skip_serializing_if = "Option::is_none")]
725 pub started_by: Option<ActionId>,
726 pub loaded: Vec<LoadedSpool>,
728 #[serde(default, skip_serializing_if = "Option::is_none")]
730 pub preflight: Option<Preflight>,
731 #[serde(default, skip_serializing_if = "Option::is_none")]
734 pub camera_check: Option<CameraCheckId>,
735}
736
737impl EventPayload for PrintStartedPayload {
738 const KIND: &'static str = "print_started";
739}
740
741impl Sample for PrintStartedPayload {
742 fn sample_full() -> Self {
743 Self {
744 file_name: Some("benchy.gcode".to_owned()),
745 started_by: Some(ActionId::sample_full()),
746 loaded: vec![LoadedSpool::sample_full()],
747 preflight: Some(Preflight::sample_full()),
748 camera_check: Some(CameraCheckId::sample_full()),
749 }
750 }
751
752 fn sample_minimal() -> Self {
753 Self {
754 file_name: None,
755 started_by: None,
756 loaded: Vec::new(),
757 preflight: None,
758 camera_check: None,
759 }
760 }
761}
762
763#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
765#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
766#[schemars(crate = "printobserver_types::schemars")]
767pub struct PrintEndedPayload {
768 pub outcome: PrintOutcome,
770 pub state: PrinterState,
772 pub reason: String,
774 #[serde(default, skip_serializing_if = "Option::is_none")]
776 pub last_position: Option<FilePosition>,
777}
778
779impl EventPayload for PrintEndedPayload {
780 const KIND: &'static str = "print_ended";
781}
782
783impl Sample for PrintEndedPayload {
784 fn sample_full() -> Self {
785 Self {
786 outcome: PrintOutcome::Cancelled,
787 state: PrinterState::Cancelling,
788 reason: "the operator cancelled it".to_owned(),
789 last_position: Some(FilePosition::sample_full()),
790 }
791 }
792
793 fn sample_minimal() -> Self {
794 Self {
795 outcome: PrintOutcome::Completed,
796 state: PrinterState::Operational,
797 reason: "finished".to_owned(),
798 last_position: None,
799 }
800 }
801}
802
803#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
805#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
806#[schemars(crate = "printobserver_types::schemars")]
807pub struct FilamentConsumedPayload {
808 pub charge_key: ChargeKey,
810 pub tool: i64,
812 pub method: ChargeMethod,
814 pub length_mm: f64,
816 #[serde(default, skip_serializing_if = "Option::is_none")]
820 pub charged: Option<ChargedFilament>,
821 #[serde(default, skip_serializing_if = "Option::is_none")]
823 pub analysed_length_mm: Option<f64>,
824 #[serde(default, skip_serializing_if = "Option::is_none")]
826 pub position: Option<FilePosition>,
827 #[serde(default, skip_serializing_if = "Option::is_none")]
829 pub note: Option<String>,
830}
831
832impl EventPayload for FilamentConsumedPayload {
833 const KIND: &'static str = "filament_consumed";
834}
835
836impl Sample for FilamentConsumedPayload {
837 fn sample_full() -> Self {
838 Self {
839 charge_key: ChargeKey::sample_full(),
840 tool: 0,
841 method: ChargeMethod::GcodeExtrusion,
842 length_mm: 1_000.0,
843 charged: Some(ChargedFilament::sample_full()),
844 analysed_length_mm: Some(5_120.0),
845 position: Some(FilePosition::sample_full()),
846 note: Some("charged up to the filament change".to_owned()),
847 }
848 }
849
850 fn sample_minimal() -> Self {
851 Self {
852 charge_key: ChargeKey::sample_full(),
853 tool: 0,
854 method: ChargeMethod::SlicerEstimate,
855 length_mm: 5_120.0,
856 charged: None,
857 analysed_length_mm: None,
858 position: None,
859 note: None,
860 }
861 }
862}
863
864#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
866#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
867#[schemars(crate = "printobserver_types::schemars")]
868pub struct SpoolRegisteredPayload {
869 pub spool: SpoolRecord,
871 pub actor: Actor,
873 pub reason: String,
875}
876
877impl EventPayload for SpoolRegisteredPayload {
878 const KIND: &'static str = "spool_registered";
879}
880
881impl Sample for SpoolRegisteredPayload {
882 fn sample_full() -> Self {
883 Self {
884 spool: SpoolRecord::sample_full(),
885 actor: Actor::Operator,
886 reason: sample_reason(),
887 }
888 }
889
890 fn sample_minimal() -> Self {
891 Self {
892 spool: SpoolRecord::sample_minimal(),
893 ..Self::sample_full()
894 }
895 }
896}
897
898#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
900#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
901#[schemars(crate = "printobserver_types::schemars")]
902pub struct SpoolLoadedPayload {
903 pub spool_id: SpoolId,
905 pub tool: i64,
907 #[serde(default, skip_serializing_if = "Option::is_none")]
909 pub replaced: Option<SpoolId>,
910 #[serde(default, skip_serializing_if = "Vec::is_empty")]
913 pub took_pending: Vec<PendingTaken>,
914 #[serde(default, skip_serializing_if = "Vec::is_empty")]
916 pub cleared_marks: Vec<ClearedMark>,
917 pub actor: Actor,
919 pub reason: String,
921}
922
923impl EventPayload for SpoolLoadedPayload {
924 const KIND: &'static str = "spool_loaded";
925}
926
927impl Sample for SpoolLoadedPayload {
928 fn sample_full() -> Self {
929 Self {
930 spool_id: sample_spool_id(),
931 tool: 0,
932 replaced: Some(ClearedMark::sample_full().spool_id),
933 took_pending: vec![PendingTaken::sample_full()],
934 cleared_marks: vec![ClearedMark::sample_full()],
935 actor: Actor::Operator,
936 reason: sample_reason(),
937 }
938 }
939
940 fn sample_minimal() -> Self {
941 Self {
942 replaced: None,
943 took_pending: Vec::new(),
944 cleared_marks: Vec::new(),
945 ..Self::sample_full()
946 }
947 }
948}
949
950#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
952#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
953#[schemars(crate = "printobserver_types::schemars")]
954pub struct SpoolUnloadedPayload {
955 pub spool_id: SpoolId,
957 pub tool: i64,
959 pub actor: Actor,
961 pub reason: String,
963}
964
965impl EventPayload for SpoolUnloadedPayload {
966 const KIND: &'static str = "spool_unloaded";
967}
968
969impl Sample for SpoolUnloadedPayload {
970 fn sample_full() -> Self {
971 Self {
972 spool_id: sample_spool_id(),
973 tool: 0,
974 actor: Actor::Operator,
975 reason: sample_reason(),
976 }
977 }
978}
979
980#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
982#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
983#[schemars(crate = "printobserver_types::schemars")]
984pub struct SpoolAdjustedPayload {
985 pub spool_id: SpoolId,
987 pub remaining_before_g: f64,
989 pub remaining_after_g: f64,
991 #[serde(default, skip_serializing_if = "Option::is_none")]
994 pub gross_g: Option<f64>,
995 #[serde(default, skip_serializing_if = "Vec::is_empty")]
998 pub took_pending: Vec<PendingTaken>,
999 #[serde(default, skip_serializing_if = "Vec::is_empty")]
1001 pub cleared_marks: Vec<ClearedMark>,
1002 pub actor: Actor,
1004 pub reason: String,
1006}
1007
1008impl EventPayload for SpoolAdjustedPayload {
1009 const KIND: &'static str = "spool_adjusted";
1010}
1011
1012impl Sample for SpoolAdjustedPayload {
1013 fn sample_full() -> Self {
1014 Self {
1015 spool_id: sample_spool_id(),
1016 remaining_before_g: 742.5,
1017 remaining_after_g: 700.0,
1018 gross_g: Some(950.0),
1019 took_pending: vec![PendingTaken::sample_full()],
1020 cleared_marks: vec![ClearedMark {
1021 spool_id: sample_spool_id(),
1022 reason: UnverifiedReason::sample_full(),
1023 }],
1024 actor: Actor::Operator,
1025 reason: sample_reason(),
1026 }
1027 }
1028
1029 fn sample_minimal() -> Self {
1030 Self {
1031 gross_g: None,
1032 took_pending: Vec::new(),
1033 cleared_marks: Vec::new(),
1034 ..Self::sample_full()
1035 }
1036 }
1037}
1038
1039#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1041#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1042#[schemars(crate = "printobserver_types::schemars")]
1043pub struct SpoolRetiredPayload {
1044 pub spool_id: SpoolId,
1046 pub remaining_g: f64,
1048 pub actor: Actor,
1050 pub reason: String,
1052}
1053
1054impl EventPayload for SpoolRetiredPayload {
1055 const KIND: &'static str = "spool_retired";
1056}
1057
1058impl Sample for SpoolRetiredPayload {
1059 fn sample_full() -> Self {
1060 Self {
1061 spool_id: sample_spool_id(),
1062 remaining_g: 12.5,
1063 actor: Actor::Operator,
1064 reason: "the spool is empty".to_owned(),
1065 }
1066 }
1067}
1068
1069#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1071#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1072#[schemars(crate = "printobserver_types::schemars")]
1073pub struct SpoolCommandRejectedPayload {
1074 pub command: SpoolCommand,
1076 pub decision: PolicyDecision,
1078}
1079
1080impl EventPayload for SpoolCommandRejectedPayload {
1081 const KIND: &'static str = "spool_command_rejected";
1082}
1083
1084impl Sample for SpoolCommandRejectedPayload {
1085 fn sample_full() -> Self {
1086 Self {
1087 command: SpoolCommand::sample_full(),
1088 decision: PolicyDecision::Rejected(crate::records::RejectionReason::SpoolRefused {
1089 cause: crate::records::SpoolRefusalCause::DensityRequired {
1090 spool_id: None,
1091 material: "PEEK".to_owned(),
1092 },
1093 message: "PEEK has no known density, so the spool needs one".to_owned(),
1094 }),
1095 }
1096 }
1097
1098 fn sample_minimal() -> Self {
1099 Self {
1100 command: SpoolCommand::sample_minimal(),
1101 ..Self::sample_full()
1102 }
1103 }
1104}
1105
1106#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1108#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1109#[schemars(crate = "printobserver_types::schemars")]
1110pub struct SpoolUnverifiedPayload {
1111 pub spool_id: SpoolId,
1113 pub reason: UnverifiedReason,
1115}
1116
1117impl EventPayload for SpoolUnverifiedPayload {
1118 const KIND: &'static str = "spool_unverified";
1119}
1120
1121impl Sample for SpoolUnverifiedPayload {
1122 fn sample_full() -> Self {
1123 Self {
1124 spool_id: sample_spool_id(),
1125 reason: UnverifiedReason::sample_full(),
1126 }
1127 }
1128}
1129
1130#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1132#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1133#[schemars(crate = "printobserver_types::schemars")]
1134pub struct FilamentChangeSignalledPayload {
1135 #[serde(default, skip_serializing_if = "Option::is_none")]
1137 pub tool: Option<i64>,
1138 #[serde(default, skip_serializing_if = "Option::is_none")]
1140 pub spool_id: Option<SpoolId>,
1141 pub source_kind: EventKind,
1143 #[serde(default, skip_serializing_if = "Option::is_none")]
1146 pub position: Option<SignalPosition>,
1147 #[serde(default, skip_serializing_if = "Option::is_none")]
1151 pub planned_change: Option<u32>,
1152}
1153
1154#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1156#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1157#[schemars(crate = "printobserver_types::schemars")]
1158pub struct SignalPosition {
1159 pub position: FilePosition,
1161 pub freshness: PositionFreshness,
1164}
1165
1166#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1168#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1169#[schemars(crate = "printobserver_types::schemars")]
1170pub enum PositionFreshness {
1171 ReadAtSignal,
1173 LastRecorded,
1176}
1177
1178impl EventPayload for FilamentChangeSignalledPayload {
1179 const KIND: &'static str = "filament_change_signalled";
1180}
1181
1182impl Sample for FilamentChangeSignalledPayload {
1183 fn sample_full() -> Self {
1184 Self {
1185 tool: Some(0),
1186 spool_id: Some(sample_spool_id()),
1187 source_kind: EventKind::new("obico_printer_notification").expect("a kind name"),
1188 position: Some(SignalPosition {
1189 position: FilePosition::sample_full(),
1190 freshness: PositionFreshness::ReadAtSignal,
1191 }),
1192 planned_change: Some(0),
1193 }
1194 }
1195
1196 fn sample_minimal() -> Self {
1197 Self {
1198 tool: None,
1199 spool_id: None,
1200 position: None,
1201 planned_change: None,
1202 ..Self::sample_full()
1203 }
1204 }
1205}
1206
1207#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1209#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1210#[schemars(crate = "printobserver_types::schemars")]
1211pub enum PlannedChangeTrigger {
1212 Signal,
1214 Position,
1216}
1217
1218#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1225#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1226#[schemars(
1227 crate = "printobserver_types::schemars",
1228 transform = crate::gcode_index::null_is_sent
1229)]
1230pub struct FilamentChangePlannedReachedPayload {
1231 pub change: PlannedChange,
1233 pub previous_color: Option<String>,
1236 pub trigger: PlannedChangeTrigger,
1238 pub position: FilePosition,
1240 pub spool_id: Option<SpoolId>,
1243 pub next_spool_id: Option<SpoolId>,
1246 pub next_segment_filament_mm: f64,
1248}
1249
1250impl EventPayload for FilamentChangePlannedReachedPayload {
1251 const KIND: &'static str = "filament_change_planned_reached";
1252}
1253
1254impl Sample for FilamentChangePlannedReachedPayload {
1255 fn sample_full() -> Self {
1256 Self {
1257 change: PlannedChange::sample_full(),
1258 previous_color: Some("#FFFFFF".to_owned()),
1259 trigger: PlannedChangeTrigger::Position,
1260 position: FilePosition::sample_full(),
1261 spool_id: Some(sample_spool_id()),
1262 next_spool_id: Some(sample_spool_id()),
1263 next_segment_filament_mm: 812.4,
1264 }
1265 }
1266
1267 fn sample_alternates() -> Vec<Self> {
1268 vec![Self {
1269 previous_color: None,
1270 trigger: PlannedChangeTrigger::Signal,
1271 spool_id: None,
1272 next_spool_id: None,
1273 ..Self::sample_full()
1274 }]
1275 }
1276}
1277
1278#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1282#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1283#[schemars(
1284 crate = "printobserver_types::schemars",
1285 transform = crate::gcode_index::null_is_sent
1286)]
1287pub struct FilamentChangePlannedResumedPayload {
1288 pub change: PlannedChange,
1290 pub previous_color: Option<String>,
1293 pub waited_s: i64,
1295 pub position: FilePosition,
1297}
1298
1299impl EventPayload for FilamentChangePlannedResumedPayload {
1300 const KIND: &'static str = "filament_change_planned_resumed";
1301}
1302
1303impl Sample for FilamentChangePlannedResumedPayload {
1304 fn sample_full() -> Self {
1305 Self {
1306 change: PlannedChange::sample_full(),
1307 previous_color: Some("#FFFFFF".to_owned()),
1308 waited_s: 412,
1309 position: FilePosition::sample_full(),
1310 }
1311 }
1312
1313 fn sample_alternates() -> Vec<Self> {
1314 vec![Self {
1315 previous_color: None,
1316 ..Self::sample_full()
1317 }]
1318 }
1319}
1320
1321#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1323#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1324#[schemars(crate = "printobserver_types::schemars")]
1325pub struct UnaccountedPrintPayload {
1326 pub file_name: String,
1328 #[serde(default, skip_serializing_if = "Option::is_none")]
1330 pub printed_at: Option<Timestamp>,
1331 pub success: bool,
1334 pub charged: bool,
1337}
1338
1339impl EventPayload for UnaccountedPrintPayload {
1340 const KIND: &'static str = "unaccounted_print";
1341}
1342
1343impl Sample for UnaccountedPrintPayload {
1344 fn sample_full() -> Self {
1345 Self {
1346 file_name: "benchy.gcode".to_owned(),
1347 printed_at: Some(Timestamp::sample_full()),
1348 success: true,
1349 charged: true,
1350 }
1351 }
1352
1353 fn sample_minimal() -> Self {
1354 Self {
1355 printed_at: None,
1356 success: false,
1357 charged: false,
1358 ..Self::sample_full()
1359 }
1360 }
1361}
1362
1363#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1365#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1366#[schemars(crate = "printobserver_types::schemars")]
1367pub struct PreflightCheckedPayload {
1368 pub preflight: Preflight,
1370 #[serde(default, skip_serializing_if = "Option::is_none")]
1372 pub action_id: Option<ActionId>,
1373}
1374
1375impl EventPayload for PreflightCheckedPayload {
1376 const KIND: &'static str = "preflight_checked";
1377}
1378
1379impl Sample for PreflightCheckedPayload {
1380 fn sample_full() -> Self {
1381 Self {
1382 preflight: Preflight::sample_full(),
1383 action_id: Some(ActionId::sample_full()),
1384 }
1385 }
1386
1387 fn sample_minimal() -> Self {
1388 Self {
1389 action_id: None,
1390 ..Self::sample_full()
1391 }
1392 }
1393}
1394
1395#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1398#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1399#[schemars(crate = "printobserver_types::schemars")]
1400pub struct ChargePendedPayload {
1401 pub pending: PendingCharge,
1403}
1404
1405impl EventPayload for ChargePendedPayload {
1406 const KIND: &'static str = "charge_pended";
1407}
1408
1409impl Sample for ChargePendedPayload {
1410 fn sample_full() -> Self {
1411 Self {
1412 pending: PendingCharge::sample_full(),
1413 }
1414 }
1415
1416 fn sample_minimal() -> Self {
1417 Self {
1418 pending: PendingCharge::sample_minimal(),
1419 }
1420 }
1421}
1422
1423#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1426#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1427#[schemars(crate = "printobserver_types::schemars")]
1428pub struct PrintUntrackedPayload {
1429 pub reason: String,
1431}
1432
1433impl EventPayload for PrintUntrackedPayload {
1434 const KIND: &'static str = "print_untracked";
1435}
1436
1437impl Sample for PrintUntrackedPayload {
1438 fn sample_full() -> Self {
1439 Self {
1440 reason: "the print was already running when spool tracking was installed".to_owned(),
1441 }
1442 }
1443}
1444
1445#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1447#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1448#[schemars(crate = "printobserver_types::schemars")]
1449pub enum RebaselineDisposition {
1450 Accounted,
1452 Unverified,
1455}
1456
1457impl Sample for RebaselineDisposition {
1458 fn sample_full() -> Self {
1459 Self::Unverified
1460 }
1461}
1462
1463#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1469#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1470#[schemars(crate = "printobserver_types::schemars")]
1471pub struct FileTallyRebaselinedPayload {
1472 pub file_name: String,
1474 pub origin: String,
1476 pub old_generation: u32,
1478 pub new_generation: u32,
1480 pub old_successes: i64,
1482 pub old_failures: i64,
1484 pub new_successes: i64,
1486 pub new_failures: i64,
1488 pub disposition: RebaselineDisposition,
1490}
1491
1492impl EventPayload for FileTallyRebaselinedPayload {
1493 const KIND: &'static str = "file_tally_rebaselined";
1494}
1495
1496impl Sample for FileTallyRebaselinedPayload {
1497 fn sample_full() -> Self {
1498 Self {
1499 file_name: "benchy.gcode".to_owned(),
1500 origin: "local".to_owned(),
1501 old_generation: 0,
1502 new_generation: 1,
1503 old_successes: 5,
1504 old_failures: 1,
1505 new_successes: 1,
1506 new_failures: 0,
1507 disposition: RebaselineDisposition::Unverified,
1508 }
1509 }
1510
1511 fn sample_alternates() -> Vec<Self> {
1512 vec![Self {
1513 disposition: RebaselineDisposition::Accounted,
1514 ..Self::sample_full()
1515 }]
1516 }
1517}
1518
1519#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1524#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1525#[schemars(crate = "printobserver_types::schemars")]
1526pub struct PrinterConnectionChangedPayload {
1527 pub from: PrinterState,
1529 pub to: PrinterState,
1531 pub detail: String,
1533}
1534
1535impl EventPayload for PrinterConnectionChangedPayload {
1536 const KIND: &'static str = "printer_connection_changed";
1537}
1538
1539impl Sample for PrinterConnectionChangedPayload {
1540 fn sample_full() -> Self {
1541 Self {
1542 from: PrinterState::Printing,
1543 to: PrinterState::Offline,
1544 detail: "the printer reports Offline after error: SerialTimeoutException: ".to_owned(),
1545 }
1546 }
1547
1548 fn sample_alternates() -> Vec<Self> {
1549 vec![Self {
1550 from: PrinterState::Offline,
1551 to: PrinterState::Operational,
1552 detail: "the printer reports Operational".to_owned(),
1553 }]
1554 }
1555}
1556
1557#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1564#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1565#[schemars(crate = "printobserver_types::schemars")]
1566pub struct PrinterResetPayload {
1567 #[serde(default)]
1569 pub during_print: Option<PrintId>,
1570 pub detail: String,
1572}
1573
1574impl EventPayload for PrinterResetPayload {
1575 const KIND: &'static str = "printer_reset";
1576}
1577
1578impl Sample for PrinterResetPayload {
1579 fn sample_full() -> Self {
1580 Self {
1581 during_print: Some(PrintId::sample_full()),
1582 detail: "the printer pushed a reset".to_owned(),
1583 }
1584 }
1585
1586 fn sample_minimal() -> Self {
1587 Self {
1588 during_print: None,
1589 detail: "the printer pushed a reset".to_owned(),
1590 }
1591 }
1592}
1593
1594#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1596#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1597#[schemars(crate = "printobserver_types::schemars")]
1598pub struct HeatedTool {
1599 pub tool: i64,
1601 pub target_c: f64,
1603}
1604
1605impl Sample for HeatedTool {
1606 fn sample_full() -> Self {
1607 Self {
1608 tool: 0,
1609 target_c: 215.0,
1610 }
1611 }
1612}
1613
1614#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1622#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1623#[schemars(crate = "printobserver_types::schemars")]
1624pub struct UnattendedPrinterActivityPayload {
1625 pub last_print_id: PrintId,
1627 pub tools: Vec<HeatedTool>,
1629 #[serde(default)]
1631 pub bed_target_c: Option<f64>,
1632 #[serde(default)]
1635 pub moved: Option<bool>,
1636 pub detail: String,
1638}
1639
1640impl EventPayload for UnattendedPrinterActivityPayload {
1641 const KIND: &'static str = "unattended_printer_activity";
1642}
1643
1644impl Sample for UnattendedPrinterActivityPayload {
1645 fn sample_full() -> Self {
1646 Self {
1647 last_print_id: PrintId::sample_full(),
1648 tools: vec![HeatedTool::sample_full()],
1649 bed_target_c: Some(60.0),
1650 moved: Some(true),
1651 detail: "tool 0 is heating to 215 °C with no job running".to_owned(),
1652 }
1653 }
1654
1655 fn sample_minimal() -> Self {
1656 Self {
1657 last_print_id: PrintId::sample_full(),
1658 tools: Vec::new(),
1659 bed_target_c: None,
1660 moved: None,
1661 detail: "the print head moved with no job running".to_owned(),
1662 }
1663 }
1664}
1665
1666#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1668#[serde(
1669 crate = "printobserver_types::serde",
1670 rename_all = "snake_case",
1671 deny_unknown_fields
1672)]
1673#[schemars(crate = "printobserver_types::schemars")]
1674pub enum DetectorStatus {
1675 Available,
1677 Unavailable,
1679}
1680
1681impl Sample for DetectorStatus {
1682 fn sample_full() -> Self {
1683 Self::Unavailable
1684 }
1685
1686 fn sample_alternates() -> Vec<Self> {
1687 vec![Self::Available]
1688 }
1689}
1690
1691#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1695#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1696#[schemars(crate = "printobserver_types::schemars")]
1697pub struct DetectorHealthChangedPayload {
1698 pub status: DetectorStatus,
1700 pub detail: String,
1702}
1703
1704impl EventPayload for DetectorHealthChangedPayload {
1705 const KIND: &'static str = "detector_health_changed";
1706}
1707
1708impl Sample for DetectorHealthChangedPayload {
1709 fn sample_full() -> Self {
1710 Self {
1711 status: DetectorStatus::Unavailable,
1712 detail: "the detector's health check answered 503".to_owned(),
1713 }
1714 }
1715
1716 fn sample_alternates() -> Vec<Self> {
1717 vec![Self {
1718 status: DetectorStatus::Available,
1719 detail: "the detector's health check answered 200".to_owned(),
1720 }]
1721 }
1722}
1723
1724#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1728#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1729#[schemars(crate = "printobserver_types::schemars")]
1730pub struct RecoveryRequestedPayload {
1731 pub action: RecoveryAction,
1733 pub actor: Actor,
1735 pub reason: String,
1737 #[serde(default, skip_serializing_if = "Option::is_none")]
1741 pub bed_clear: Option<EventId>,
1742}
1743
1744impl EventPayload for RecoveryRequestedPayload {
1745 const KIND: &'static str = "recovery_requested";
1746}
1747
1748impl Sample for RecoveryRequestedPayload {
1749 fn sample_full() -> Self {
1750 Self {
1751 action: RecoveryAction::sample_full(),
1752 actor: Actor::Operator,
1753 reason: "free the nozzle from the part".to_owned(),
1754 bed_clear: Some(EventId::sample_full()),
1755 }
1756 }
1757
1758 fn sample_minimal() -> Self {
1759 Self {
1760 bed_clear: None,
1761 ..Self::sample_full()
1762 }
1763 }
1764}
1765
1766#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1768#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1769#[schemars(crate = "printobserver_types::schemars")]
1770pub struct RecoveryExecutedPayload {
1771 pub action: RecoveryAction,
1773 pub actor: Actor,
1775 pub reason: String,
1777 pub outcome: crate::records::ExecutionOutcome,
1779 #[serde(default, skip_serializing_if = "Option::is_none")]
1783 pub bed_clear: Option<EventId>,
1784}
1785
1786impl EventPayload for RecoveryExecutedPayload {
1787 const KIND: &'static str = "recovery_executed";
1788}
1789
1790impl Sample for RecoveryExecutedPayload {
1791 fn sample_full() -> Self {
1792 Self {
1793 action: RecoveryAction::RecoverLift { mm: 10.0 },
1794 actor: Actor::Operator,
1795 reason: "free the nozzle from the part".to_owned(),
1796 outcome: crate::records::ExecutionOutcome::Succeeded,
1797 bed_clear: Some(EventId::sample_full()),
1798 }
1799 }
1800
1801 fn sample_minimal() -> Self {
1802 Self {
1803 bed_clear: None,
1804 ..Self::sample_full()
1805 }
1806 }
1807
1808 fn sample_alternates() -> Vec<Self> {
1809 vec![Self {
1810 outcome: crate::records::ExecutionOutcome::Failed {
1811 reason: "the printer is unreachable: connection refused".to_owned(),
1812 },
1813 ..Self::sample_full()
1814 }]
1815 }
1816}
1817
1818#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1820#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1821#[schemars(crate = "printobserver_types::schemars")]
1822pub struct RecoveryRejectedPayload {
1823 pub action: RecoveryAction,
1825 pub actor: Actor,
1827 pub reason: String,
1829 pub rejection: RecoveryRejection,
1831}
1832
1833impl EventPayload for RecoveryRejectedPayload {
1834 const KIND: &'static str = "recovery_rejected";
1835}
1836
1837impl Sample for RecoveryRejectedPayload {
1838 fn sample_full() -> Self {
1839 Self {
1840 action: RecoveryAction::RecoverPark {
1841 clearance_asserted: false,
1842 },
1843 actor: Actor::Operator,
1844 reason: "move the head off the part".to_owned(),
1845 rejection: RecoveryRejection::sample_full(),
1846 }
1847 }
1848}
1849
1850#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1861#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1862#[schemars(crate = "printobserver_types::schemars")]
1863pub struct BedClearAssertedPayload {
1864 pub actor: BedClearActor,
1866 pub reason: String,
1868}
1869
1870#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1876#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1877#[schemars(crate = "printobserver_types::schemars")]
1878pub enum BedClearActor {
1879 Operator,
1881}
1882
1883impl BedClearActor {
1884 #[must_use]
1886 pub const fn actor(self) -> Actor {
1887 match self {
1888 Self::Operator => Actor::Operator,
1889 }
1890 }
1891}
1892
1893impl EventPayload for BedClearAssertedPayload {
1894 const KIND: &'static str = "bed_clear_asserted";
1895}
1896
1897impl Sample for BedClearAssertedPayload {
1898 fn sample_full() -> Self {
1899 Self {
1900 actor: BedClearActor::Operator,
1901 reason: "the cancelled print is off the bed and nothing else is on it".to_owned(),
1902 }
1903 }
1904}