use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{
core::{
api_req::ApiRequest,
api_resp::{ApiResponseTrait, BaseResponse, ResponseFormat},
config::Config,
constants::AccessTokenType,
endpoints::LINGO_CLASSIFICATION_LIST,
http::Transport,
req_option::RequestOption,
trait_system::AsyncServiceOperation,
SDKResult,
},
impl_basic_service, impl_service_constructor,
service::lingo::models::{Classification, PageResponse},
};
#[derive(Debug, Clone)]
pub struct ClassificationService {
pub config: Config,
}
impl ClassificationService {
pub async fn list_classifications(
&self,
request: ClassificationListRequest,
option: Option<RequestOption>,
) -> SDKResult<BaseResponse<ClassificationListResponse>> {
<Self as AsyncServiceOperation<
ClassificationListRequest,
BaseResponse<ClassificationListResponse>,
>>::execute_with_observability(self, "list_classifications", || async {
let mut api_req = ApiRequest {
http_method: Method::GET,
api_path: LINGO_CLASSIFICATION_LIST.to_string(),
supported_access_token_types: vec![AccessTokenType::Tenant, AccessTokenType::User],
body: vec![],
..Default::default()
};
if let Some(page_token) = request.page_token {
api_req.query_params.insert("page_token", page_token);
}
if let Some(page_size) = request.page_size {
api_req
.query_params
.insert("page_size", page_size.to_string());
}
if let Some(repo_id) = request.repo_id {
api_req.query_params.insert("repo_id", repo_id);
}
Transport::request(api_req, &self.config, option).await
})
.await
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ClassificationListRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub page_token: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub page_size: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub repo_id: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ClassificationListResponse {
#[serde(flatten)]
pub classifications: PageResponse<Classification>,
}
impl ApiResponseTrait for ClassificationListResponse {
fn data_format() -> ResponseFormat {
ResponseFormat::Data
}
}
impl_basic_service!(ClassificationService, "lingo.classification", "v1");
impl_service_constructor!(ClassificationService);
impl AsyncServiceOperation<ClassificationListRequest, BaseResponse<ClassificationListResponse>>
for ClassificationService
{
}