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 ComputeEventQuery {
    SearchText(Box<super::super::super::compute::api::StringConstant>),
    /// Filters to events after this timestamp, exclusive.
    /// This includes events that start before, but end after this time.
    After(Box<super::super::super::compute::api::TimestampConstant>),
    /// Filters to events before this timestamp, exclusive.
    /// This includes events that start before, but end after this time.
    Before(Box<super::super::super::compute::api::TimestampConstant>),
    AdvancedTimeFilter(super::EventTimeFilter),
    Asset(Box<super::super::super::compute::api::StringConstant>),
    Template(Box<super::super::super::compute::api::StringConstant>),
    Workbook(Box<super::super::super::compute::api::StringConstant>),
    DataReview(Box<super::super::super::compute::api::StringConstant>),
    OriginType(super::SearchEventOriginType),
    DataReviewCheck(Box<super::super::super::compute::api::StringConstant>),
    DispositionStatus(super::EventDispositionStatus),
    Priority(Box<super::super::super::compute::api::StringConstant>),
    Assignee(Box<super::super::super::compute::api::StringConstant>),
    EventType(super::EventType),
    CreatedBy(Box<super::super::super::compute::api::StringConstant>),
    Label(Box<super::super::super::compute::api::StringConstant>),
    Property(super::Property),
    And(Vec<super::ComputeEventQuery>),
    Or(Vec<super::ComputeEventQuery>),
    Not(Box<super::ComputeEventQuery>),
    Workspace(Box<super::super::super::compute::api::StringConstant>),
    Procedure(Box<super::super::super::compute::api::StringConstant>),
    ProcedureExecution(Box<super::super::super::compute::api::StringConstant>),
    StepId(Box<super::super::super::compute::api::StringConstant>),
    /// An unknown variant.
    Unknown(Unknown),
}
impl ser::Serialize for ComputeEventQuery {
    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 {
            ComputeEventQuery::SearchText(value) => {
                map.serialize_entry(&"type", &"searchText")?;
                map.serialize_entry(&"searchText", value)?;
            }
            ComputeEventQuery::After(value) => {
                map.serialize_entry(&"type", &"after")?;
                map.serialize_entry(&"after", value)?;
            }
            ComputeEventQuery::Before(value) => {
                map.serialize_entry(&"type", &"before")?;
                map.serialize_entry(&"before", value)?;
            }
            ComputeEventQuery::AdvancedTimeFilter(value) => {
                map.serialize_entry(&"type", &"advancedTimeFilter")?;
                map.serialize_entry(&"advancedTimeFilter", value)?;
            }
            ComputeEventQuery::Asset(value) => {
                map.serialize_entry(&"type", &"asset")?;
                map.serialize_entry(&"asset", value)?;
            }
            ComputeEventQuery::Template(value) => {
                map.serialize_entry(&"type", &"template")?;
                map.serialize_entry(&"template", value)?;
            }
            ComputeEventQuery::Workbook(value) => {
                map.serialize_entry(&"type", &"workbook")?;
                map.serialize_entry(&"workbook", value)?;
            }
            ComputeEventQuery::DataReview(value) => {
                map.serialize_entry(&"type", &"dataReview")?;
                map.serialize_entry(&"dataReview", value)?;
            }
            ComputeEventQuery::OriginType(value) => {
                map.serialize_entry(&"type", &"originType")?;
                map.serialize_entry(&"originType", value)?;
            }
            ComputeEventQuery::DataReviewCheck(value) => {
                map.serialize_entry(&"type", &"dataReviewCheck")?;
                map.serialize_entry(&"dataReviewCheck", value)?;
            }
            ComputeEventQuery::DispositionStatus(value) => {
                map.serialize_entry(&"type", &"dispositionStatus")?;
                map.serialize_entry(&"dispositionStatus", value)?;
            }
            ComputeEventQuery::Priority(value) => {
                map.serialize_entry(&"type", &"priority")?;
                map.serialize_entry(&"priority", value)?;
            }
            ComputeEventQuery::Assignee(value) => {
                map.serialize_entry(&"type", &"assignee")?;
                map.serialize_entry(&"assignee", value)?;
            }
            ComputeEventQuery::EventType(value) => {
                map.serialize_entry(&"type", &"eventType")?;
                map.serialize_entry(&"eventType", value)?;
            }
            ComputeEventQuery::CreatedBy(value) => {
                map.serialize_entry(&"type", &"createdBy")?;
                map.serialize_entry(&"createdBy", value)?;
            }
            ComputeEventQuery::Label(value) => {
                map.serialize_entry(&"type", &"label")?;
                map.serialize_entry(&"label", value)?;
            }
            ComputeEventQuery::Property(value) => {
                map.serialize_entry(&"type", &"property")?;
                map.serialize_entry(&"property", value)?;
            }
            ComputeEventQuery::And(value) => {
                map.serialize_entry(&"type", &"and")?;
                map.serialize_entry(&"and", value)?;
            }
            ComputeEventQuery::Or(value) => {
                map.serialize_entry(&"type", &"or")?;
                map.serialize_entry(&"or", value)?;
            }
            ComputeEventQuery::Not(value) => {
                map.serialize_entry(&"type", &"not")?;
                map.serialize_entry(&"not", value)?;
            }
            ComputeEventQuery::Workspace(value) => {
                map.serialize_entry(&"type", &"workspace")?;
                map.serialize_entry(&"workspace", value)?;
            }
            ComputeEventQuery::Procedure(value) => {
                map.serialize_entry(&"type", &"procedure")?;
                map.serialize_entry(&"procedure", value)?;
            }
            ComputeEventQuery::ProcedureExecution(value) => {
                map.serialize_entry(&"type", &"procedureExecution")?;
                map.serialize_entry(&"procedureExecution", value)?;
            }
            ComputeEventQuery::StepId(value) => {
                map.serialize_entry(&"type", &"stepId")?;
                map.serialize_entry(&"stepId", value)?;
            }
            ComputeEventQuery::Unknown(value) => {
                map.serialize_entry(&"type", &value.type_)?;
                map.serialize_entry(&value.type_, &value.value)?;
            }
        }
        map.end()
    }
}
impl<'de> de::Deserialize<'de> for ComputeEventQuery {
    fn deserialize<D>(d: D) -> Result<ComputeEventQuery, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        d.deserialize_map(Visitor_)
    }
}
struct Visitor_;
impl<'de> de::Visitor<'de> for Visitor_ {
    type Value = ComputeEventQuery;
    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str("union ComputeEventQuery")
    }
    fn visit_map<A>(self, mut map: A) -> Result<ComputeEventQuery, 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_::SearchText, Some(Variant_::SearchText)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::SearchText(value)
                    }
                    (Variant_::After, Some(Variant_::After)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::After(value)
                    }
                    (Variant_::Before, Some(Variant_::Before)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Before(value)
                    }
                    (
                        Variant_::AdvancedTimeFilter,
                        Some(Variant_::AdvancedTimeFilter),
                    ) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::AdvancedTimeFilter(value)
                    }
                    (Variant_::Asset, Some(Variant_::Asset)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Asset(value)
                    }
                    (Variant_::Template, Some(Variant_::Template)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Template(value)
                    }
                    (Variant_::Workbook, Some(Variant_::Workbook)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Workbook(value)
                    }
                    (Variant_::DataReview, Some(Variant_::DataReview)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::DataReview(value)
                    }
                    (Variant_::OriginType, Some(Variant_::OriginType)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::OriginType(value)
                    }
                    (Variant_::DataReviewCheck, Some(Variant_::DataReviewCheck)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::DataReviewCheck(value)
                    }
                    (Variant_::DispositionStatus, Some(Variant_::DispositionStatus)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::DispositionStatus(value)
                    }
                    (Variant_::Priority, Some(Variant_::Priority)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Priority(value)
                    }
                    (Variant_::Assignee, Some(Variant_::Assignee)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Assignee(value)
                    }
                    (Variant_::EventType, Some(Variant_::EventType)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::EventType(value)
                    }
                    (Variant_::CreatedBy, Some(Variant_::CreatedBy)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::CreatedBy(value)
                    }
                    (Variant_::Label, Some(Variant_::Label)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Label(value)
                    }
                    (Variant_::Property, Some(Variant_::Property)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Property(value)
                    }
                    (Variant_::And, Some(Variant_::And)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::And(value)
                    }
                    (Variant_::Or, Some(Variant_::Or)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Or(value)
                    }
                    (Variant_::Not, Some(Variant_::Not)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Not(value)
                    }
                    (Variant_::Workspace, Some(Variant_::Workspace)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Workspace(value)
                    }
                    (Variant_::Procedure, Some(Variant_::Procedure)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Procedure(value)
                    }
                    (
                        Variant_::ProcedureExecution,
                        Some(Variant_::ProcedureExecution),
                    ) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::ProcedureExecution(value)
                    }
                    (Variant_::StepId, Some(Variant_::StepId)) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::StepId(value)
                    }
                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
                        if type_ == b {
                            let value = map.next_value()?;
                            ComputeEventQuery::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_::SearchText => {
                        let value = map.next_value()?;
                        ComputeEventQuery::SearchText(value)
                    }
                    Variant_::After => {
                        let value = map.next_value()?;
                        ComputeEventQuery::After(value)
                    }
                    Variant_::Before => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Before(value)
                    }
                    Variant_::AdvancedTimeFilter => {
                        let value = map.next_value()?;
                        ComputeEventQuery::AdvancedTimeFilter(value)
                    }
                    Variant_::Asset => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Asset(value)
                    }
                    Variant_::Template => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Template(value)
                    }
                    Variant_::Workbook => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Workbook(value)
                    }
                    Variant_::DataReview => {
                        let value = map.next_value()?;
                        ComputeEventQuery::DataReview(value)
                    }
                    Variant_::OriginType => {
                        let value = map.next_value()?;
                        ComputeEventQuery::OriginType(value)
                    }
                    Variant_::DataReviewCheck => {
                        let value = map.next_value()?;
                        ComputeEventQuery::DataReviewCheck(value)
                    }
                    Variant_::DispositionStatus => {
                        let value = map.next_value()?;
                        ComputeEventQuery::DispositionStatus(value)
                    }
                    Variant_::Priority => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Priority(value)
                    }
                    Variant_::Assignee => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Assignee(value)
                    }
                    Variant_::EventType => {
                        let value = map.next_value()?;
                        ComputeEventQuery::EventType(value)
                    }
                    Variant_::CreatedBy => {
                        let value = map.next_value()?;
                        ComputeEventQuery::CreatedBy(value)
                    }
                    Variant_::Label => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Label(value)
                    }
                    Variant_::Property => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Property(value)
                    }
                    Variant_::And => {
                        let value = map.next_value()?;
                        ComputeEventQuery::And(value)
                    }
                    Variant_::Or => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Or(value)
                    }
                    Variant_::Not => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Not(value)
                    }
                    Variant_::Workspace => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Workspace(value)
                    }
                    Variant_::Procedure => {
                        let value = map.next_value()?;
                        ComputeEventQuery::Procedure(value)
                    }
                    Variant_::ProcedureExecution => {
                        let value = map.next_value()?;
                        ComputeEventQuery::ProcedureExecution(value)
                    }
                    Variant_::StepId => {
                        let value = map.next_value()?;
                        ComputeEventQuery::StepId(value)
                    }
                    Variant_::Unknown(type_) => {
                        let value = map.next_value()?;
                        ComputeEventQuery::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_ {
    SearchText,
    After,
    Before,
    AdvancedTimeFilter,
    Asset,
    Template,
    Workbook,
    DataReview,
    OriginType,
    DataReviewCheck,
    DispositionStatus,
    Priority,
    Assignee,
    EventType,
    CreatedBy,
    Label,
    Property,
    And,
    Or,
    Not,
    Workspace,
    Procedure,
    ProcedureExecution,
    StepId,
    Unknown(Box<str>),
}
impl Variant_ {
    fn as_str(&self) -> &'static str {
        match *self {
            Variant_::SearchText => "searchText",
            Variant_::After => "after",
            Variant_::Before => "before",
            Variant_::AdvancedTimeFilter => "advancedTimeFilter",
            Variant_::Asset => "asset",
            Variant_::Template => "template",
            Variant_::Workbook => "workbook",
            Variant_::DataReview => "dataReview",
            Variant_::OriginType => "originType",
            Variant_::DataReviewCheck => "dataReviewCheck",
            Variant_::DispositionStatus => "dispositionStatus",
            Variant_::Priority => "priority",
            Variant_::Assignee => "assignee",
            Variant_::EventType => "eventType",
            Variant_::CreatedBy => "createdBy",
            Variant_::Label => "label",
            Variant_::Property => "property",
            Variant_::And => "and",
            Variant_::Or => "or",
            Variant_::Not => "not",
            Variant_::Workspace => "workspace",
            Variant_::Procedure => "procedure",
            Variant_::ProcedureExecution => "procedureExecution",
            Variant_::StepId => "stepId",
            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 {
            "searchText" => Variant_::SearchText,
            "after" => Variant_::After,
            "before" => Variant_::Before,
            "advancedTimeFilter" => Variant_::AdvancedTimeFilter,
            "asset" => Variant_::Asset,
            "template" => Variant_::Template,
            "workbook" => Variant_::Workbook,
            "dataReview" => Variant_::DataReview,
            "originType" => Variant_::OriginType,
            "dataReviewCheck" => Variant_::DataReviewCheck,
            "dispositionStatus" => Variant_::DispositionStatus,
            "priority" => Variant_::Priority,
            "assignee" => Variant_::Assignee,
            "eventType" => Variant_::EventType,
            "createdBy" => Variant_::CreatedBy,
            "label" => Variant_::Label,
            "property" => Variant_::Property,
            "and" => Variant_::And,
            "or" => Variant_::Or,
            "not" => Variant_::Not,
            "workspace" => Variant_::Workspace,
            "procedure" => Variant_::Procedure,
            "procedureExecution" => Variant_::ProcedureExecution,
            "stepId" => Variant_::StepId,
            value => Variant_::Unknown(value.to_string().into_boxed_str()),
        };
        Ok(v)
    }
}
///An unknown variant of the ComputeEventQuery union.
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Unknown {
    type_: Box<str>,
    value: conjure_object::Any,
}
impl Unknown {
    /// Returns the unknown variant's type name.
    #[inline]
    pub fn type_(&self) -> &str {
        &self.type_
    }
}
