use std::time::Duration;
#[derive(Debug, Clone)]
pub struct Config {
pub api_base_url: String,
pub api_key: String,
pub product_slug: String,
pub storage_prefix: String,
pub device_identifier: Option<String>,
pub auto_validate_interval: Duration,
pub heartbeat_interval: Duration,
pub network_recheck_interval: Duration,
pub max_retries: u32,
pub retry_delay: Duration,
pub offline_fallback_mode: OfflineFallbackMode,
pub offline_token_refresh_interval: Duration,
pub max_offline_days: u32,
pub max_clock_skew: Duration,
pub telemetry_enabled: bool,
pub debug: bool,
pub app_version: Option<String>,
pub app_build: Option<String>,
}
impl Default for Config {
fn default() -> Self {
Self {
api_base_url: "https://licenseseat.com/api/v1".into(),
api_key: String::new(),
product_slug: String::new(),
storage_prefix: "licenseseat_".into(),
device_identifier: None,
auto_validate_interval: Duration::from_secs(3600), heartbeat_interval: Duration::from_secs(300), network_recheck_interval: Duration::from_secs(30),
max_retries: 3,
retry_delay: Duration::from_secs(1),
offline_fallback_mode: OfflineFallbackMode::NetworkOnly,
offline_token_refresh_interval: Duration::from_secs(72 * 3600), max_offline_days: 0,
max_clock_skew: Duration::from_secs(300), telemetry_enabled: true,
debug: false,
app_version: None,
app_build: None,
}
}
}
impl Config {
pub fn new(api_key: impl Into<String>, product_slug: impl Into<String>) -> Self {
Self {
api_key: api_key.into(),
product_slug: product_slug.into(),
..Default::default()
}
}
pub fn with_debug(mut self, debug: bool) -> Self {
self.debug = debug;
self
}
pub fn with_auto_validate_interval(mut self, interval: Duration) -> Self {
self.auto_validate_interval = interval;
self
}
pub fn with_offline_fallback(mut self, mode: OfflineFallbackMode) -> Self {
self.offline_fallback_mode = mode;
self
}
pub fn with_max_offline_days(mut self, days: u32) -> Self {
self.max_offline_days = days;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum OfflineFallbackMode {
#[default]
NetworkOnly,
Always,
}