use crate::PlatformConfig;
use openlark_core::{SDKResult, error::business_error, req_option::RequestOption};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct AuditApi {
config: Arc<PlatformConfig>,
}
impl AuditApi {
pub fn new(config: Arc<PlatformConfig>) -> Self {
Self { config }
}
pub fn query(&self) -> QueryAuditLogsRequest {
QueryAuditLogsRequest::new(self.config.clone())
}
pub fn get(&self) -> GetAuditLogRequest {
GetAuditLogRequest::new(self.config.clone())
}
}
pub struct QueryAuditLogsRequest {
_config: Arc<PlatformConfig>,
start_time: Option<String>,
end_time: Option<String>,
page_size: Option<u32>,
}
impl QueryAuditLogsRequest {
fn new(config: Arc<PlatformConfig>) -> Self {
Self {
_config: config,
start_time: None,
end_time: None,
page_size: None,
}
}
pub fn start_time(mut self, time: impl Into<String>) -> Self {
self.start_time = Some(time.into());
self
}
pub fn end_time(mut self, time: impl Into<String>) -> Self {
self.end_time = Some(time.into());
self
}
pub fn page_size(mut self, size: u32) -> Self {
self.page_size = Some(size);
self
}
pub async fn execute(self) -> SDKResult<serde_json::Value> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
_option: RequestOption,
) -> SDKResult<serde_json::Value> {
Err(business_error(
"admin.audit.query: openlark-platform 尚未接入该 facade,请改用已实现的 admin.audit_info.list 等真实端点",
))
}
}
pub struct GetAuditLogRequest {
_config: Arc<PlatformConfig>,
log_id: Option<String>,
}
impl GetAuditLogRequest {
fn new(config: Arc<PlatformConfig>) -> Self {
Self {
_config: config,
log_id: None,
}
}
pub fn log_id(mut self, log_id: impl Into<String>) -> Self {
self.log_id = Some(log_id.into());
self
}
pub async fn execute(self) -> SDKResult<serde_json::Value> {
self.execute_with_options(RequestOption::default()).await
}
pub async fn execute_with_options(
self,
_option: RequestOption,
) -> SDKResult<serde_json::Value> {
Err(business_error(
"admin.audit.get: openlark-platform 尚未接入该 facade,请改用已实现的 admin.audit_info.list 等真实端点",
))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_audit_stub_returns_explicit_error() {
let config = Arc::new(PlatformConfig::default());
let err = AuditApi::new(config)
.query()
.start_time("2026-01-01")
.end_time("2026-01-31")
.execute()
.await
.expect_err("audit stub should now fail explicitly");
assert!(err.to_string().contains("尚未接入"));
}
}