use serde::{Deserialize, Serialize};
use validator::Validate;
use super::types::BatchItem;
use crate::{ZaiResult, client::ZaiClient};
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct BatchesListQuery {
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[validate(range(min = 1, max = 100))]
pub limit: Option<u32>,
}
impl Default for BatchesListQuery {
fn default() -> Self {
Self::new()
}
}
impl BatchesListQuery {
pub fn new() -> Self {
Self {
after: None,
limit: None,
}
}
pub fn with_after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
pub fn with_limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
pub struct BatchesListRequest {
query: BatchesListQuery,
}
impl BatchesListRequest {
pub fn new() -> Self {
Self {
query: BatchesListQuery::new(),
}
}
pub fn with_query(mut self, q: BatchesListQuery) -> Self {
self.query = q;
self
}
pub async fn send_via(&self, client: &ZaiClient) -> ZaiResult<BatchesListResponse> {
let mut params: Vec<(&str, String)> = Vec::new();
if let Some(after) = self.query.after.as_ref() {
params.push(("after", after.clone()));
}
if let Some(limit) = self.query.limit.as_ref() {
params.push(("limit", limit.to_string()));
}
let borrowed: Vec<(&str, &str)> = params.iter().map(|(k, v)| (*k, v.as_str())).collect();
let route = crate::client::routes::BATCHES_LIST;
let url = client
.endpoints()
.resolve_route_with_query(route, &[], &borrowed)?;
client
.send_empty::<BatchesListResponse>(route.method(), url)
.await
}
}
impl Default for BatchesListRequest {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct BatchesListResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<ListObject>,
#[serde(skip_serializing_if = "Option::is_none")]
pub data: Option<Vec<BatchItem>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub first_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub has_more: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ListObject {
List,
}