use conjure_object::serde::{ser, de};
use conjure_object::serde::ser::SerializeMap as SerializeMap_;
use conjure_object::private::{UnionField_, UnionTypeField_};
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SearchNotebooksQuery {
And(Vec<super::SearchNotebooksQuery>),
Or(Vec<super::SearchNotebooksQuery>),
Not(Box<super::SearchNotebooksQuery>),
ExactMatch(String),
SearchText(String),
#[deprecated(note = "use labels")]
Label(super::super::super::super::api::Label),
Labels(super::super::super::rids::api::LabelsFilter),
#[deprecated(note = "use properties")]
Property(super::super::super::super::api::Property),
Properties(super::super::super::rids::api::PropertiesFilter),
#[deprecated(note = "use assetRids")]
AssetRid(super::super::super::rids::api::AssetRid),
AssetRids(super::AssetsFilter),
ExactAssetRids(std::collections::BTreeSet<super::super::super::rids::api::AssetRid>),
AuthorRid(super::super::super::rids::api::UserRid),
#[deprecated(note = "use runRids")]
RunRid(super::super::super::run::api::RunRid),
RunRids(super::RunsFilter),
#[deprecated(note = "use notebook types")]
NotebookType(super::NotebookType),
NotebookTypes(super::NotebookTypesFilter),
DraftState(bool),
Archived(bool),
Workspace(super::super::super::super::api::rids::WorkspaceRid),
AuthorIsCurrentUser(bool),
AuthorRids(std::collections::BTreeSet<super::super::super::rids::api::UserRid>),
Unknown(Unknown),
}
impl ser::Serialize for SearchNotebooksQuery {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where
S: ser::Serializer,
{
let mut map = s.serialize_map(Some(2))?;
match self {
SearchNotebooksQuery::And(value) => {
map.serialize_entry(&"type", &"and")?;
map.serialize_entry(&"and", value)?;
}
SearchNotebooksQuery::Or(value) => {
map.serialize_entry(&"type", &"or")?;
map.serialize_entry(&"or", value)?;
}
SearchNotebooksQuery::Not(value) => {
map.serialize_entry(&"type", &"not")?;
map.serialize_entry(&"not", value)?;
}
SearchNotebooksQuery::ExactMatch(value) => {
map.serialize_entry(&"type", &"exactMatch")?;
map.serialize_entry(&"exactMatch", value)?;
}
SearchNotebooksQuery::SearchText(value) => {
map.serialize_entry(&"type", &"searchText")?;
map.serialize_entry(&"searchText", value)?;
}
#[allow(deprecated)]
SearchNotebooksQuery::Label(value) => {
map.serialize_entry(&"type", &"label")?;
map.serialize_entry(&"label", value)?;
}
SearchNotebooksQuery::Labels(value) => {
map.serialize_entry(&"type", &"labels")?;
map.serialize_entry(&"labels", value)?;
}
#[allow(deprecated)]
SearchNotebooksQuery::Property(value) => {
map.serialize_entry(&"type", &"property")?;
map.serialize_entry(&"property", value)?;
}
SearchNotebooksQuery::Properties(value) => {
map.serialize_entry(&"type", &"properties")?;
map.serialize_entry(&"properties", value)?;
}
#[allow(deprecated)]
SearchNotebooksQuery::AssetRid(value) => {
map.serialize_entry(&"type", &"assetRid")?;
map.serialize_entry(&"assetRid", value)?;
}
SearchNotebooksQuery::AssetRids(value) => {
map.serialize_entry(&"type", &"assetRids")?;
map.serialize_entry(&"assetRids", value)?;
}
SearchNotebooksQuery::ExactAssetRids(value) => {
map.serialize_entry(&"type", &"exactAssetRids")?;
map.serialize_entry(&"exactAssetRids", value)?;
}
SearchNotebooksQuery::AuthorRid(value) => {
map.serialize_entry(&"type", &"authorRid")?;
map.serialize_entry(&"authorRid", value)?;
}
#[allow(deprecated)]
SearchNotebooksQuery::RunRid(value) => {
map.serialize_entry(&"type", &"runRid")?;
map.serialize_entry(&"runRid", value)?;
}
SearchNotebooksQuery::RunRids(value) => {
map.serialize_entry(&"type", &"runRids")?;
map.serialize_entry(&"runRids", value)?;
}
#[allow(deprecated)]
SearchNotebooksQuery::NotebookType(value) => {
map.serialize_entry(&"type", &"notebookType")?;
map.serialize_entry(&"notebookType", value)?;
}
SearchNotebooksQuery::NotebookTypes(value) => {
map.serialize_entry(&"type", &"notebookTypes")?;
map.serialize_entry(&"notebookTypes", value)?;
}
SearchNotebooksQuery::DraftState(value) => {
map.serialize_entry(&"type", &"draftState")?;
map.serialize_entry(&"draftState", value)?;
}
SearchNotebooksQuery::Archived(value) => {
map.serialize_entry(&"type", &"archived")?;
map.serialize_entry(&"archived", value)?;
}
SearchNotebooksQuery::Workspace(value) => {
map.serialize_entry(&"type", &"workspace")?;
map.serialize_entry(&"workspace", value)?;
}
SearchNotebooksQuery::AuthorIsCurrentUser(value) => {
map.serialize_entry(&"type", &"authorIsCurrentUser")?;
map.serialize_entry(&"authorIsCurrentUser", value)?;
}
SearchNotebooksQuery::AuthorRids(value) => {
map.serialize_entry(&"type", &"authorRids")?;
map.serialize_entry(&"authorRids", value)?;
}
SearchNotebooksQuery::Unknown(value) => {
map.serialize_entry(&"type", &value.type_)?;
map.serialize_entry(&value.type_, &value.value)?;
}
}
map.end()
}
}
impl<'de> de::Deserialize<'de> for SearchNotebooksQuery {
fn deserialize<D>(d: D) -> Result<SearchNotebooksQuery, D::Error>
where
D: de::Deserializer<'de>,
{
d.deserialize_map(Visitor_)
}
}
struct Visitor_;
impl<'de> de::Visitor<'de> for Visitor_ {
type Value = SearchNotebooksQuery;
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str("union SearchNotebooksQuery")
}
fn visit_map<A>(self, mut map: A) -> Result<SearchNotebooksQuery, A::Error>
where
A: de::MapAccess<'de>,
{
let v = match map.next_key::<UnionField_<Variant_>>()? {
Some(UnionField_::Type) => {
let variant = map.next_value()?;
let key = map.next_key()?;
match (variant, key) {
(Variant_::And, Some(Variant_::And)) => {
let value = map.next_value()?;
SearchNotebooksQuery::And(value)
}
(Variant_::Or, Some(Variant_::Or)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Or(value)
}
(Variant_::Not, Some(Variant_::Not)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Not(value)
}
(Variant_::ExactMatch, Some(Variant_::ExactMatch)) => {
let value = map.next_value()?;
SearchNotebooksQuery::ExactMatch(value)
}
(Variant_::SearchText, Some(Variant_::SearchText)) => {
let value = map.next_value()?;
SearchNotebooksQuery::SearchText(value)
}
#[allow(deprecated)]
(Variant_::Label, Some(Variant_::Label)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Label(value)
}
(Variant_::Labels, Some(Variant_::Labels)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Labels(value)
}
#[allow(deprecated)]
(Variant_::Property, Some(Variant_::Property)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Property(value)
}
(Variant_::Properties, Some(Variant_::Properties)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Properties(value)
}
#[allow(deprecated)]
(Variant_::AssetRid, Some(Variant_::AssetRid)) => {
let value = map.next_value()?;
SearchNotebooksQuery::AssetRid(value)
}
(Variant_::AssetRids, Some(Variant_::AssetRids)) => {
let value = map.next_value()?;
SearchNotebooksQuery::AssetRids(value)
}
(Variant_::ExactAssetRids, Some(Variant_::ExactAssetRids)) => {
let value = map.next_value()?;
SearchNotebooksQuery::ExactAssetRids(value)
}
(Variant_::AuthorRid, Some(Variant_::AuthorRid)) => {
let value = map.next_value()?;
SearchNotebooksQuery::AuthorRid(value)
}
#[allow(deprecated)]
(Variant_::RunRid, Some(Variant_::RunRid)) => {
let value = map.next_value()?;
SearchNotebooksQuery::RunRid(value)
}
(Variant_::RunRids, Some(Variant_::RunRids)) => {
let value = map.next_value()?;
SearchNotebooksQuery::RunRids(value)
}
#[allow(deprecated)]
(Variant_::NotebookType, Some(Variant_::NotebookType)) => {
let value = map.next_value()?;
SearchNotebooksQuery::NotebookType(value)
}
(Variant_::NotebookTypes, Some(Variant_::NotebookTypes)) => {
let value = map.next_value()?;
SearchNotebooksQuery::NotebookTypes(value)
}
(Variant_::DraftState, Some(Variant_::DraftState)) => {
let value = map.next_value()?;
SearchNotebooksQuery::DraftState(value)
}
(Variant_::Archived, Some(Variant_::Archived)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Archived(value)
}
(Variant_::Workspace, Some(Variant_::Workspace)) => {
let value = map.next_value()?;
SearchNotebooksQuery::Workspace(value)
}
(
Variant_::AuthorIsCurrentUser,
Some(Variant_::AuthorIsCurrentUser),
) => {
let value = map.next_value()?;
SearchNotebooksQuery::AuthorIsCurrentUser(value)
}
(Variant_::AuthorRids, Some(Variant_::AuthorRids)) => {
let value = map.next_value()?;
SearchNotebooksQuery::AuthorRids(value)
}
(Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
if type_ == b {
let value = map.next_value()?;
SearchNotebooksQuery::Unknown(Unknown { type_, value })
} else {
return Err(
de::Error::invalid_value(de::Unexpected::Str(&type_), &&*b),
)
}
}
(variant, Some(key)) => {
return Err(
de::Error::invalid_value(
de::Unexpected::Str(key.as_str()),
&variant.as_str(),
),
);
}
(variant, None) => {
return Err(de::Error::missing_field(variant.as_str()));
}
}
}
Some(UnionField_::Value(variant)) => {
let value = match &variant {
Variant_::And => {
let value = map.next_value()?;
SearchNotebooksQuery::And(value)
}
Variant_::Or => {
let value = map.next_value()?;
SearchNotebooksQuery::Or(value)
}
Variant_::Not => {
let value = map.next_value()?;
SearchNotebooksQuery::Not(value)
}
Variant_::ExactMatch => {
let value = map.next_value()?;
SearchNotebooksQuery::ExactMatch(value)
}
Variant_::SearchText => {
let value = map.next_value()?;
SearchNotebooksQuery::SearchText(value)
}
Variant_::Label => {
let value = map.next_value()?;
#[allow(deprecated)] SearchNotebooksQuery::Label(value)
}
Variant_::Labels => {
let value = map.next_value()?;
SearchNotebooksQuery::Labels(value)
}
Variant_::Property => {
let value = map.next_value()?;
#[allow(deprecated)] SearchNotebooksQuery::Property(value)
}
Variant_::Properties => {
let value = map.next_value()?;
SearchNotebooksQuery::Properties(value)
}
Variant_::AssetRid => {
let value = map.next_value()?;
#[allow(deprecated)] SearchNotebooksQuery::AssetRid(value)
}
Variant_::AssetRids => {
let value = map.next_value()?;
SearchNotebooksQuery::AssetRids(value)
}
Variant_::ExactAssetRids => {
let value = map.next_value()?;
SearchNotebooksQuery::ExactAssetRids(value)
}
Variant_::AuthorRid => {
let value = map.next_value()?;
SearchNotebooksQuery::AuthorRid(value)
}
Variant_::RunRid => {
let value = map.next_value()?;
#[allow(deprecated)] SearchNotebooksQuery::RunRid(value)
}
Variant_::RunRids => {
let value = map.next_value()?;
SearchNotebooksQuery::RunRids(value)
}
Variant_::NotebookType => {
let value = map.next_value()?;
#[allow(deprecated)] SearchNotebooksQuery::NotebookType(value)
}
Variant_::NotebookTypes => {
let value = map.next_value()?;
SearchNotebooksQuery::NotebookTypes(value)
}
Variant_::DraftState => {
let value = map.next_value()?;
SearchNotebooksQuery::DraftState(value)
}
Variant_::Archived => {
let value = map.next_value()?;
SearchNotebooksQuery::Archived(value)
}
Variant_::Workspace => {
let value = map.next_value()?;
SearchNotebooksQuery::Workspace(value)
}
Variant_::AuthorIsCurrentUser => {
let value = map.next_value()?;
SearchNotebooksQuery::AuthorIsCurrentUser(value)
}
Variant_::AuthorRids => {
let value = map.next_value()?;
SearchNotebooksQuery::AuthorRids(value)
}
Variant_::Unknown(type_) => {
let value = map.next_value()?;
SearchNotebooksQuery::Unknown(Unknown {
type_: type_.clone(),
value,
})
}
};
if map.next_key::<UnionTypeField_>()?.is_none() {
return Err(de::Error::missing_field("type"));
}
let type_variant = map.next_value::<Variant_>()?;
if variant != type_variant {
return Err(
de::Error::invalid_value(
de::Unexpected::Str(type_variant.as_str()),
&variant.as_str(),
),
);
}
value
}
None => return Err(de::Error::missing_field("type")),
};
if map.next_key::<UnionField_<Variant_>>()?.is_some() {
return Err(de::Error::invalid_length(3, &"type and value fields"));
}
Ok(v)
}
}
#[derive(PartialEq)]
enum Variant_ {
And,
Or,
Not,
ExactMatch,
SearchText,
Label,
Labels,
Property,
Properties,
AssetRid,
AssetRids,
ExactAssetRids,
AuthorRid,
RunRid,
RunRids,
NotebookType,
NotebookTypes,
DraftState,
Archived,
Workspace,
AuthorIsCurrentUser,
AuthorRids,
Unknown(Box<str>),
}
impl Variant_ {
fn as_str(&self) -> &'static str {
match *self {
Variant_::And => "and",
Variant_::Or => "or",
Variant_::Not => "not",
Variant_::ExactMatch => "exactMatch",
Variant_::SearchText => "searchText",
Variant_::Label => "label",
Variant_::Labels => "labels",
Variant_::Property => "property",
Variant_::Properties => "properties",
Variant_::AssetRid => "assetRid",
Variant_::AssetRids => "assetRids",
Variant_::ExactAssetRids => "exactAssetRids",
Variant_::AuthorRid => "authorRid",
Variant_::RunRid => "runRid",
Variant_::RunRids => "runRids",
Variant_::NotebookType => "notebookType",
Variant_::NotebookTypes => "notebookTypes",
Variant_::DraftState => "draftState",
Variant_::Archived => "archived",
Variant_::Workspace => "workspace",
Variant_::AuthorIsCurrentUser => "authorIsCurrentUser",
Variant_::AuthorRids => "authorRids",
Variant_::Unknown(_) => "unknown variant",
}
}
}
impl<'de> de::Deserialize<'de> for Variant_ {
fn deserialize<D>(d: D) -> Result<Variant_, D::Error>
where
D: de::Deserializer<'de>,
{
d.deserialize_str(VariantVisitor_)
}
}
struct VariantVisitor_;
impl<'de> de::Visitor<'de> for VariantVisitor_ {
type Value = Variant_;
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str("string")
}
fn visit_str<E>(self, value: &str) -> Result<Variant_, E>
where
E: de::Error,
{
let v = match value {
"and" => Variant_::And,
"or" => Variant_::Or,
"not" => Variant_::Not,
"exactMatch" => Variant_::ExactMatch,
"searchText" => Variant_::SearchText,
"label" => Variant_::Label,
"labels" => Variant_::Labels,
"property" => Variant_::Property,
"properties" => Variant_::Properties,
"assetRid" => Variant_::AssetRid,
"assetRids" => Variant_::AssetRids,
"exactAssetRids" => Variant_::ExactAssetRids,
"authorRid" => Variant_::AuthorRid,
"runRid" => Variant_::RunRid,
"runRids" => Variant_::RunRids,
"notebookType" => Variant_::NotebookType,
"notebookTypes" => Variant_::NotebookTypes,
"draftState" => Variant_::DraftState,
"archived" => Variant_::Archived,
"workspace" => Variant_::Workspace,
"authorIsCurrentUser" => Variant_::AuthorIsCurrentUser,
"authorRids" => Variant_::AuthorRids,
value => Variant_::Unknown(value.to_string().into_boxed_str()),
};
Ok(v)
}
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Unknown {
type_: Box<str>,
value: conjure_object::Any,
}
impl Unknown {
#[inline]
pub fn type_(&self) -> &str {
&self.type_
}
}