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::{CostAllocationPlan, CostAllocationPlanListRequest, PageResponse},
};
pub struct CostAllocationPlanService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct CostAllocationPlanListResponse {
#[serde(flatten)]
pub plans: PageResponse<CostAllocationPlan>,
}
impl ApiResponseTrait for CostAllocationPlanListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl CostAllocationPlanService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn list_plans(
&self,
request: CostAllocationPlanListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<CostAllocationPlanListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: PAYROLL_V1_COST_ALLOCATION_PLANS.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(plan_type) = request.plan_type {
api_req.query_params.insert("plan_type", plan_type);
}
Transport::request(api_req, &self.config, option).await
}
}