1use printobserver_types::schemars::JsonSchema;
16use printobserver_types::serde::{Deserialize, Serialize};
17use printobserver_types::{EventId, FileName, PrintId, Timestamp};
18
19use super::ids::ActionId;
20use super::manifest::JobManifest;
21use super::policy::PolicyDecision;
22
23#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
25#[serde(
26 crate = "printobserver_types::serde",
27 rename_all = "snake_case",
28 deny_unknown_fields
29)]
30#[schemars(crate = "printobserver_types::schemars")]
31pub enum Actor {
32 Agent {
34 session_name: String,
36 },
37 Operator,
39 System,
41}
42
43impl Actor {
44 #[must_use]
46 pub const fn class(&self) -> ActorClass {
47 match self {
48 Self::Agent { .. } => ActorClass::Agent,
49 Self::Operator => ActorClass::Operator,
50 Self::System => ActorClass::System,
51 }
52 }
53}
54
55#[derive(
57 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
58)]
59#[serde(
60 crate = "printobserver_types::serde",
61 rename_all = "snake_case",
62 deny_unknown_fields
63)]
64#[schemars(crate = "printobserver_types::schemars")]
65pub enum ActorClass {
66 Agent,
68 Operator,
70 System,
72}
73
74#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
76#[serde(
77 crate = "printobserver_types::serde",
78 rename_all = "snake_case",
79 deny_unknown_fields
80)]
81#[schemars(crate = "printobserver_types::schemars")]
82pub enum AcknowledgementDisposition {
83 Continue,
85 Watch,
87 Stop,
89}
90
91#[derive(
96 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
97)]
98#[serde(
99 crate = "printobserver_types::serde",
100 rename_all = "snake_case",
101 deny_unknown_fields
102)]
103#[schemars(crate = "printobserver_types::schemars")]
104pub enum ActionKind {
105 Pause,
107 Resume,
109 Cancel,
111 StartPrint,
113 SetFeedrateFactor,
115 SetFlowrateFactor,
117 SetToolTargetC,
119 SetBedTargetC,
121 SetFanPercent,
123 AcknowledgeFailure,
125}
126
127#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
129#[serde(
130 crate = "printobserver_types::serde",
131 tag = "action",
132 rename_all = "snake_case",
133 deny_unknown_fields
134)]
135#[schemars(crate = "printobserver_types::schemars")]
136pub enum PrintAction {
137 Pause {
139 reason: String,
141 actor: Actor,
143 },
144 Resume {
146 reason: String,
148 actor: Actor,
150 },
151 Cancel {
153 reason: String,
155 actor: Actor,
157 },
158 StartPrint {
160 file_name: FileName,
162 manifest: JobManifest,
164 reason: String,
166 actor: Actor,
168 },
169 SetFeedrateFactor {
171 factor: f64,
173 #[serde(default, skip_serializing_if = "Option::is_none")]
175 duration_s: Option<i64>,
176 reason: String,
178 actor: Actor,
180 },
181 SetFlowrateFactor {
183 factor: f64,
185 #[serde(default, skip_serializing_if = "Option::is_none")]
187 duration_s: Option<i64>,
188 reason: String,
190 actor: Actor,
192 },
193 SetToolTargetC {
195 tool: i64,
197 target_c: f64,
199 #[serde(default, skip_serializing_if = "Option::is_none")]
201 duration_s: Option<i64>,
202 reason: String,
204 actor: Actor,
206 },
207 SetBedTargetC {
209 target_c: f64,
211 #[serde(default, skip_serializing_if = "Option::is_none")]
213 duration_s: Option<i64>,
214 reason: String,
216 actor: Actor,
218 },
219 SetFanPercent {
221 percent: f64,
223 #[serde(default, skip_serializing_if = "Option::is_none")]
225 duration_s: Option<i64>,
226 reason: String,
228 actor: Actor,
230 },
231 AcknowledgeFailure {
233 event_id: EventId,
235 disposition: AcknowledgementDisposition,
237 reason: String,
239 actor: Actor,
241 },
242}
243
244impl PrintAction {
245 #[must_use]
247 pub const fn kind(&self) -> ActionKind {
248 match self {
249 Self::Pause { .. } => ActionKind::Pause,
250 Self::Resume { .. } => ActionKind::Resume,
251 Self::Cancel { .. } => ActionKind::Cancel,
252 Self::StartPrint { .. } => ActionKind::StartPrint,
253 Self::SetFeedrateFactor { .. } => ActionKind::SetFeedrateFactor,
254 Self::SetFlowrateFactor { .. } => ActionKind::SetFlowrateFactor,
255 Self::SetToolTargetC { .. } => ActionKind::SetToolTargetC,
256 Self::SetBedTargetC { .. } => ActionKind::SetBedTargetC,
257 Self::SetFanPercent { .. } => ActionKind::SetFanPercent,
258 Self::AcknowledgeFailure { .. } => ActionKind::AcknowledgeFailure,
259 }
260 }
261
262 #[must_use]
264 pub fn reason(&self) -> &str {
265 match self {
266 Self::Pause { reason, .. }
267 | Self::Resume { reason, .. }
268 | Self::Cancel { reason, .. }
269 | Self::StartPrint { reason, .. }
270 | Self::SetFeedrateFactor { reason, .. }
271 | Self::SetFlowrateFactor { reason, .. }
272 | Self::SetToolTargetC { reason, .. }
273 | Self::SetBedTargetC { reason, .. }
274 | Self::SetFanPercent { reason, .. }
275 | Self::AcknowledgeFailure { reason, .. } => reason,
276 }
277 }
278
279 #[must_use]
281 pub const fn actor(&self) -> &Actor {
282 match self {
283 Self::Pause { actor, .. }
284 | Self::Resume { actor, .. }
285 | Self::Cancel { actor, .. }
286 | Self::StartPrint { actor, .. }
287 | Self::SetFeedrateFactor { actor, .. }
288 | Self::SetFlowrateFactor { actor, .. }
289 | Self::SetToolTargetC { actor, .. }
290 | Self::SetBedTargetC { actor, .. }
291 | Self::SetFanPercent { actor, .. }
292 | Self::AcknowledgeFailure { actor, .. } => actor,
293 }
294 }
295}
296
297#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
299#[serde(
300 crate = "printobserver_types::serde",
301 rename_all = "snake_case",
302 deny_unknown_fields
303)]
304#[schemars(crate = "printobserver_types::schemars")]
305pub enum ExecutionOutcome {
306 Succeeded,
308 Failed {
310 reason: String,
312 },
313}
314
315#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
317#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
318#[schemars(crate = "printobserver_types::schemars")]
319pub struct ActionRequest {
320 pub action: PrintAction,
322 pub actor: Actor,
324 pub requested_at: Timestamp,
326}
327
328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
334#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
335#[schemars(crate = "printobserver_types::schemars")]
336pub struct ActionRecord {
337 pub id: ActionId,
339 pub print_id: PrintId,
341 pub request: ActionRequest,
343 pub decision: PolicyDecision,
345 #[serde(default, skip_serializing_if = "Option::is_none")]
347 pub executed_at: Option<Timestamp>,
348 #[serde(default, skip_serializing_if = "Option::is_none")]
350 pub outcome: Option<ExecutionOutcome>,
351}