1use crate::metrics::{
6    Datetime, DatetimeMetric, QuantityMetric, StringMetric, TimeUnit, TimespanMetric,
7};
8use crate::{CommonMetricData, Lifetime};
9
10use once_cell::sync::Lazy;
11
12#[derive(Debug, Default)]
14pub struct ClientInfoMetrics {
15    pub app_build: String,
17    pub app_display_version: String,
19    pub app_build_date: Datetime,
21
22    pub architecture: String,
24    pub os_version: String,
26
27    pub channel: Option<String>,
29    pub android_sdk_version: Option<String>,
31    pub windows_build_number: Option<i64>,
33    pub device_manufacturer: Option<String>,
36    pub device_model: Option<String>,
40    pub locale: Option<String>,
43}
44
45impl ClientInfoMetrics {
47    pub fn unknown() -> Self {
49        ClientInfoMetrics {
50            app_build: "Unknown".to_string(),
51            app_display_version: "Unknown".to_string(),
52            app_build_date: Datetime::default(),
53            architecture: "Unknown".to_string(),
54            os_version: "Unknown".to_string(),
55            channel: Some("Unknown".to_string()),
56            android_sdk_version: None,
57            windows_build_number: None,
58            device_manufacturer: None,
59            device_model: None,
60            locale: None,
61        }
62    }
63}
64
65#[allow(non_upper_case_globals)]
66pub mod internal_metrics {
67    use super::*;
68
69    pub static app_build: Lazy<StringMetric> = Lazy::new(|| {
70        StringMetric::new(CommonMetricData {
71            name: "app_build".into(),
72            category: "".into(),
73            send_in_pings: vec!["glean_client_info".into()],
74            lifetime: Lifetime::Application,
75            disabled: false,
76            ..Default::default()
77        })
78    });
79
80    pub static app_display_version: Lazy<StringMetric> = Lazy::new(|| {
81        StringMetric::new(CommonMetricData {
82            name: "app_display_version".into(),
83            category: "".into(),
84            send_in_pings: vec!["glean_client_info".into()],
85            lifetime: Lifetime::Application,
86            disabled: false,
87            ..Default::default()
88        })
89    });
90
91    pub static app_build_date: Lazy<DatetimeMetric> = Lazy::new(|| {
92        DatetimeMetric::new(
93            CommonMetricData {
94                name: "build_date".into(),
95                category: "".into(),
96                send_in_pings: vec!["glean_client_info".into()],
97                lifetime: Lifetime::Application,
98                disabled: false,
99                ..Default::default()
100            },
101            TimeUnit::Second,
102        )
103    });
104
105    pub static app_channel: Lazy<StringMetric> = Lazy::new(|| {
106        StringMetric::new(CommonMetricData {
107            name: "app_channel".into(),
108            category: "".into(),
109            send_in_pings: vec!["glean_client_info".into()],
110            lifetime: Lifetime::Application,
111            disabled: false,
112            ..Default::default()
113        })
114    });
115
116    pub static os_version: Lazy<StringMetric> = Lazy::new(|| {
117        StringMetric::new(CommonMetricData {
118            name: "os_version".into(),
119            category: "".into(),
120            send_in_pings: vec!["glean_client_info".into()],
121            lifetime: Lifetime::Application,
122            disabled: false,
123            ..Default::default()
124        })
125    });
126
127    pub static architecture: Lazy<StringMetric> = Lazy::new(|| {
128        StringMetric::new(CommonMetricData {
129            name: "architecture".into(),
130            category: "".into(),
131            send_in_pings: vec!["glean_client_info".into()],
132            lifetime: Lifetime::Application,
133            disabled: false,
134            ..Default::default()
135        })
136    });
137
138    pub static android_sdk_version: Lazy<StringMetric> = Lazy::new(|| {
139        StringMetric::new(CommonMetricData {
140            name: "android_sdk_version".into(),
141            category: "".into(),
142            send_in_pings: vec!["glean_client_info".into()],
143            lifetime: Lifetime::Application,
144            disabled: false,
145            ..Default::default()
146        })
147    });
148
149    pub static windows_build_number: Lazy<QuantityMetric> = Lazy::new(|| {
150        QuantityMetric::new(CommonMetricData {
151            name: "windows_build_number".into(),
152            category: "".into(),
153            send_in_pings: vec!["glean_client_info".into()],
154            lifetime: Lifetime::Application,
155            disabled: false,
156            ..Default::default()
157        })
158    });
159
160    pub static device_manufacturer: Lazy<StringMetric> = Lazy::new(|| {
161        StringMetric::new(CommonMetricData {
162            name: "device_manufacturer".into(),
163            category: "".into(),
164            send_in_pings: vec!["glean_client_info".into()],
165            lifetime: Lifetime::Application,
166            disabled: false,
167            ..Default::default()
168        })
169    });
170
171    pub static device_model: Lazy<StringMetric> = Lazy::new(|| {
172        StringMetric::new(CommonMetricData {
173            name: "device_model".into(),
174            category: "".into(),
175            send_in_pings: vec!["glean_client_info".into()],
176            lifetime: Lifetime::Application,
177            disabled: false,
178            ..Default::default()
179        })
180    });
181
182    pub static locale: Lazy<StringMetric> = Lazy::new(|| {
183        StringMetric::new(CommonMetricData {
184            name: "locale".into(),
185            category: "".into(),
186            send_in_pings: vec!["glean_client_info".into()],
187            lifetime: Lifetime::Application,
188            disabled: false,
189            ..Default::default()
190        })
191    });
192
193    pub static baseline_duration: Lazy<TimespanMetric> = Lazy::new(|| {
194        TimespanMetric::new(
195            CommonMetricData {
196                name: "duration".into(),
197                category: "glean.baseline".into(),
198                send_in_pings: vec!["baseline".into()],
199                lifetime: Lifetime::Ping,
200                disabled: false,
201                ..Default::default()
202            },
203            TimeUnit::Second,
204        )
205    });
206}