use crate::{filter::Filter, CompositeCompare, CompositeFieldRef};
use prisma_value::PrismaValue;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CompositeFilter {
pub field: CompositeFieldRef,
pub condition: Box<CompositeCondition>,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum CompositeCondition {
Every(Filter),
Some(Filter),
None(Filter),
Empty(bool),
Equals(PrismaValue),
Is(Filter),
IsNot(Filter),
IsSet(bool),
}
impl CompositeCompare for CompositeFieldRef {
fn every<T>(&self, filter: T) -> Filter
where
T: Into<Filter>,
{
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::Every(filter.into())),
}
.into()
}
fn some<T>(&self, filter: T) -> Filter
where
T: Into<Filter>,
{
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::Some(filter.into())),
}
.into()
}
fn none<T>(&self, filter: T) -> Filter
where
T: Into<Filter>,
{
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::None(filter.into())),
}
.into()
}
fn is<T>(&self, filter: T) -> Filter
where
T: Into<Filter>,
{
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::Is(filter.into())),
}
.into()
}
fn is_not<T>(&self, filter: T) -> Filter
where
T: Into<Filter>,
{
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::IsNot(filter.into())),
}
.into()
}
fn is_empty(&self, b: bool) -> Filter {
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::Empty(b)),
}
.into()
}
fn is_set(&self, b: bool) -> Filter {
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::IsSet(b)),
}
.into()
}
fn equals(&self, val: PrismaValue) -> Filter {
CompositeFilter {
field: self.clone(),
condition: Box::new(CompositeCondition::Equals(val)),
}
.into()
}
}