Skip to main content

remendo/client/
types.rs

1//! Query parameter types and retry configuration for API requests.
2
3/// Parameters for list endpoints (`/api/patchsets`, `/api/messages`).
4#[derive(Debug, Clone)]
5pub struct ListParams {
6    /// Page number (1-indexed).
7    pub page: u32,
8    /// Items per page (max 100).
9    pub per_page: u32,
10    /// Optional search query string.
11    pub search: Option<String>,
12    /// Optional mailing list filter.
13    pub mailing_list: Option<String>,
14}
15
16impl Default for ListParams {
17    fn default() -> Self {
18        Self {
19            page: 1,
20            per_page: 50,
21            search: None,
22            mailing_list: None,
23        }
24    }
25}
26
27/// Parameters for review endpoints (`/api/review`, `/api/review_log`).
28#[derive(Debug, Clone)]
29pub struct ReviewQuery {
30    /// Review ID (one of `id` or `patchset_id` required).
31    pub id: Option<i64>,
32    /// Patchset ID to get the latest review for.
33    pub patchset_id: Option<i64>,
34}
35
36/// Retry configuration for transient failures.
37#[derive(Debug, Clone)]
38pub struct RetryConfig {
39    /// Maximum number of retry attempts.
40    pub max_retries: u32,
41    /// Base delay between retries in milliseconds.
42    pub base_delay_ms: u64,
43    /// Maximum delay between retries in milliseconds.
44    pub max_delay_ms: u64,
45    /// Backoff multiplier applied after each retry.
46    pub backoff_factor: f64,
47}
48
49impl Default for RetryConfig {
50    fn default() -> Self {
51        Self {
52            max_retries: 3,
53            base_delay_ms: 500,
54            max_delay_ms: 10_000,
55            backoff_factor: 2.0,
56        }
57    }
58}
59
60impl RetryConfig {
61    /// Create a retry config from a `RemoteConfig`.
62    #[must_use]
63    pub fn from_remote(config: &crate::config::RemoteConfig) -> Self {
64        Self {
65            max_retries: config.max_retries,
66            ..Self::default()
67        }
68    }
69}
70
71#[cfg(test)]
72mod tests {
73    use super::*;
74
75    #[test]
76    fn list_params_defaults() {
77        let params = ListParams::default();
78        assert_eq!(params.page, 1);
79        assert_eq!(params.per_page, 50);
80        assert!(params.search.is_none());
81        assert!(params.mailing_list.is_none());
82    }
83
84    #[test]
85    fn retry_config_defaults() {
86        let config = RetryConfig::default();
87        assert_eq!(config.max_retries, 3);
88        assert_eq!(config.base_delay_ms, 500);
89        assert_eq!(config.max_delay_ms, 10_000);
90    }
91}