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::{AttachmentDownloadResponse, EmployeeAttachmentRequest},
};
pub struct AttachmentService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EmployeeAttachmentDownloadResponse {
#[serde(flatten)]
pub attachment: AttachmentDownloadResponse,
}
impl ApiResponseTrait for EmployeeAttachmentDownloadResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl AttachmentService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn download_attachment(
&self,
request: EmployeeAttachmentRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<EmployeeAttachmentDownloadResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: format!(
"/open-apis/ehr/v1/employees/{}/attachments/{}",
request.employee_id, request.attachment_id
),
supported_access_token_types: vec![AccessTokenType::Tenant],
body: vec![],
..Default::default()
};
if let Some(user_id_type) = request.user_id_type {
api_req.query_params.insert("user_id_type", user_id_type);
}
Transport::request(api_req, &self.config, option).await
}
}