use crate::collections::objects::Object;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct BatchDeleteRequest {
#[serde(rename = "match")]
pub matches: MatchConfig,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub output: Option<Verbosity>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub dry_run: Option<bool>,
}
impl BatchDeleteRequest {
pub fn builder(matches: MatchConfig) -> BatchDeleteRequestBuilder {
BatchDeleteRequestBuilder::new(matches)
}
}
pub struct BatchDeleteRequestBuilder {
pub matches: MatchConfig,
pub output: Option<Verbosity>,
pub dry_run: Option<bool>,
}
impl BatchDeleteRequestBuilder {
pub fn new(matches: MatchConfig) -> BatchDeleteRequestBuilder {
BatchDeleteRequestBuilder {
matches,
output: None,
dry_run: None,
}
}
pub fn with_output(mut self, output: Verbosity) -> BatchDeleteRequestBuilder {
self.output = Some(output);
self
}
pub fn with_dry_run(mut self, dry_run: bool) -> BatchDeleteRequestBuilder {
self.dry_run = Some(dry_run);
self
}
pub fn build(self) -> BatchDeleteRequest {
BatchDeleteRequest {
matches: self.matches,
output: self.output,
dry_run: self.dry_run,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct MatchConfig {
pub class: String,
#[serde(rename = "where")]
pub match_where: serde_json::Value,
}
impl MatchConfig {
pub fn new(class: &str, match_where: serde_json::Value) -> MatchConfig {
MatchConfig {
class: class.into(),
match_where,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub enum Verbosity {
#[serde(rename = "minimal")]
MINIMAL,
#[serde(rename = "verbose")]
VERBOSE,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct BatchDeleteResponse {
#[serde(rename = "match")]
pub matches: MatchConfig,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub output: Option<Verbosity>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub dry_run: Option<bool>,
pub results: BatchDeleteResult,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchDeleteResult {
pub matches: u64,
pub limit: u64,
pub successful: u64,
pub failed: u64,
#[serde(default)]
pub objects: Option<DeleteObjects>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct DeleteObjects(Vec<DeleteObject>);
#[derive(Serialize, Deserialize, Debug)]
pub struct DeleteObject {
pub id: Uuid,
pub status: GeneralStatus,
#[serde(default)]
pub errors: Option<BatchRequestErrors>,
}
#[derive(Serialize, Deserialize, Debug)]
pub enum GeneralStatus {
SUCCESS,
FAILED,
DRYRUN,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ResultStatus {
pub status: GeneralStatus,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchRequestErrors {
pub error: ErrorMessages,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ErrorMessages(Vec<ErrorMessage>);
#[derive(Serialize, Deserialize, Debug)]
pub struct ErrorMessage {
pub message: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchAddObjects(Vec<BatchAddObject>);
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct BatchAddObject {
pub class: String,
pub properties: serde_json::Value,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub id: Option<Uuid>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub vector: Option<Vec<f64>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub tenant: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub creation_time_unix: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub last_update_time_unix: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
pub vector_weights: Option<u64>,
pub result: ResultStatus,
}
impl BatchAddObject {
pub fn to_object(self) -> Object {
Object {
class: self.class,
properties: self.properties,
id: self.id,
vector: self.vector,
tenant: self.tenant,
creation_time_unix: self.creation_time_unix,
last_update_time_unix: self.last_update_time_unix,
vector_weights: self.vector_weights,
additional: None,
}
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchAddReferencesResponse(pub Vec<BatchAddReferenceResponse>);
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchAddReferenceResponse {
result: BatchAddReferenceResult,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BatchAddReferenceResult {
pub status: GeneralStatus,
#[serde(default)]
pub errors: Option<BatchRequestErrors>,
}