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::ehr::models::{Employee, EmployeeListRequest, PageResponse},
};
pub struct EmployeeService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EmployeeListResponse {
#[serde(flatten)]
pub employees: PageResponse<Employee>,
}
impl ApiResponseTrait for EmployeeListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl EmployeeService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn list_employees(
&self,
request: EmployeeListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<EmployeeListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: "/open-apis/ehr/v1/employees".to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
if let Some(page_size) = request.page_size {
api_req
.query_params
.insert("page_size", page_size.to_string());
}
if let Some(page_token) = request.page_token {
api_req.query_params.insert("page_token", page_token);
}
if let Some(status) = request.status {
api_req.query_params.insert("status", status);
}
if let Some(department_id) = request.department_id {
api_req.query_params.insert("department_id", department_id);
}
if let Some(user_id_type) = request.user_id_type {
api_req.query_params.insert("user_id_type", user_id_type);
}
if let Some(department_id_type) = request.department_id_type {
api_req
.query_params
.insert("department_id_type", department_id_type);
}
if let Some(include_resigned) = request.include_resigned {
api_req
.query_params
.insert("include_resigned", include_resigned.to_string());
}
if let Some(fields) = request.fields {
if !fields.is_empty() {
api_req.query_params.insert("fields", fields.join(","));
}
}
Transport::request(api_req, &self.config, option).await
}
}