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