1use crate::error::{LighterError, Result};
2use url::Url;
3
4#[derive(Debug, Clone)]
5pub struct Config {
6 pub base_url: Url,
7 pub ws_url: Url,
8 pub api_key: Option<String>,
9 pub timeout_secs: u64,
10 pub max_retries: u32,
11}
12
13impl Config {
14 pub fn new() -> Self {
15 Self::default()
16 }
17
18 pub fn with_api_key<S: Into<String>>(mut self, api_key: S) -> Self {
19 self.api_key = Some(api_key.into());
20 self
21 }
22
23 pub fn with_base_url<S: AsRef<str>>(mut self, url: S) -> Result<Self> {
24 self.base_url = Url::parse(url.as_ref())
25 .map_err(|e| LighterError::Config(format!("Invalid base URL: {}", e)))?;
26 Ok(self)
27 }
28
29 pub fn with_ws_url<S: AsRef<str>>(mut self, url: S) -> Result<Self> {
30 self.ws_url = Url::parse(url.as_ref())
31 .map_err(|e| LighterError::Config(format!("Invalid WebSocket URL: {}", e)))?;
32 Ok(self)
33 }
34
35 pub fn with_timeout(mut self, timeout_secs: u64) -> Self {
36 self.timeout_secs = timeout_secs;
37 self
38 }
39
40 pub fn with_max_retries(mut self, max_retries: u32) -> Self {
41 self.max_retries = max_retries;
42 self
43 }
44}
45
46impl Default for Config {
47 fn default() -> Self {
48 Self {
49 base_url: Url::parse("https://api.lighter.xyz").unwrap(),
50 ws_url: Url::parse("wss://ws.lighter.xyz").unwrap(),
51 api_key: None,
52 timeout_secs: 30,
53 max_retries: 3,
54 }
55 }
56}