use openlark_core::config::Config;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct DocsClient {
config: Arc<Config>,
#[cfg(feature = "ccm-core")]
pub ccm: CcmClient,
#[cfg(any(feature = "base", feature = "bitable"))]
pub base: BaseClient,
#[cfg(any(feature = "baike", feature = "lingo"))]
pub baike: BaikeClient,
#[cfg(feature = "minutes")]
pub minutes: MinutesClient,
}
impl DocsClient {
pub fn new(config: Config) -> Self {
let config = Arc::new(config);
Self {
config: config.clone(),
#[cfg(feature = "ccm-core")]
ccm: CcmClient::new(config.clone()),
#[cfg(any(feature = "base", feature = "bitable"))]
base: BaseClient::new(config.clone()),
#[cfg(any(feature = "baike", feature = "lingo"))]
baike: BaikeClient::new(config.clone()),
#[cfg(feature = "minutes")]
minutes: MinutesClient::new(config),
}
}
pub fn config(&self) -> &Config {
&self.config
}
}
#[cfg(feature = "ccm-core")]
#[derive(Debug, Clone)]
pub struct CcmClient {
config: Arc<Config>,
}
#[cfg(feature = "ccm-core")]
impl CcmClient {
fn new(config: Arc<Config>) -> Self {
Self { config }
}
pub fn config(&self) -> &Config {
&self.config
}
}
#[cfg(any(feature = "base", feature = "bitable"))]
#[derive(Debug, Clone)]
pub struct BaseClient {
config: Arc<Config>,
}
#[cfg(any(feature = "base", feature = "bitable"))]
impl BaseClient {
fn new(config: Arc<Config>) -> Self {
Self { config }
}
pub fn config(&self) -> &Config {
&self.config
}
#[cfg(feature = "bitable")]
pub fn bitable(&self) -> BitableClient {
BitableClient::new(self.config.clone())
}
}
#[cfg(feature = "bitable")]
#[derive(Debug, Clone)]
pub struct BitableClient {
config: Arc<Config>,
}
#[cfg(feature = "bitable")]
impl BitableClient {
fn new(config: Arc<Config>) -> Self {
Self { config }
}
pub fn config(&self) -> &Config {
&self.config
}
}
#[cfg(any(feature = "baike", feature = "lingo"))]
#[derive(Debug, Clone)]
pub struct BaikeClient {
config: Arc<Config>,
}
#[cfg(any(feature = "baike", feature = "lingo"))]
impl BaikeClient {
fn new(config: Arc<Config>) -> Self {
Self { config }
}
pub fn config(&self) -> &Config {
&self.config
}
}
#[cfg(feature = "minutes")]
#[derive(Debug, Clone)]
pub struct MinutesClient {
config: Arc<Config>,
}
#[cfg(feature = "minutes")]
impl MinutesClient {
fn new(config: Arc<Config>) -> Self {
Self { config }
}
pub fn config(&self) -> &Config {
&self.config
}
}
#[cfg(test)]
mod tests {
use serde_json;
#[test]
fn test_serialization_roundtrip() {
let json = r#"{"test": "value"}"#;
assert!(serde_json::from_str::<serde_json::Value>(json).is_ok());
}
#[test]
fn test_deserialization_from_json() {
let json = r#"{"field": "data"}"#;
let value: serde_json::Value = serde_json::from_str(json).unwrap();
assert_eq!(value["field"], "data");
}
}