1use std::path::PathBuf;
2use std::time::Duration;
3
4pub struct FunPayConfig {
5 pub base_url: String,
6 pub user_agent: String,
7 pub retry_base_ms: u32,
8 pub max_retries: u32,
9 pub redirect_limit: usize,
10 pub polling_interval: Duration,
11 pub error_retry_delay: Duration,
12 pub event_channel_capacity: usize,
13 pub state_storage_path: Option<PathBuf>,
14}
15
16impl Default for FunPayConfig {
17 fn default() -> Self {
18 Self {
19 base_url: "https://funpay.com".to_string(),
20 user_agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36".to_string(),
21 retry_base_ms: 20,
22 max_retries: 3,
23 redirect_limit: 10,
24 polling_interval: Duration::from_millis(1500),
25 error_retry_delay: Duration::from_secs(5),
26 event_channel_capacity: 512,
27 state_storage_path: None,
28 }
29 }
30}
31
32impl FunPayConfig {
33 pub fn builder() -> FunPayConfigBuilder {
34 FunPayConfigBuilder::default()
35 }
36}
37
38#[derive(Default)]
39pub struct FunPayConfigBuilder {
40 config: FunPayConfig,
41}
42
43impl FunPayConfigBuilder {
44 pub fn base_url(mut self, url: impl Into<String>) -> Self {
45 self.config.base_url = url.into();
46 self
47 }
48
49 pub fn user_agent(mut self, ua: impl Into<String>) -> Self {
50 self.config.user_agent = ua.into();
51 self
52 }
53
54 pub fn retry_policy(mut self, base_ms: u32, max_retries: u32) -> Self {
55 self.config.retry_base_ms = base_ms;
56 self.config.max_retries = max_retries;
57 self
58 }
59
60 pub fn redirect_limit(mut self, limit: usize) -> Self {
61 self.config.redirect_limit = limit;
62 self
63 }
64
65 pub fn polling_interval(mut self, interval: Duration) -> Self {
66 self.config.polling_interval = interval;
67 self
68 }
69
70 pub fn error_retry_delay(mut self, delay: Duration) -> Self {
71 self.config.error_retry_delay = delay;
72 self
73 }
74
75 pub fn event_channel_capacity(mut self, capacity: usize) -> Self {
76 self.config.event_channel_capacity = capacity;
77 self
78 }
79
80 pub fn state_storage_path(mut self, path: impl Into<PathBuf>) -> Self {
81 self.config.state_storage_path = Some(path.into());
82 self
83 }
84
85 pub fn build(self) -> FunPayConfig {
86 self.config
87 }
88}