printobserver_core/
context.rs1use crate::records::{EffectiveBounds, Intervention, JobManifest, PrintRecord};
18use crate::watch::DetectorHealth;
19use printobserver_printer_api::{JobSnapshot, PrinterSnapshot};
20use printobserver_types::contract::Sample;
21use printobserver_types::schemars::JsonSchema;
22use printobserver_types::serde::{Deserialize, Serialize};
23use printobserver_types::{EventRecord, ImageRef};
24
25#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
27#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
28#[schemars(crate = "printobserver_types::schemars")]
29pub struct PrintContext {
30 pub print: PrintRecord,
32 #[serde(default, skip_serializing_if = "Option::is_none")]
34 pub printer: Option<PrinterSnapshot>,
35 #[serde(default, skip_serializing_if = "Option::is_none")]
37 pub job: Option<JobSnapshot>,
38 #[serde(default, skip_serializing_if = "Option::is_none")]
40 pub manifest: Option<JobManifest>,
41 pub bounds: EffectiveBounds,
43 pub interventions: Vec<Intervention>,
45 pub recent_events: Vec<EventRecord>,
47 #[serde(default, skip_serializing_if = "Option::is_none")]
49 pub latest_image: Option<ImageRef>,
50 #[serde(default)]
52 pub detector: DetectorHealth,
53}
54
55impl Sample for PrintContext {
56 fn sample_full() -> Self {
57 Self {
58 print: PrintRecord::sample_full(),
59 printer: Some(PrinterSnapshot::sample_full()),
60 job: Some(JobSnapshot::sample_full()),
61 manifest: Some(JobManifest::sample_full()),
62 bounds: EffectiveBounds::sample_full(),
63 interventions: vec![Intervention::sample_full()],
64 recent_events: vec![EventRecord::sample_full()],
65 latest_image: Some(ImageRef::sample_full()),
66 detector: DetectorHealth::sample_full(),
67 }
68 }
69
70 fn sample_minimal() -> Self {
71 Self {
72 print: PrintRecord::sample_minimal(),
73 printer: None,
74 job: None,
75 manifest: None,
76 bounds: EffectiveBounds::sample_full(),
77 interventions: vec![],
78 recent_events: vec![],
79 latest_image: None,
80 detector: DetectorHealth::sample_minimal(),
81 }
82 }
83}