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 SearchQuery {
#[deprecated(note = "Use startTime instead")]
StartTimeInclusive(super::UtcTimestamp),
StartTime(Box<super::TimeframeFilter>),
#[deprecated(note = "Use endTime instead")]
EndTimeInclusive(super::UtcTimestamp),
EndTime(Box<super::TimeframeFilter>),
TimeRange(super::TimeRangeFilter),
CreatedAt(Box<super::TimeframeFilter>),
ExactMatch(String),
SearchText(String),
#[deprecated(note = "Use getRunsByAsset rather than text-based search")]
Asset(super::super::super::rids::api::AssetRid),
Assets(super::AssetsFilter),
IsSingleAsset(bool),
#[deprecated(note = "use labels instead")]
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),
PropertyKey(super::super::super::super::api::PropertyName),
Properties(super::super::super::rids::api::PropertiesFilter),
DataSourceSeriesTag(super::DataSourceSeriesTag),
DataSourceRefName(super::super::super::api::DataSourceRefName),
#[deprecated(
note = "Use dataSourceRefName, rather than searching directly by DataSource."
)]
DataSource(Box<super::DataSource>),
RunNumber(conjure_object::SafeLong),
RunPrefix(String),
CheckAlertStatesFilter(super::CheckAlertStatesFilter),
Archived(bool),
And(Vec<super::SearchQuery>),
Or(Vec<super::SearchQuery>),
Not(Box<super::SearchQuery>),
Workspace(super::super::super::super::api::rids::WorkspaceRid),
Unknown(Unknown),
}
impl ser::Serialize for SearchQuery {
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 {
#[allow(deprecated)]
SearchQuery::StartTimeInclusive(value) => {
map.serialize_entry(&"type", &"startTimeInclusive")?;
map.serialize_entry(&"startTimeInclusive", value)?;
}
SearchQuery::StartTime(value) => {
map.serialize_entry(&"type", &"startTime")?;
map.serialize_entry(&"startTime", value)?;
}
#[allow(deprecated)]
SearchQuery::EndTimeInclusive(value) => {
map.serialize_entry(&"type", &"endTimeInclusive")?;
map.serialize_entry(&"endTimeInclusive", value)?;
}
SearchQuery::EndTime(value) => {
map.serialize_entry(&"type", &"endTime")?;
map.serialize_entry(&"endTime", value)?;
}
SearchQuery::TimeRange(value) => {
map.serialize_entry(&"type", &"timeRange")?;
map.serialize_entry(&"timeRange", value)?;
}
SearchQuery::CreatedAt(value) => {
map.serialize_entry(&"type", &"createdAt")?;
map.serialize_entry(&"createdAt", value)?;
}
SearchQuery::ExactMatch(value) => {
map.serialize_entry(&"type", &"exactMatch")?;
map.serialize_entry(&"exactMatch", value)?;
}
SearchQuery::SearchText(value) => {
map.serialize_entry(&"type", &"searchText")?;
map.serialize_entry(&"searchText", value)?;
}
#[allow(deprecated)]
SearchQuery::Asset(value) => {
map.serialize_entry(&"type", &"asset")?;
map.serialize_entry(&"asset", value)?;
}
SearchQuery::Assets(value) => {
map.serialize_entry(&"type", &"assets")?;
map.serialize_entry(&"assets", value)?;
}
SearchQuery::IsSingleAsset(value) => {
map.serialize_entry(&"type", &"isSingleAsset")?;
map.serialize_entry(&"isSingleAsset", value)?;
}
#[allow(deprecated)]
SearchQuery::Label(value) => {
map.serialize_entry(&"type", &"label")?;
map.serialize_entry(&"label", value)?;
}
SearchQuery::Labels(value) => {
map.serialize_entry(&"type", &"labels")?;
map.serialize_entry(&"labels", value)?;
}
#[allow(deprecated)]
SearchQuery::Property(value) => {
map.serialize_entry(&"type", &"property")?;
map.serialize_entry(&"property", value)?;
}
SearchQuery::PropertyKey(value) => {
map.serialize_entry(&"type", &"propertyKey")?;
map.serialize_entry(&"propertyKey", value)?;
}
SearchQuery::Properties(value) => {
map.serialize_entry(&"type", &"properties")?;
map.serialize_entry(&"properties", value)?;
}
SearchQuery::DataSourceSeriesTag(value) => {
map.serialize_entry(&"type", &"dataSourceSeriesTag")?;
map.serialize_entry(&"dataSourceSeriesTag", value)?;
}
SearchQuery::DataSourceRefName(value) => {
map.serialize_entry(&"type", &"dataSourceRefName")?;
map.serialize_entry(&"dataSourceRefName", value)?;
}
#[allow(deprecated)]
SearchQuery::DataSource(value) => {
map.serialize_entry(&"type", &"dataSource")?;
map.serialize_entry(&"dataSource", value)?;
}
SearchQuery::RunNumber(value) => {
map.serialize_entry(&"type", &"runNumber")?;
map.serialize_entry(&"runNumber", value)?;
}
SearchQuery::RunPrefix(value) => {
map.serialize_entry(&"type", &"runPrefix")?;
map.serialize_entry(&"runPrefix", value)?;
}
SearchQuery::CheckAlertStatesFilter(value) => {
map.serialize_entry(&"type", &"checkAlertStatesFilter")?;
map.serialize_entry(&"checkAlertStatesFilter", value)?;
}
SearchQuery::Archived(value) => {
map.serialize_entry(&"type", &"archived")?;
map.serialize_entry(&"archived", value)?;
}
SearchQuery::And(value) => {
map.serialize_entry(&"type", &"and")?;
map.serialize_entry(&"and", value)?;
}
SearchQuery::Or(value) => {
map.serialize_entry(&"type", &"or")?;
map.serialize_entry(&"or", value)?;
}
SearchQuery::Not(value) => {
map.serialize_entry(&"type", &"not")?;
map.serialize_entry(&"not", value)?;
}
SearchQuery::Workspace(value) => {
map.serialize_entry(&"type", &"workspace")?;
map.serialize_entry(&"workspace", value)?;
}
SearchQuery::Unknown(value) => {
map.serialize_entry(&"type", &value.type_)?;
map.serialize_entry(&value.type_, &value.value)?;
}
}
map.end()
}
}
impl<'de> de::Deserialize<'de> for SearchQuery {
fn deserialize<D>(d: D) -> Result<SearchQuery, D::Error>
where
D: de::Deserializer<'de>,
{
d.deserialize_map(Visitor_)
}
}
struct Visitor_;
impl<'de> de::Visitor<'de> for Visitor_ {
type Value = SearchQuery;
fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str("union SearchQuery")
}
fn visit_map<A>(self, mut map: A) -> Result<SearchQuery, 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) {
#[allow(deprecated)]
(
Variant_::StartTimeInclusive,
Some(Variant_::StartTimeInclusive),
) => {
let value = map.next_value()?;
SearchQuery::StartTimeInclusive(value)
}
(Variant_::StartTime, Some(Variant_::StartTime)) => {
let value = map.next_value()?;
SearchQuery::StartTime(value)
}
#[allow(deprecated)]
(Variant_::EndTimeInclusive, Some(Variant_::EndTimeInclusive)) => {
let value = map.next_value()?;
SearchQuery::EndTimeInclusive(value)
}
(Variant_::EndTime, Some(Variant_::EndTime)) => {
let value = map.next_value()?;
SearchQuery::EndTime(value)
}
(Variant_::TimeRange, Some(Variant_::TimeRange)) => {
let value = map.next_value()?;
SearchQuery::TimeRange(value)
}
(Variant_::CreatedAt, Some(Variant_::CreatedAt)) => {
let value = map.next_value()?;
SearchQuery::CreatedAt(value)
}
(Variant_::ExactMatch, Some(Variant_::ExactMatch)) => {
let value = map.next_value()?;
SearchQuery::ExactMatch(value)
}
(Variant_::SearchText, Some(Variant_::SearchText)) => {
let value = map.next_value()?;
SearchQuery::SearchText(value)
}
#[allow(deprecated)]
(Variant_::Asset, Some(Variant_::Asset)) => {
let value = map.next_value()?;
SearchQuery::Asset(value)
}
(Variant_::Assets, Some(Variant_::Assets)) => {
let value = map.next_value()?;
SearchQuery::Assets(value)
}
(Variant_::IsSingleAsset, Some(Variant_::IsSingleAsset)) => {
let value = map.next_value()?;
SearchQuery::IsSingleAsset(value)
}
#[allow(deprecated)]
(Variant_::Label, Some(Variant_::Label)) => {
let value = map.next_value()?;
SearchQuery::Label(value)
}
(Variant_::Labels, Some(Variant_::Labels)) => {
let value = map.next_value()?;
SearchQuery::Labels(value)
}
#[allow(deprecated)]
(Variant_::Property, Some(Variant_::Property)) => {
let value = map.next_value()?;
SearchQuery::Property(value)
}
(Variant_::PropertyKey, Some(Variant_::PropertyKey)) => {
let value = map.next_value()?;
SearchQuery::PropertyKey(value)
}
(Variant_::Properties, Some(Variant_::Properties)) => {
let value = map.next_value()?;
SearchQuery::Properties(value)
}
(
Variant_::DataSourceSeriesTag,
Some(Variant_::DataSourceSeriesTag),
) => {
let value = map.next_value()?;
SearchQuery::DataSourceSeriesTag(value)
}
(Variant_::DataSourceRefName, Some(Variant_::DataSourceRefName)) => {
let value = map.next_value()?;
SearchQuery::DataSourceRefName(value)
}
#[allow(deprecated)]
(Variant_::DataSource, Some(Variant_::DataSource)) => {
let value = map.next_value()?;
SearchQuery::DataSource(value)
}
(Variant_::RunNumber, Some(Variant_::RunNumber)) => {
let value = map.next_value()?;
SearchQuery::RunNumber(value)
}
(Variant_::RunPrefix, Some(Variant_::RunPrefix)) => {
let value = map.next_value()?;
SearchQuery::RunPrefix(value)
}
(
Variant_::CheckAlertStatesFilter,
Some(Variant_::CheckAlertStatesFilter),
) => {
let value = map.next_value()?;
SearchQuery::CheckAlertStatesFilter(value)
}
(Variant_::Archived, Some(Variant_::Archived)) => {
let value = map.next_value()?;
SearchQuery::Archived(value)
}
(Variant_::And, Some(Variant_::And)) => {
let value = map.next_value()?;
SearchQuery::And(value)
}
(Variant_::Or, Some(Variant_::Or)) => {
let value = map.next_value()?;
SearchQuery::Or(value)
}
(Variant_::Not, Some(Variant_::Not)) => {
let value = map.next_value()?;
SearchQuery::Not(value)
}
(Variant_::Workspace, Some(Variant_::Workspace)) => {
let value = map.next_value()?;
SearchQuery::Workspace(value)
}
(Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
if type_ == b {
let value = map.next_value()?;
SearchQuery::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_::StartTimeInclusive => {
let value = map.next_value()?;
#[allow(deprecated)] SearchQuery::StartTimeInclusive(value)
}
Variant_::StartTime => {
let value = map.next_value()?;
SearchQuery::StartTime(value)
}
Variant_::EndTimeInclusive => {
let value = map.next_value()?;
#[allow(deprecated)] SearchQuery::EndTimeInclusive(value)
}
Variant_::EndTime => {
let value = map.next_value()?;
SearchQuery::EndTime(value)
}
Variant_::TimeRange => {
let value = map.next_value()?;
SearchQuery::TimeRange(value)
}
Variant_::CreatedAt => {
let value = map.next_value()?;
SearchQuery::CreatedAt(value)
}
Variant_::ExactMatch => {
let value = map.next_value()?;
SearchQuery::ExactMatch(value)
}
Variant_::SearchText => {
let value = map.next_value()?;
SearchQuery::SearchText(value)
}
Variant_::Asset => {
let value = map.next_value()?;
#[allow(deprecated)] SearchQuery::Asset(value)
}
Variant_::Assets => {
let value = map.next_value()?;
SearchQuery::Assets(value)
}
Variant_::IsSingleAsset => {
let value = map.next_value()?;
SearchQuery::IsSingleAsset(value)
}
Variant_::Label => {
let value = map.next_value()?;
#[allow(deprecated)] SearchQuery::Label(value)
}
Variant_::Labels => {
let value = map.next_value()?;
SearchQuery::Labels(value)
}
Variant_::Property => {
let value = map.next_value()?;
#[allow(deprecated)] SearchQuery::Property(value)
}
Variant_::PropertyKey => {
let value = map.next_value()?;
SearchQuery::PropertyKey(value)
}
Variant_::Properties => {
let value = map.next_value()?;
SearchQuery::Properties(value)
}
Variant_::DataSourceSeriesTag => {
let value = map.next_value()?;
SearchQuery::DataSourceSeriesTag(value)
}
Variant_::DataSourceRefName => {
let value = map.next_value()?;
SearchQuery::DataSourceRefName(value)
}
Variant_::DataSource => {
let value = map.next_value()?;
#[allow(deprecated)] SearchQuery::DataSource(value)
}
Variant_::RunNumber => {
let value = map.next_value()?;
SearchQuery::RunNumber(value)
}
Variant_::RunPrefix => {
let value = map.next_value()?;
SearchQuery::RunPrefix(value)
}
Variant_::CheckAlertStatesFilter => {
let value = map.next_value()?;
SearchQuery::CheckAlertStatesFilter(value)
}
Variant_::Archived => {
let value = map.next_value()?;
SearchQuery::Archived(value)
}
Variant_::And => {
let value = map.next_value()?;
SearchQuery::And(value)
}
Variant_::Or => {
let value = map.next_value()?;
SearchQuery::Or(value)
}
Variant_::Not => {
let value = map.next_value()?;
SearchQuery::Not(value)
}
Variant_::Workspace => {
let value = map.next_value()?;
SearchQuery::Workspace(value)
}
Variant_::Unknown(type_) => {
let value = map.next_value()?;
SearchQuery::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_ {
StartTimeInclusive,
StartTime,
EndTimeInclusive,
EndTime,
TimeRange,
CreatedAt,
ExactMatch,
SearchText,
Asset,
Assets,
IsSingleAsset,
Label,
Labels,
Property,
PropertyKey,
Properties,
DataSourceSeriesTag,
DataSourceRefName,
DataSource,
RunNumber,
RunPrefix,
CheckAlertStatesFilter,
Archived,
And,
Or,
Not,
Workspace,
Unknown(Box<str>),
}
impl Variant_ {
fn as_str(&self) -> &'static str {
match *self {
Variant_::StartTimeInclusive => "startTimeInclusive",
Variant_::StartTime => "startTime",
Variant_::EndTimeInclusive => "endTimeInclusive",
Variant_::EndTime => "endTime",
Variant_::TimeRange => "timeRange",
Variant_::CreatedAt => "createdAt",
Variant_::ExactMatch => "exactMatch",
Variant_::SearchText => "searchText",
Variant_::Asset => "asset",
Variant_::Assets => "assets",
Variant_::IsSingleAsset => "isSingleAsset",
Variant_::Label => "label",
Variant_::Labels => "labels",
Variant_::Property => "property",
Variant_::PropertyKey => "propertyKey",
Variant_::Properties => "properties",
Variant_::DataSourceSeriesTag => "dataSourceSeriesTag",
Variant_::DataSourceRefName => "dataSourceRefName",
Variant_::DataSource => "dataSource",
Variant_::RunNumber => "runNumber",
Variant_::RunPrefix => "runPrefix",
Variant_::CheckAlertStatesFilter => "checkAlertStatesFilter",
Variant_::Archived => "archived",
Variant_::And => "and",
Variant_::Or => "or",
Variant_::Not => "not",
Variant_::Workspace => "workspace",
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 {
"startTimeInclusive" => Variant_::StartTimeInclusive,
"startTime" => Variant_::StartTime,
"endTimeInclusive" => Variant_::EndTimeInclusive,
"endTime" => Variant_::EndTime,
"timeRange" => Variant_::TimeRange,
"createdAt" => Variant_::CreatedAt,
"exactMatch" => Variant_::ExactMatch,
"searchText" => Variant_::SearchText,
"asset" => Variant_::Asset,
"assets" => Variant_::Assets,
"isSingleAsset" => Variant_::IsSingleAsset,
"label" => Variant_::Label,
"labels" => Variant_::Labels,
"property" => Variant_::Property,
"propertyKey" => Variant_::PropertyKey,
"properties" => Variant_::Properties,
"dataSourceSeriesTag" => Variant_::DataSourceSeriesTag,
"dataSourceRefName" => Variant_::DataSourceRefName,
"dataSource" => Variant_::DataSource,
"runNumber" => Variant_::RunNumber,
"runPrefix" => Variant_::RunPrefix,
"checkAlertStatesFilter" => Variant_::CheckAlertStatesFilter,
"archived" => Variant_::Archived,
"and" => Variant_::And,
"or" => Variant_::Or,
"not" => Variant_::Not,
"workspace" => Variant_::Workspace,
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_
}
}