printobserver_types/intervention.rs
1//! A bounded change, and what became of it when it expired.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::adjustable::Adjustable;
7use crate::ids::{ActionId, InterventionId, PrintId};
8use crate::timestamp::Timestamp;
9
10/// What became of a bounded change.
11#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
12#[serde(rename_all = "snake_case", deny_unknown_fields)]
13pub enum InterventionOutcome {
14 /// It is still in force.
15 StillActive,
16 /// The prior value was put back.
17 Restored,
18 /// There was no prior value to put back.
19 RestoreUnavailable,
20 /// Putting the prior value back failed.
21 RestoreFailed {
22 /// Why it failed.
23 reason: String,
24 },
25 /// Another intervention replaced it before it expired.
26 Superseded {
27 /// The intervention that replaced it.
28 by: InterventionId,
29 },
30}
31
32/// One adjustment made for a bounded time.
33///
34/// `prior_value` is read from the printer snapshot taken before the change, and
35/// is absent when the printer reported none — in which case expiry restores
36/// nothing and the outcome says so rather than guessing a default.
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
38#[serde(deny_unknown_fields)]
39pub struct Intervention {
40 /// This intervention's identifier, minted by the store.
41 pub id: InterventionId,
42 /// The print it was made against.
43 pub print_id: PrintId,
44 /// The action that asked for it.
45 pub action_id: ActionId,
46 /// What it changed.
47 pub adjustable: Adjustable,
48 /// What the printer reported before the change, if it reported anything.
49 #[serde(default, skip_serializing_if = "Option::is_none")]
50 pub prior_value: Option<f64>,
51 /// What it was changed to.
52 pub applied_value: f64,
53 /// When it was applied.
54 pub applied_at: Timestamp,
55 /// When it stops standing.
56 pub expires_at: Timestamp,
57 /// When the prior value was put back, if it was.
58 #[serde(default, skip_serializing_if = "Option::is_none")]
59 pub restored_at: Option<Timestamp>,
60 /// What became of it.
61 pub outcome: InterventionOutcome,
62}