use crate::{Id, Predicate, TypedPredicate};
#[derive(Clone, Debug)]
pub enum Filter {
Id(TypedPredicate<Id>),
Type(TypedPredicate<String>),
Created(TypedPredicate<u64>),
LastUpdated(TypedPredicate<u64>),
Field(String, Predicate),
Edge(String, Box<Filter>),
IntoEdge(String),
}
impl Filter {
pub fn where_id<P: Into<TypedPredicate<Id>>>(p: P) -> Self {
Self::Id(p.into())
}
pub fn where_type<P: Into<TypedPredicate<String>>>(p: P) -> Self {
Self::Type(p.into())
}
pub fn where_created<P: Into<TypedPredicate<u64>>>(p: P) -> Self {
Self::Created(p.into())
}
pub fn where_last_updated<P: Into<TypedPredicate<u64>>>(p: P) -> Self {
Self::LastUpdated(p.into())
}
pub fn where_field<S: Into<String>, P: Into<Predicate>>(name: S, p: P) -> Self {
Self::Field(name.into(), p.into())
}
pub fn where_edge<S: Into<String>, F: Into<Filter>>(name: S, filter: F) -> Self {
Self::Edge(name.into(), Box::new(filter.into()))
}
pub fn where_into_edge<S: Into<String>>(name: S) -> Self {
Self::IntoEdge(name.into())
}
}