use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{
core::{
api_req::ApiRequest,
api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
config::Config,
constants::AccessTokenType,
http::Transport,
req_option::RequestOption,
SDKResult,
},
service::admin::models::{
DataReport, DepartmentDataReportRequest, PageResponse, UserDataReportRequest,
},
};
pub struct DataReportService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct DepartmentDataReportResponse {
#[serde(flatten)]
pub page_response: PageResponse<DataReport>,
}
impl ApiResponseTrait for DepartmentDataReportResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UserDataReportResponse {
#[serde(flatten)]
pub page_response: PageResponse<DataReport>,
}
impl ApiResponseTrait for UserDataReportResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl DataReportService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn get_department_data_report(
&self,
request: DepartmentDataReportRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<DepartmentDataReportResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: "/open-apis/admin/v1/data_report/department".to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
api_req
.query_params
.insert("start_date".to_string(), request.start_date);
api_req
.query_params
.insert("end_date".to_string(), request.end_date);
if let Some(department_id_type) = request.department_id_type {
api_req
.query_params
.insert("department_id_type".to_string(), department_id_type);
}
if let Some(department_id) = request.department_id {
api_req
.query_params
.insert("department_id".to_string(), department_id);
}
if let Some(page_size) = request.page_size {
api_req
.query_params
.insert("page_size".to_string(), page_size.to_string());
}
if let Some(page_token) = request.page_token {
api_req
.query_params
.insert("page_token".to_string(), page_token);
}
Transport::request(api_req, &self.config, option).await
}
pub async fn get_user_data_report(
&self,
request: UserDataReportRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<UserDataReportResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: "/open-apis/admin/v1/data_report/user".to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
api_req
.query_params
.insert("start_date".to_string(), request.start_date);
api_req
.query_params
.insert("end_date".to_string(), request.end_date);
if let Some(user_id_type) = request.user_id_type {
api_req
.query_params
.insert("user_id_type".to_string(), user_id_type);
}
if let Some(user_ids) = request.user_ids {
api_req
.query_params
.insert("user_ids".to_string(), user_ids.join(","));
}
if let Some(department_id_type) = request.department_id_type {
api_req
.query_params
.insert("department_id_type".to_string(), department_id_type);
}
if let Some(department_id) = request.department_id {
api_req
.query_params
.insert("department_id".to_string(), department_id);
}
if let Some(page_size) = request.page_size {
api_req
.query_params
.insert("page_size".to_string(), page_size.to_string());
}
if let Some(page_token) = request.page_token {
api_req
.query_params
.insert("page_token".to_string(), page_token);
}
Transport::request(api_req, &self.config, option).await
}
}