Skip to main content

systemprompt_sync/
config.rs

1//! Sync configuration: the [`SyncConfig`] value passed to
2//! [`crate::SyncService`] and its [`SyncConfigBuilder`].
3
4use systemprompt_identifiers::TenantId;
5
6use crate::SyncDirection;
7
8#[derive(Clone, Debug)]
9pub struct SyncConfig {
10    pub direction: SyncDirection,
11    pub dry_run: bool,
12    pub verbose: bool,
13    pub tenant_id: TenantId,
14    pub api_url: String,
15    pub api_token: String,
16    pub services_path: String,
17    pub hostname: Option<String>,
18    pub sync_token: Option<String>,
19    pub local_database_url: Option<String>,
20}
21
22#[derive(Debug)]
23pub struct SyncConfigBuilder {
24    direction: SyncDirection,
25    dry_run: bool,
26    verbose: bool,
27    tenant_id: TenantId,
28    api_url: String,
29    api_token: String,
30    services_path: String,
31    hostname: Option<String>,
32    sync_token: Option<String>,
33    local_database_url: Option<String>,
34}
35
36impl SyncConfigBuilder {
37    pub fn new(
38        tenant_id: impl Into<TenantId>,
39        api_url: impl Into<String>,
40        api_token: impl Into<String>,
41        services_path: impl Into<String>,
42    ) -> Self {
43        Self {
44            direction: SyncDirection::Push,
45            dry_run: false,
46            verbose: false,
47            tenant_id: tenant_id.into(),
48            api_url: api_url.into(),
49            api_token: api_token.into(),
50            services_path: services_path.into(),
51            hostname: None,
52            sync_token: None,
53            local_database_url: None,
54        }
55    }
56
57    pub const fn with_direction(mut self, direction: SyncDirection) -> Self {
58        self.direction = direction;
59        self
60    }
61
62    pub const fn with_dry_run(mut self, dry_run: bool) -> Self {
63        self.dry_run = dry_run;
64        self
65    }
66
67    pub const fn with_verbose(mut self, verbose: bool) -> Self {
68        self.verbose = verbose;
69        self
70    }
71
72    pub fn with_hostname(mut self, hostname: Option<String>) -> Self {
73        self.hostname = hostname;
74        self
75    }
76
77    pub fn with_sync_token(mut self, sync_token: Option<String>) -> Self {
78        self.sync_token = sync_token;
79        self
80    }
81
82    pub fn with_local_database_url(mut self, url: impl Into<String>) -> Self {
83        self.local_database_url = Some(url.into());
84        self
85    }
86
87    pub fn build(self) -> SyncConfig {
88        SyncConfig {
89            direction: self.direction,
90            dry_run: self.dry_run,
91            verbose: self.verbose,
92            tenant_id: self.tenant_id,
93            api_url: self.api_url,
94            api_token: self.api_token,
95            services_path: self.services_path,
96            hostname: self.hostname,
97            sync_token: self.sync_token,
98            local_database_url: self.local_database_url,
99        }
100    }
101}
102
103impl SyncConfig {
104    pub fn builder(
105        tenant_id: impl Into<TenantId>,
106        api_url: impl Into<String>,
107        api_token: impl Into<String>,
108        services_path: impl Into<String>,
109    ) -> SyncConfigBuilder {
110        SyncConfigBuilder::new(tenant_id, api_url, api_token, services_path)
111    }
112}