Skip to main content

axonflow_sdk_rust/
config.rs

1use std::fmt;
2use std::time::Duration;
3
4#[derive(Default, Debug, Clone, PartialEq, Eq)]
5pub enum Mode {
6    #[default]
7    Production,
8    Sandbox,
9}
10
11#[derive(Debug, Clone)]
12pub struct RetryConfig {
13    pub enabled: bool,
14    pub max_attempts: u32,
15    pub initial_delay: Duration,
16}
17
18impl Default for RetryConfig {
19    fn default() -> Self {
20        Self {
21            enabled: true,
22            max_attempts: 3,
23            initial_delay: Duration::from_secs(1),
24        }
25    }
26}
27
28#[derive(Debug, Clone)]
29pub struct CacheConfig {
30    pub enabled: bool,
31    pub ttl: Duration,
32}
33
34impl Default for CacheConfig {
35    fn default() -> Self {
36        Self {
37            enabled: true,
38            ttl: Duration::from_secs(60),
39        }
40    }
41}
42
43#[derive(Clone)]
44pub struct AxonFlowConfig {
45    pub endpoint: String,
46    pub client_id: Option<String>,
47    pub client_secret: Option<String>,
48    pub license_key: Option<String>,
49    pub mode: Mode,
50    pub debug: bool,
51    pub timeout: Duration,
52    pub map_timeout: Duration,
53    pub retry: RetryConfig,
54    pub cache: CacheConfig,
55    pub insecure_skip_tls_verify: bool,
56}
57
58impl fmt::Debug for AxonFlowConfig {
59    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
60        f.debug_struct("AxonFlowConfig")
61            .field("endpoint", &self.endpoint)
62            .field("client_id", &self.client_id)
63            .field(
64                "client_secret",
65                &self.client_secret.as_ref().map(|_| "[REDACTED]"),
66            )
67            .field(
68                "license_key",
69                &self.license_key.as_ref().map(|_| "[REDACTED]"),
70            )
71            .field("mode", &self.mode)
72            .field("debug", &self.debug)
73            .field("timeout", &self.timeout)
74            .field("map_timeout", &self.map_timeout)
75            .field("retry", &self.retry)
76            .field("cache", &self.cache)
77            .field("insecure_skip_tls_verify", &self.insecure_skip_tls_verify)
78            .finish()
79    }
80}
81
82impl Default for AxonFlowConfig {
83    fn default() -> Self {
84        Self {
85            endpoint: String::new(),
86            client_id: None,
87            client_secret: None,
88            license_key: None,
89            mode: Mode::default(),
90            debug: false,
91            timeout: Duration::from_secs(60),
92            map_timeout: Duration::from_secs(120),
93            retry: RetryConfig::default(),
94            cache: CacheConfig::default(),
95            insecure_skip_tls_verify: false,
96        }
97    }
98}
99
100impl AxonFlowConfig {
101    pub fn new(endpoint: impl Into<String>) -> Self {
102        Self {
103            endpoint: endpoint.into(),
104            ..Default::default()
105        }
106    }
107
108    pub fn with_auth(
109        mut self,
110        client_id: impl Into<String>,
111        client_secret: impl Into<String>,
112    ) -> Self {
113        self.client_id = Some(client_id.into());
114        self.client_secret = Some(client_secret.into());
115        self
116    }
117
118    pub fn with_license_key(mut self, license_key: impl Into<String>) -> Self {
119        self.license_key = Some(license_key.into());
120        self
121    }
122
123    pub fn with_mode(mut self, mode: Mode) -> Self {
124        self.mode = mode;
125        self
126    }
127
128    pub fn with_timeout(mut self, timeout: Duration) -> Self {
129        self.timeout = timeout;
130        self
131    }
132
133    pub fn with_map_timeout(mut self, timeout: Duration) -> Self {
134        self.map_timeout = timeout;
135        self
136    }
137
138    pub fn with_retry(mut self, retry: RetryConfig) -> Self {
139        self.retry = retry;
140        self
141    }
142
143    pub fn with_cache(mut self, cache: CacheConfig) -> Self {
144        self.cache = cache;
145        self
146    }
147}