use url::Url;
use crate::{
errors::OapiError,
pagination::{PaginationOrder, PaginationQuery},
rest::get::{Get, GetNoStream},
vector_stores::VectorStoreFile,
};
#[derive(Debug, Clone, Default)]
pub struct ListVectorStoreBatchFilesRequest<'a> {
pub vector_store_id: &'a str,
pub batch_id: &'a str,
pub pagination: PaginationQuery<'a>,
pub filter: Option<serde_json::Value>,
pub extra_query: Option<std::collections::HashMap<String, String>>,
}
impl Get for ListVectorStoreBatchFilesRequest<'_> {
fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
let mut url =
Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
url.path_segments_mut()
.map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
.push("vector_stores")
.push(self.vector_store_id)
.push("file_batches")
.push(self.batch_id)
.push("files");
let mut touched = false;
{
let mut pairs = url.query_pairs_mut();
if self.pagination.any_set() {
self.pagination.append_to(&mut pairs);
touched = true;
}
if let Some(filter) = &self.filter {
let serialized = serde_json::to_string(filter)
.map_err(|e| OapiError::ResponseError(e.to_string()))?;
pairs.append_pair("filter", &serialized);
touched = true;
}
if let Some(extra_query) = &self.extra_query {
for (key, value) in extra_query {
pairs.append_pair(key, value);
}
touched = true;
}
}
if !touched {
url.set_query(None);
}
Ok(url.to_string())
}
}
impl GetNoStream for ListVectorStoreBatchFilesRequest<'_> {
type Response = crate::vector_stores::files::ListVectorStoreFilesResponse;
}