1use url::Url;
4
5#[derive(Debug, Clone, Default)]
7pub enum Environment {
8 #[default]
10 Sandbox,
11 Production,
13 Custom(Url),
15}
16
17impl Environment {
18 pub fn base_url(&self) -> Url {
20 match self {
21 Environment::Sandbox => {
22 Url::parse("https://api.sandbox.noah.com/v1").expect("Invalid sandbox URL")
23 }
24 Environment::Production => {
25 Url::parse("https://api.noah.com/v1").expect("Invalid production URL")
26 }
27 Environment::Custom(url) => url.clone(),
28 }
29 }
30}
31
32#[derive(Debug, Clone)]
34pub struct Config {
35 pub base_url: Url,
37 pub timeout_secs: u64,
39 pub user_agent: String,
41 pub enable_logging: bool,
43}
44
45impl Config {
46 pub fn new(environment: Environment) -> Self {
48 Self {
49 base_url: environment.base_url(),
50 timeout_secs: 30,
51 user_agent: format!("noah-sdk/{}", env!("CARGO_PKG_VERSION")),
52 enable_logging: false,
53 }
54 }
55
56 pub fn with_timeout(mut self, timeout_secs: u64) -> Self {
58 self.timeout_secs = timeout_secs;
59 self
60 }
61
62 pub fn with_user_agent(mut self, user_agent: String) -> Self {
64 self.user_agent = user_agent;
65 self
66 }
67
68 pub fn with_logging(mut self, enable: bool) -> Self {
70 self.enable_logging = enable;
71 self
72 }
73}
74
75impl Default for Config {
76 fn default() -> Self {
77 Self::new(Environment::default())
78 }
79}