use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
use validator::Validate;
use crate::ZaiResult;
use crate::client::ZaiClient;
#[derive(Debug, Clone, Serialize, Deserialize, Validate, Default)]
pub struct DocumentReembeddingBody {
#[serde(skip_serializing_if = "Option::is_none")]
#[validate(url)]
pub callback_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub callback_header: Option<BTreeMap<String, String>>,
}
pub struct DocumentReembeddingRequest {
document_id: String,
body: DocumentReembeddingBody,
}
impl DocumentReembeddingRequest {
pub fn new(document_id: impl Into<String>) -> Self {
Self {
document_id: document_id.into(),
body: DocumentReembeddingBody::default(),
}
}
pub fn with_callback_url(mut self, url: impl Into<String>) -> Self {
self.body.callback_url = Some(url.into());
self
}
pub fn with_callback_header(mut self, hdr: BTreeMap<String, String>) -> Self {
self.body.callback_header = Some(hdr);
self
}
pub async fn send_via(&self, client: &ZaiClient) -> ZaiResult<DocumentReembeddingResponse> {
self.body.validate()?;
let route = crate::client::routes::DOCUMENTS_REEMBED;
let url = client
.endpoints()
.resolve_route(route, &[&self.document_id])?;
client
.send_json::<_, DocumentReembeddingResponse>(route.method(), url, &self.body)
.await
}
}
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
pub struct DocumentReembeddingResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub code: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub message: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamp: Option<u64>,
}