use crate::PlatformConfig;
use openlark_core::{SDKResult, error::business_error, req_option::RequestOption};
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct UsersApi {
config: Arc<PlatformConfig>,
}
impl UsersApi {
pub fn new(config: Arc<PlatformConfig>) -> Self {
Self { config }
}
pub fn list(&self) -> ListAdminUsersRequest {
ListAdminUsersRequest::new(self.config.clone())
}
pub fn disable(&self) -> DisableUserRequest {
DisableUserRequest::new(self.config.clone())
}
pub fn enable(&self) -> EnableUserRequest {
EnableUserRequest::new(self.config.clone())
}
}
pub struct ListAdminUsersRequest {
_config: Arc<PlatformConfig>,
page_size: Option<u32>,
}
impl ListAdminUsersRequest {
fn new(config: Arc<PlatformConfig>) -> Self {
Self {
_config: config,
page_size: None,
}
}
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.users.list: openlark-platform 尚未接入该 facade,请改用已实现的 admin_user_stat.list 等真实端点",
))
}
}
pub struct DisableUserRequest {
_config: Arc<PlatformConfig>,
user_id: Option<String>,
}
impl DisableUserRequest {
fn new(config: Arc<PlatformConfig>) -> Self {
Self {
_config: config,
user_id: None,
}
}
pub fn user_id(mut self, user_id: impl Into<String>) -> Self {
self.user_id = Some(user_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.users.disable: openlark-platform 尚未接入该 facade,请等待后续真实端点支持",
))
}
}
pub struct EnableUserRequest {
_config: Arc<PlatformConfig>,
user_id: Option<String>,
}
impl EnableUserRequest {
fn new(config: Arc<PlatformConfig>) -> Self {
Self {
_config: config,
user_id: None,
}
}
pub fn user_id(mut self, user_id: impl Into<String>) -> Self {
self.user_id = Some(user_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.users.enable: openlark-platform 尚未接入该 facade,请等待后续真实端点支持",
))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_users_stub_returns_explicit_error() {
let config = Arc::new(PlatformConfig::default());
let err = UsersApi::new(config)
.list()
.page_size(20)
.execute()
.await
.expect_err("users stub should now fail explicitly");
assert!(err.to_string().contains("尚未接入"));
}
}