use super::*;
#[derive(Debug, Clone, PartialEq)]
pub struct EnumFilter<T> {
pub(crate) eq: Option<T>,
pub(crate) ne: Option<T>,
pub(crate) in_: Option<Box<[T]>>,
pub(crate) not_in: Option<Box<[T]>>,
}
impl<T> EnumFilter<T> {
#[inline]
pub const fn new() -> Self {
Self {
eq: None,
ne: None,
in_: None,
not_in: None,
}
}
#[inline]
pub const fn is_empty(&self) -> bool {
self.eq.is_none() && self.ne.is_none() && self.in_.is_none() && self.not_in.is_none()
}
opt_accessor!(eq: T => with_eq, set_eq, maybe_eq, update_eq);
opt_accessor!(ne: T => with_ne, set_ne, maybe_ne, update_ne);
opt_accessor!(in_: [T] => with_in_, set_in_, maybe_in_, update_in_);
opt_accessor!(not_in: [T] => with_not_in, set_not_in, maybe_not_in, update_not_in);
#[inline]
pub const fn is_referential(&self) -> bool {
(self.eq.is_some() ^ self.in_.is_some()) && self.ne.is_none() && self.not_in.is_none()
}
pub fn try_map<U, E, F>(self, mut f: F) -> Result<EnumFilter<U>, E>
where
F: FnMut(T) -> Result<U, E>,
{
Ok(EnumFilter {
eq: map_operand(self.eq, &mut f)?,
ne: map_operand(self.ne, &mut f)?,
in_: map_operands(self.in_, &mut f)?,
not_in: map_operands(self.not_in, &mut f)?,
})
}
}
impl<T> Default for EnumFilter<T> {
#[inline]
fn default() -> Self {
Self::new()
}
}
impl<T, U> TryMapFilter<T, U> for EnumFilter<T> {
type Mapped = EnumFilter<U>;
#[inline]
fn try_map_filter<E, F>(self, f: F) -> Result<Self::Mapped, E>
where
F: FnMut(T) -> Result<U, E>,
{
self.try_map(f)
}
}
impl<T> EqualsFilter<T> for EnumFilter<T> {
#[inline]
fn equals(value: T) -> Self {
Self::new().with_eq(value)
}
}
impl<T> GraphqlFilter for EnumFilter<T> {
#[inline]
fn is_empty(&self) -> bool {
Self::is_empty(self)
}
}
#[cfg(feature = "async-graphql")]
impl<T: async_graphql::InputType> async_graphql::InputType for EnumFilter<T> {
type RawValueType = Self;
fn type_name() -> ::std::borrow::Cow<'static, str> {
::std::borrow::Cow::Owned(::std::format!("{}Filter", T::type_name()))
}
fn create_type_info(registry: &mut async_graphql::registry::Registry) -> ::std::string::String {
registry.create_input_type::<Self, _>(
async_graphql::registry::MetaTypeId::InputObject,
|registry| async_graphql::registry::MetaType::InputObject {
name: ::std::borrow::Cow::into_owned(Self::type_name()),
description: ::std::option::Option::None,
input_fields: <Self as crate::NullableFace>::bare_fields(registry),
visible: ::std::option::Option::None,
inaccessible: false,
tags: ::std::vec::Vec::new(),
rust_typename: ::std::option::Option::Some(::std::any::type_name::<Self>()),
oneof: false,
directive_invocations: ::std::vec::Vec::new(),
},
)
}
fn parse(
value: ::std::option::Option<async_graphql::Value>,
) -> async_graphql::InputValueResult<Self> {
let object = match super::sent(value) {
super::Sent::Longhand(object) => object,
super::Sent::Bare(bare) => {
let mut object = async_graphql::indexmap::IndexMap::new();
object.insert(async_graphql::Name::new("eq"), bare);
object
}
super::Sent::Null => {
return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(
async_graphql::Value::Null,
));
}
super::Sent::Refused(sent) => {
return ::std::result::Result::Err(async_graphql::InputValueError::expected_type(sent));
}
};
::std::result::Result::Ok(Self {
eq: parse_slot::<_, Self>(&object, "eq")?,
ne: parse_slot::<_, Self>(&object, "ne")?,
in_: parse_slot::<_, Self>(&object, "in")?,
not_in: parse_slot::<_, Self>(&object, "notIn")?,
})
}
fn to_value(&self) -> async_graphql::Value {
async_graphql::Value::Object(<Self as crate::NullableFace>::bare_values(self))
}
#[inline]
fn as_raw_value(&self) -> ::std::option::Option<&Self::RawValueType> {
::std::option::Option::Some(self)
}
}
#[cfg(feature = "async-graphql")]
impl<T: async_graphql::InputType> async_graphql::InputObjectType for EnumFilter<T> {}
#[cfg(feature = "async-graphql")]
impl<T: async_graphql::InputType> crate::NullableFace for EnumFilter<T> {
fn bare_fields(
registry: &mut async_graphql::registry::Registry,
) -> async_graphql::indexmap::IndexMap<
::std::string::String,
async_graphql::registry::MetaInputValue,
> {
__ingraph_filter_input_fields!(
registry,
"eq" : ::core::option::Option<T>,
"ne" : ::core::option::Option<T>,
"in" : ::core::option::Option<::std::boxed::Box<[T]>>,
"notIn" : ::core::option::Option<::std::boxed::Box<[T]>>,
)
}
fn bare_values(
&self,
) -> async_graphql::indexmap::IndexMap<async_graphql::Name, async_graphql::Value> {
__ingraph_filter_value_map!(self, "eq" : eq, "ne" : ne, "in" : in_, "notIn" : not_in)
}
}