1use maud::{html, Markup, Render};
2use thiserror::Error;
3
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Error)]
8pub enum Error {
9 #[error("invalid report type")]
10 InvalidReportType,
11}
12
13use std::fmt::Display;
14use std::str::FromStr;
15
16#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
18pub enum QcReportType {
19 Summary,
23 #[default]
27 Full,
28}
29
30impl FromStr for QcReportType {
31 type Err = Error;
32 fn from_str(s: &str) -> Result<Self, Self::Err> {
33 match s.trim().to_lowercase().as_str() {
34 "sum" | "summ" | "summary" => Ok(Self::Summary),
35 "full" => Ok(Self::Full),
36 _ => Err(Error::InvalidReportType),
37 }
38 }
39}
40
41impl Display for QcReportType {
42 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
43 match self {
44 Self::Full => f.write_str("Full"),
45 Self::Summary => f.write_str("Summary"),
46 }
47 }
48}
49
50#[derive(Debug, Clone, Default, Deserialize)]
51pub struct QcConfig {
52 #[serde(default)]
53 pub report: QcReportType,
54
55 #[cfg(feature = "navigation")]
56 #[cfg_attr(docsrs, doc(cfg(feature = "navigation")))]
57 #[serde(default)]
58 pub user_rx_ecef: Option<(f64, f64, f64)>,
59}
60
61impl QcConfig {
62 pub fn set_report_type(&mut self, report_type: QcReportType) {
64 self.report = report_type;
65 }
66
67 #[cfg(feature = "navigation")]
69 #[cfg_attr(docsrs, doc(cfg(feature = "navigation")))]
70 pub fn set_reference_rx_orbit(&mut self, ecef_m: (f64, f64, f64)) {
71 self.user_rx_ecef = Some(ecef_m);
72 }
73
74 pub fn with_report_type(&self, report_type: QcReportType) -> Self {
76 let mut s = self.clone();
77 s.report = report_type;
78 s
79 }
80
81 #[cfg(feature = "navigation")]
83 #[cfg_attr(docsrs, doc(cfg(feature = "navigation")))]
84 pub fn with_user_rx_position_ecef(&self, ecef_m: (f64, f64, f64)) -> Self {
85 let mut s = self.clone();
86 s.user_rx_ecef = Some(ecef_m);
87 s
88 }
89}
90
91impl Render for QcConfig {
92 fn render(&self) -> Markup {
93 html! {
94 tr {
95 td {
96 "Report"
97 }
98 td {
99 (self.report.to_string())
100 }
101 }
102 }
103 }
104}