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::payroll::models::{
CostAllocationReport, CostAllocationReportListRequest, PageResponse,
},
};
pub struct CostAllocationReportService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CostAllocationReportListResponse {
#[serde(flatten)]
pub reports: PageResponse<CostAllocationReport>,
}
impl ApiResponseTrait for CostAllocationReportListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl CostAllocationReportService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn list_reports(
&self,
request: CostAllocationReportListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<CostAllocationReportListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: "/open-apis/payroll/v1/cost_allocation_reports".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(cost_center_id) = request.cost_center_id {
api_req
.query_params
.insert("cost_center_id".to_string(), cost_center_id);
}
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);
}
if let Some(report_type) = request.report_type {
api_req
.query_params
.insert("report_type".to_string(), report_type);
}
Transport::request(api_req, &self.config, option).await
}
}