use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize, bon::Builder)]
pub struct CompoundFilter {
#[serde(rename = "type")]
pub r#type: Type,
#[serde(rename = "filters")]
pub filters: Vec<models::ComparisonFilter>,
}
impl CompoundFilter {
pub fn new(r#type: Type, filters: Vec<models::ComparisonFilter>) -> CompoundFilter {
CompoundFilter { r#type, filters }
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum Type {
#[serde(rename = "and")]
And,
#[serde(rename = "or")]
Or,
}
impl Default for Type {
fn default() -> Type {
Self::And
}
}
impl std::fmt::Display for CompoundFilter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match serde_json::to_string(self) {
Ok(s) => write!(f, "{}", s),
Err(_) => Err(std::fmt::Error),
}
}
}