melvin_ob/http_handler/
common.rs

1use super::http_request::request_common::RequestError;
2use super::http_response::response_common::ResponseError;
3use chrono::{DateTime, Utc};
4use strum_macros::Display;
5
6/// Represents the different types of imaging objective zones.
7///
8/// A zone can either be:
9/// - `KnownZone`: a rectangular area defined by four integers `[x_1, y_1, x_2, y_2]`.
10/// - `SecretZone`: a zone with unknown dimensions and an unknown position.
11#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
12#[serde(untagged)]
13pub(crate) enum ZoneType {
14    /// A rectangular zone defined by `[x, y, x_2, y_2]`.
15    KnownZone([i32; 4]),
16    /// A secret zone.
17    SecretZone(String),
18}
19
20/// Describes an imaging objective with a defined timeframe, required coverage,
21/// and optical constraints.
22///
23/// These objectives are fulfilled by imaging specific map areas (zones) using a satellite camera.
24#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
25pub(crate) struct ImageObjective {
26    /// Unique identifier for the objective.
27    id: usize,
28    /// Human-readable name of the objective.
29    name: String,
30    /// UTC timestamp marking when the objective becomes active.
31    start: DateTime<Utc>,
32    /// UTC timestamp after which the objective can no longer be fulfilled.
33    end: DateTime<Utc>,
34    /// Unused parameter.
35    decrease_rate: f32,
36    /// The target zone type: either known or secret.
37    zone: ZoneType,
38    /// Required camera lens configuration (e.g., `"wide"` or `"narrow"`).
39    optic_required: String,
40    /// Minimum percentage of zone coverage required for success (range 0.0–1.0).
41    coverage_required: f64,
42    /// Unused parameter.
43    sprite: Option<String>,
44    /// Whether the objective is secret or not.
45    secret: bool,
46}
47
48impl ImageObjective {
49    /// Returns the objective’s unique identifier.
50    pub(crate) fn id(&self) -> usize { self.id }
51    /// Returns the UTC start time for the objective.
52    pub(crate) fn start(&self) -> DateTime<Utc> { self.start }
53    /// Returns the UTC end time for the objective.
54    pub(crate) fn end(&self) -> DateTime<Utc> { self.end }
55    /// Returns the objective's display name.
56    pub(crate) fn name(&self) -> &str { &self.name }
57    /// Returns the associated zone type (known or secret).
58    pub(crate) fn zone_type(&self) -> &ZoneType { &self.zone }
59    /// Returns the required optical configuration (e.g. "wide", "narrow").
60    pub(crate) fn optic_required(&self) -> &str { &self.optic_required }
61    /// Returns the minimum coverage (fraction) required to fulfill the objective.
62    pub(crate) fn coverage_required(&self) -> f64 { self.coverage_required }
63    /// Returns whether the objective is secret.
64    pub(crate) fn is_secret(&self) -> bool { self.secret }
65}
66
67/// A mission objective involving beacon detection and signal noise filtering.
68#[derive(serde::Deserialize, serde::Serialize, Debug, Clone)]
69pub struct BeaconObjective {
70    /// Unique identifier for the beacon objective.
71    id: usize,
72    /// Display name of the beacon objective.
73    name: String,
74    /// UTC start time for the valid measurement window.
75    start: DateTime<Utc>,
76    /// UTC end time for the valid measurement window.
77    end: DateTime<Utc>,
78    /// Unused parameter.
79    decrease_rate: f32,
80    /// Number of attempts already made for this objective.
81    attempts_made: u32,
82    /// Description and contextual details about the objective.
83    description: String,
84}
85
86impl BeaconObjective {
87    /// Returns the beacon objective’s name.
88    pub(crate) fn name(&self) -> &str { self.name.as_str() }
89    /// Returns the unique ID of the objective.
90    pub(crate) fn id(&self) -> usize { self.id }
91    /// Returns the number of attempts made to fulfill the objective.
92    pub(crate) fn attempts_made(&self) -> u32 { self.attempts_made }
93    /// Returns the UTC start time of the objective.
94    pub(crate) fn start(&self) -> DateTime<Utc> { self.start }
95    /// Returns the UTC end time of the objective.
96    pub(crate) fn end(&self) -> DateTime<Utc> { self.end }
97    /// Returns the human-readable objective description.
98    pub(crate) fn description(&self) -> &str { self.description.as_str() }
99}
100
101/// A time slot during which communication (e.g., console downlink) is enabled.
102#[derive(serde::Deserialize, Debug)]
103pub struct CommunicationSlot {
104    /// Unique ID of the communication slot.
105    id: usize,
106    /// UTC timestamp when the slot opens.
107    start: DateTime<Utc>,
108    /// UTC timestamp when the slot closes.
109    end: DateTime<Utc>,
110    /// Whether communication is enabled for this slot.
111    enabled: bool,
112}
113
114impl CommunicationSlot {
115    /// Returns whether this communication slot is currently enabled.
116    fn is_enabled(&self) -> bool { self.enabled }
117
118    /// Returns the unique identifier for this slot.
119    fn id(&self) -> usize { self.id }
120}
121
122/// Represents an achievement milestone defined by the simulation backend.
123#[derive(serde::Deserialize, Debug)]
124pub struct Achievement {
125    /// Unique name or label of the achievement.
126    name: String,
127    /// Whether the achievement has been completed.
128    done: bool,
129    /// Number of points awarded for completing the achievement.
130    points: f32,
131    /// A detailed explanation of the achievement goal.
132    description: String,
133    /// Indicates whether the parameter threshold was crossed.
134    goal_parameter_threshold: bool,
135    /// Indicates whether the achievement's goal condition is satisfied.
136    goal_parameter: bool,
137}
138
139impl Achievement {
140    /// Returns the name of the achievement.
141    fn name(&self) -> &str { &self.name }
142    /// Returns whether the achievement has been completed.
143    fn is_done(&self) -> bool { self.done }
144    /// Returns the number of points this achievement is worth.
145    fn points(&self) -> f32 { self.points }
146    /// Returns the textual description of this achievement.
147    fn description(&self) -> &str { &self.description }
148    /// Returns whether the goal threshold has been reached.
149    fn is_goal_parameter_threshold(&self) -> bool { self.goal_parameter_threshold }
150    /// Returns whether the goal parameter is currently satisfied.
151    fn is_goal_parameter(&self) -> bool { self.goal_parameter }
152}
153
154/// High-level error type that wraps both HTTP request and response errors.
155///
156/// Used throughout the API and backend interface layers to propagate errors between
157/// request and response handlers.
158#[derive(Debug, Display)]
159pub enum HTTPError {
160    /// Represents a failure during the HTTP request phase.
161    HTTPRequestError(RequestError),
162    /// Represents a failure while parsing or interpreting the HTTP response.
163    HTTPResponseError(ResponseError),
164}
165
166impl std::error::Error for HTTPError {}