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::{AcctItem, AcctItemListRequest, PageResponse},
};
pub struct AcctItemService {
pub config: Config,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AcctItemListResponse {
#[serde(flatten)]
pub acct_items: PageResponse<AcctItem>,
}
impl ApiResponseTrait for AcctItemListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl AcctItemService {
pub fn new(config: Config) -> Self {
Self { config }
}
pub async fn list_acct_items(
&self,
request: AcctItemListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<AcctItemListResponse>> {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: PAYROLL_V1_ACCT_ITEMS.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(item_type) = request.item_type {
api_req.query_params.insert("item_type", item_type);
}
if let Some(paygroup_id) = request.paygroup_id {
api_req.query_params.insert("paygroup_id", paygroup_id);
}
if let Some(status) = request.status {
api_req.query_params.insert("status", status);
}
Transport::request(api_req, &self.config, option).await
}
}