use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{
core::{
api_req::ApiRequest,
api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
config::Config,
constants::AccessTokenType,
endpoints::payroll::*,
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: 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", request.start_date);
api_req.query_params.insert("end_date", request.end_date);
if let Some(cost_center_id) = request.cost_center_id {
api_req
.query_params
.insert("cost_center_id", cost_center_id);
}
if let Some(department_id) = request.department_id {
api_req.query_params.insert("department_id", department_id);
}
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(report_type) = request.report_type {
api_req.query_params.insert("report_type", report_type);
}
Transport::request(api_req, &self.config, option).await
}
}