use openlark_core::config::Config as CoreConfig;
use std::time::Duration;
pub trait LarkClient: Send + Sync {
fn config(&self) -> &CoreConfig;
fn is_configured(&self) -> bool {
!self.config().app_id().is_empty() && !self.config().app_secret().is_empty()
}
fn app_id(&self) -> &str {
self.config().app_id()
}
fn app_secret(&self) -> &str {
self.config().app_secret()
}
fn base_url(&self) -> &str {
self.config().base_url()
}
fn timeout(&self) -> Option<Duration> {
self.config().req_timeout()
}
fn retry_count(&self) -> u32 {
self.config().retry_count()
}
fn is_log_enabled(&self) -> bool {
self.config().enable_log()
}
}
#[cfg(test)]
#[allow(unused_imports)]
mod tests {
use super::*;
use openlark_core::config::Config;
struct TestClient {
config: Config,
}
impl LarkClient for TestClient {
fn config(&self) -> &Config {
&self.config
}
}
#[test]
fn test_lark_client_basic_methods() {
let config = Config::builder()
.app_id("test_app_id")
.app_secret("test_app_secret")
.base_url("https://test.feishu.cn")
.req_timeout(std::time::Duration::from_secs(30))
.retry_count(3)
.enable_log(true)
.build();
let client = TestClient { config };
assert_eq!(client.app_id(), "test_app_id");
assert_eq!(client.app_secret(), "test_app_secret");
assert_eq!(client.base_url(), "https://test.feishu.cn");
assert_eq!(client.timeout(), Some(std::time::Duration::from_secs(30)));
assert_eq!(client.retry_count(), 3);
assert!(client.is_log_enabled());
assert!(client.is_configured());
}
#[test]
fn test_not_configured_client() {
let config = Config::default();
let client = TestClient { config };
assert!(!client.is_configured());
}
}