use reqwest::Method;
use serde_json::json;
use crate::{
core::{
api_resp::BaseResponse, config::Config, constants::AccessTokenType, http::Transport,
req_option::RequestOption, SDKResult,
},
impl_executable_builder_owned,
};
use super::models::{
DelArchiveReportRequest, DelArchiveReportRespData, ListArchiveRulesRequest,
ListArchiveRulesRespData, QueryArchiveStatsFieldsRequest, QueryArchiveStatsFieldsRespData,
UploadArchiveReportRequest, UploadArchiveReportRespData,
};
pub struct ArchiveRuleService {
pub config: Config,
}
impl ArchiveRuleService {
pub async fn query_user_stats_fields(
&self,
request: QueryArchiveStatsFieldsRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<QueryArchiveStatsFieldsRespData>> {
let mut api_req = request.api_req;
api_req.http_method = Method::GET;
api_req.api_path = format!(
"/open-apis/attendance/v1/archive_rules/{}/user_stats_fields",
request.archive_rule_id
);
api_req.supported_access_token_types = vec![AccessTokenType::Tenant];
api_req
.query_params
.insert("employee_type".to_string(), request.employee_type);
let api_resp = Transport::request(api_req, &self.config, option).await?;
Ok(api_resp)
}
pub async fn upload_report(
&self,
request: UploadArchiveReportRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<UploadArchiveReportRespData>> {
let mut api_req = request.api_req;
api_req.http_method = Method::POST;
api_req.api_path = format!(
"/open-apis/attendance/v1/archive_rules/{}/upload_report",
request.archive_rule_id
);
api_req.supported_access_token_types = vec![AccessTokenType::Tenant];
api_req
.query_params
.insert("employee_type".to_string(), request.employee_type);
let body = json!({
"report_data": request.report_data
});
api_req.body = serde_json::to_vec(&body)?;
let api_resp = Transport::request(api_req, &self.config, option).await?;
Ok(api_resp)
}
pub async fn del_report(
&self,
request: DelArchiveReportRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<DelArchiveReportRespData>> {
let mut api_req = request.api_req;
api_req.http_method = Method::POST;
api_req.api_path = format!(
"/open-apis/attendance/v1/archive_rules/{}/del_report",
request.archive_rule_id
);
api_req.supported_access_token_types = vec![AccessTokenType::Tenant];
api_req
.query_params
.insert("employee_type".to_string(), request.employee_type);
let body = json!({
"record_ids": request.record_ids
});
api_req.body = serde_json::to_vec(&body)?;
let api_resp = Transport::request(api_req, &self.config, option).await?;
Ok(api_resp)
}
pub async fn list(
&self,
request: ListArchiveRulesRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<ListArchiveRulesRespData>> {
let mut api_req = request.api_req;
api_req.http_method = Method::GET;
api_req.api_path = "/open-apis/attendance/v1/archive_rules".to_string();
api_req.supported_access_token_types = vec![AccessTokenType::Tenant];
api_req
.query_params
.insert("employee_type".to_string(), request.employee_type);
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);
}
let api_resp = Transport::request(api_req, &self.config, option).await?;
Ok(api_resp)
}
}
impl_executable_builder_owned!(
QueryArchiveStatsFieldsRequest,
ArchiveRuleService,
QueryArchiveStatsFieldsRequest,
BaseResponse<QueryArchiveStatsFieldsRespData>,
query_user_stats_fields
);
impl_executable_builder_owned!(
UploadArchiveReportRequest,
ArchiveRuleService,
UploadArchiveReportRequest,
BaseResponse<UploadArchiveReportRespData>,
upload_report
);
impl_executable_builder_owned!(
DelArchiveReportRequest,
ArchiveRuleService,
DelArchiveReportRequest,
BaseResponse<DelArchiveReportRespData>,
del_report
);
impl_executable_builder_owned!(
ListArchiveRulesRequest,
ArchiveRuleService,
ListArchiveRulesRequest,
BaseResponse<ListArchiveRulesRespData>,
list
);