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, conjure_object::private::DeriveWith)]
#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ComputeNodeAppendResponse {
    /// Merging can be done via dropping any old ranges (possibly truncating the last one) and adding these new
    /// ranges, possibly merging them if they overlap or are adjacent.
    Range(Vec<super::super::super::super::scout::compute::api::Range>),
    /// Merging can be done by keeping track of the applicable point present within the current window
    EnumPoint(Option<super::super::super::super::scout::compute::api::EnumPoint>),
    /// Merging can be done by keeping track of the applicable point present within the current window
    NumericPoint(Option<super::super::super::super::scout::compute::api::NumericPoint>),
    /// Merging can be done by keeping track of the applicable point present within the current window
    SinglePoint(Option<super::super::super::super::scout::compute::api::SinglePoint>),
    /// Merging can be done by keeping track of the applicable point present within the current window
    LogPoint(Option<super::super::super::super::scout::compute::api::LogPoint>),
    /// Merging can be done by keeping track of the applicable range present within the current window, possibly
    /// merging ranges if they are overlap or are adjacent
    RangeValue(Option<super::super::super::super::scout::compute::api::Range>),
    /// Merging can be done by dropping any old points and adding the new ones, accounting for overlaps
    Numeric(super::super::super::super::scout::compute::api::NumericPlot),
    /// Merging can be done by dropping any old points and adding the new ones, accounting for overlaps
    Enum(super::super::super::super::scout::compute::api::EnumPlot),
    /// Merging can be done by dropping any old points and adding the new ones, accounting for overlaps
    Log(super::super::super::super::scout::compute::api::LogPlot),
    /// Merging can be done by dropping any old buckets and adding the new ones. Overlapping buckets are
    /// guaranteed to align (same bucket end timestamp) and the older version of the bucket can be replaced
    /// with the newer ones.
    BucketedNumeric(
        super::super::super::super::scout::compute::api::BucketedNumericPlot,
    ),
    /// Merging can be done by dropping any old buckets and adding the new ones. Overlapping buckets are
    /// guaranteed to align (same bucket end timestamp) and the older version of the bucket can be replaced
    /// with the newer ones.
    BucketedEnum(super::super::super::super::scout::compute::api::BucketedEnumPlot),
    /// Merging can be done by dropping any old buckets and adding the new ones. Overlapping buckets are
    /// guaranteed to align (same bucket end timestamp) and the older version of the bucket can be replaced
    /// with the newer ones.
    Multivariate(
        super::super::super::super::scout::compute::api::BucketedMultivariatePlot,
    ),
    /// Merging can be done by dropping any old points and adding the new ones, accounting for overlaps
    ArrowNumeric(super::super::super::super::scout::compute::api::ArrowPlot),
    /// Merging can be done by dropping any old points and adding the new ones, accounting for overlaps
    ArrowEnum(super::super::super::super::scout::compute::api::ArrowPlot),
    /// Merging can be done by dropping any old buckets and adding the new ones. Overlapping buckets are
    /// guaranteed to align (same bucket end timestamp) and the older version of the bucket can be replaced
    /// with the newer ones.
    ArrowBucketedNumeric(super::super::super::super::scout::compute::api::ArrowPlot),
    /// Merging can be done by dropping any old buckets and adding the new ones. Overlapping buckets are
    /// guaranteed to align (same bucket end timestamp) and the older version of the bucket can be replaced
    /// with the newer ones.
    ArrowBucketedEnum(super::super::super::super::scout::compute::api::ArrowPlot),
    /// Merging can be done by dropping any old buckets and adding the new ones. Overlapping buckets are
    /// guaranteed to align (same bucket end timestamp) and the older version of the bucket can be replaced
    /// with the newer ones.
    ArrowBucketedMultivariate(
        super::super::super::super::scout::compute::api::ArrowPlot,
    ),
    /// Merging can be done by dropping any old buckets and adding the new ones. Overlapping buckets are
    /// guaranteed to align (same bucket end timestamp) and the older version of the bucket can be replaced
    /// with the newer ones.
    ArrowBucketedStruct(super::super::super::super::scout::compute::api::ArrowPlot),
    /// Merging can be done by dropping any old points and adding the new ones, accounting for overlaps
    ArrowStruct(super::super::super::super::scout::compute::api::ArrowPlot),
    /// Merging can be done by dropping any old points and adding the new ones, accounting for overlaps
    ArrowLog(super::super::super::super::scout::compute::api::ArrowPlot),
    /// Appends can be done by doing an append individually for each contained `ComputeNodeAppendResponse`.
    Grouped(super::GroupedComputeNodeAppendResponses),
    /// An unknown variant.
    Unknown(Unknown),
}
impl ser::Serialize for ComputeNodeAppendResponse {
    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 {
            ComputeNodeAppendResponse::Range(value) => {
                map.serialize_entry(&"type", &"range")?;
                map.serialize_entry(&"range", value)?;
            }
            ComputeNodeAppendResponse::EnumPoint(value) => {
                map.serialize_entry(&"type", &"enumPoint")?;
                map.serialize_entry(&"enumPoint", value)?;
            }
            ComputeNodeAppendResponse::NumericPoint(value) => {
                map.serialize_entry(&"type", &"numericPoint")?;
                map.serialize_entry(&"numericPoint", value)?;
            }
            ComputeNodeAppendResponse::SinglePoint(value) => {
                map.serialize_entry(&"type", &"singlePoint")?;
                map.serialize_entry(&"singlePoint", value)?;
            }
            ComputeNodeAppendResponse::LogPoint(value) => {
                map.serialize_entry(&"type", &"logPoint")?;
                map.serialize_entry(&"logPoint", value)?;
            }
            ComputeNodeAppendResponse::RangeValue(value) => {
                map.serialize_entry(&"type", &"rangeValue")?;
                map.serialize_entry(&"rangeValue", value)?;
            }
            ComputeNodeAppendResponse::Numeric(value) => {
                map.serialize_entry(&"type", &"numeric")?;
                map.serialize_entry(&"numeric", value)?;
            }
            ComputeNodeAppendResponse::Enum(value) => {
                map.serialize_entry(&"type", &"enum")?;
                map.serialize_entry(&"enum", value)?;
            }
            ComputeNodeAppendResponse::Log(value) => {
                map.serialize_entry(&"type", &"log")?;
                map.serialize_entry(&"log", value)?;
            }
            ComputeNodeAppendResponse::BucketedNumeric(value) => {
                map.serialize_entry(&"type", &"bucketedNumeric")?;
                map.serialize_entry(&"bucketedNumeric", value)?;
            }
            ComputeNodeAppendResponse::BucketedEnum(value) => {
                map.serialize_entry(&"type", &"bucketedEnum")?;
                map.serialize_entry(&"bucketedEnum", value)?;
            }
            ComputeNodeAppendResponse::Multivariate(value) => {
                map.serialize_entry(&"type", &"multivariate")?;
                map.serialize_entry(&"multivariate", value)?;
            }
            ComputeNodeAppendResponse::ArrowNumeric(value) => {
                map.serialize_entry(&"type", &"arrowNumeric")?;
                map.serialize_entry(&"arrowNumeric", value)?;
            }
            ComputeNodeAppendResponse::ArrowEnum(value) => {
                map.serialize_entry(&"type", &"arrowEnum")?;
                map.serialize_entry(&"arrowEnum", value)?;
            }
            ComputeNodeAppendResponse::ArrowBucketedNumeric(value) => {
                map.serialize_entry(&"type", &"arrowBucketedNumeric")?;
                map.serialize_entry(&"arrowBucketedNumeric", value)?;
            }
            ComputeNodeAppendResponse::ArrowBucketedEnum(value) => {
                map.serialize_entry(&"type", &"arrowBucketedEnum")?;
                map.serialize_entry(&"arrowBucketedEnum", value)?;
            }
            ComputeNodeAppendResponse::ArrowBucketedMultivariate(value) => {
                map.serialize_entry(&"type", &"arrowBucketedMultivariate")?;
                map.serialize_entry(&"arrowBucketedMultivariate", value)?;
            }
            ComputeNodeAppendResponse::ArrowBucketedStruct(value) => {
                map.serialize_entry(&"type", &"arrowBucketedStruct")?;
                map.serialize_entry(&"arrowBucketedStruct", value)?;
            }
            ComputeNodeAppendResponse::ArrowStruct(value) => {
                map.serialize_entry(&"type", &"arrowStruct")?;
                map.serialize_entry(&"arrowStruct", value)?;
            }
            ComputeNodeAppendResponse::ArrowLog(value) => {
                map.serialize_entry(&"type", &"arrowLog")?;
                map.serialize_entry(&"arrowLog", value)?;
            }
            ComputeNodeAppendResponse::Grouped(value) => {
                map.serialize_entry(&"type", &"grouped")?;
                map.serialize_entry(&"grouped", value)?;
            }
            ComputeNodeAppendResponse::Unknown(value) => {
                map.serialize_entry(&"type", &value.type_)?;
                map.serialize_entry(&value.type_, &value.value)?;
            }
        }
        map.end()
    }
}
impl<'de> de::Deserialize<'de> for ComputeNodeAppendResponse {
    fn deserialize<D>(d: D) -> Result<ComputeNodeAppendResponse, D::Error>
    where
        D: de::Deserializer<'de>,
    {
        d.deserialize_map(Visitor_)
    }
}
struct Visitor_;
impl<'de> de::Visitor<'de> for Visitor_ {
    type Value = ComputeNodeAppendResponse;
    fn expecting(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
        fmt.write_str("union ComputeNodeAppendResponse")
    }
    fn visit_map<A>(self, mut map: A) -> Result<ComputeNodeAppendResponse, 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_::Range, Some(Variant_::Range)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Range(value)
                    }
                    (Variant_::EnumPoint, Some(Variant_::EnumPoint)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::EnumPoint(value)
                    }
                    (Variant_::NumericPoint, Some(Variant_::NumericPoint)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::NumericPoint(value)
                    }
                    (Variant_::SinglePoint, Some(Variant_::SinglePoint)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::SinglePoint(value)
                    }
                    (Variant_::LogPoint, Some(Variant_::LogPoint)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::LogPoint(value)
                    }
                    (Variant_::RangeValue, Some(Variant_::RangeValue)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::RangeValue(value)
                    }
                    (Variant_::Numeric, Some(Variant_::Numeric)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Numeric(value)
                    }
                    (Variant_::Enum, Some(Variant_::Enum)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Enum(value)
                    }
                    (Variant_::Log, Some(Variant_::Log)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Log(value)
                    }
                    (Variant_::BucketedNumeric, Some(Variant_::BucketedNumeric)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::BucketedNumeric(value)
                    }
                    (Variant_::BucketedEnum, Some(Variant_::BucketedEnum)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::BucketedEnum(value)
                    }
                    (Variant_::Multivariate, Some(Variant_::Multivariate)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Multivariate(value)
                    }
                    (Variant_::ArrowNumeric, Some(Variant_::ArrowNumeric)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowNumeric(value)
                    }
                    (Variant_::ArrowEnum, Some(Variant_::ArrowEnum)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowEnum(value)
                    }
                    (
                        Variant_::ArrowBucketedNumeric,
                        Some(Variant_::ArrowBucketedNumeric),
                    ) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedNumeric(value)
                    }
                    (Variant_::ArrowBucketedEnum, Some(Variant_::ArrowBucketedEnum)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedEnum(value)
                    }
                    (
                        Variant_::ArrowBucketedMultivariate,
                        Some(Variant_::ArrowBucketedMultivariate),
                    ) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedMultivariate(value)
                    }
                    (
                        Variant_::ArrowBucketedStruct,
                        Some(Variant_::ArrowBucketedStruct),
                    ) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedStruct(value)
                    }
                    (Variant_::ArrowStruct, Some(Variant_::ArrowStruct)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowStruct(value)
                    }
                    (Variant_::ArrowLog, Some(Variant_::ArrowLog)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowLog(value)
                    }
                    (Variant_::Grouped, Some(Variant_::Grouped)) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Grouped(value)
                    }
                    (Variant_::Unknown(type_), Some(Variant_::Unknown(b))) => {
                        if type_ == b {
                            let value = map.next_value()?;
                            ComputeNodeAppendResponse::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_::Range => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Range(value)
                    }
                    Variant_::EnumPoint => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::EnumPoint(value)
                    }
                    Variant_::NumericPoint => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::NumericPoint(value)
                    }
                    Variant_::SinglePoint => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::SinglePoint(value)
                    }
                    Variant_::LogPoint => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::LogPoint(value)
                    }
                    Variant_::RangeValue => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::RangeValue(value)
                    }
                    Variant_::Numeric => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Numeric(value)
                    }
                    Variant_::Enum => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Enum(value)
                    }
                    Variant_::Log => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Log(value)
                    }
                    Variant_::BucketedNumeric => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::BucketedNumeric(value)
                    }
                    Variant_::BucketedEnum => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::BucketedEnum(value)
                    }
                    Variant_::Multivariate => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Multivariate(value)
                    }
                    Variant_::ArrowNumeric => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowNumeric(value)
                    }
                    Variant_::ArrowEnum => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowEnum(value)
                    }
                    Variant_::ArrowBucketedNumeric => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedNumeric(value)
                    }
                    Variant_::ArrowBucketedEnum => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedEnum(value)
                    }
                    Variant_::ArrowBucketedMultivariate => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedMultivariate(value)
                    }
                    Variant_::ArrowBucketedStruct => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowBucketedStruct(value)
                    }
                    Variant_::ArrowStruct => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowStruct(value)
                    }
                    Variant_::ArrowLog => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::ArrowLog(value)
                    }
                    Variant_::Grouped => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::Grouped(value)
                    }
                    Variant_::Unknown(type_) => {
                        let value = map.next_value()?;
                        ComputeNodeAppendResponse::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_ {
    Range,
    EnumPoint,
    NumericPoint,
    SinglePoint,
    LogPoint,
    RangeValue,
    Numeric,
    Enum,
    Log,
    BucketedNumeric,
    BucketedEnum,
    Multivariate,
    ArrowNumeric,
    ArrowEnum,
    ArrowBucketedNumeric,
    ArrowBucketedEnum,
    ArrowBucketedMultivariate,
    ArrowBucketedStruct,
    ArrowStruct,
    ArrowLog,
    Grouped,
    Unknown(Box<str>),
}
impl Variant_ {
    fn as_str(&self) -> &'static str {
        match *self {
            Variant_::Range => "range",
            Variant_::EnumPoint => "enumPoint",
            Variant_::NumericPoint => "numericPoint",
            Variant_::SinglePoint => "singlePoint",
            Variant_::LogPoint => "logPoint",
            Variant_::RangeValue => "rangeValue",
            Variant_::Numeric => "numeric",
            Variant_::Enum => "enum",
            Variant_::Log => "log",
            Variant_::BucketedNumeric => "bucketedNumeric",
            Variant_::BucketedEnum => "bucketedEnum",
            Variant_::Multivariate => "multivariate",
            Variant_::ArrowNumeric => "arrowNumeric",
            Variant_::ArrowEnum => "arrowEnum",
            Variant_::ArrowBucketedNumeric => "arrowBucketedNumeric",
            Variant_::ArrowBucketedEnum => "arrowBucketedEnum",
            Variant_::ArrowBucketedMultivariate => "arrowBucketedMultivariate",
            Variant_::ArrowBucketedStruct => "arrowBucketedStruct",
            Variant_::ArrowStruct => "arrowStruct",
            Variant_::ArrowLog => "arrowLog",
            Variant_::Grouped => "grouped",
            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 {
            "range" => Variant_::Range,
            "enumPoint" => Variant_::EnumPoint,
            "numericPoint" => Variant_::NumericPoint,
            "singlePoint" => Variant_::SinglePoint,
            "logPoint" => Variant_::LogPoint,
            "rangeValue" => Variant_::RangeValue,
            "numeric" => Variant_::Numeric,
            "enum" => Variant_::Enum,
            "log" => Variant_::Log,
            "bucketedNumeric" => Variant_::BucketedNumeric,
            "bucketedEnum" => Variant_::BucketedEnum,
            "multivariate" => Variant_::Multivariate,
            "arrowNumeric" => Variant_::ArrowNumeric,
            "arrowEnum" => Variant_::ArrowEnum,
            "arrowBucketedNumeric" => Variant_::ArrowBucketedNumeric,
            "arrowBucketedEnum" => Variant_::ArrowBucketedEnum,
            "arrowBucketedMultivariate" => Variant_::ArrowBucketedMultivariate,
            "arrowBucketedStruct" => Variant_::ArrowBucketedStruct,
            "arrowStruct" => Variant_::ArrowStruct,
            "arrowLog" => Variant_::ArrowLog,
            "grouped" => Variant_::Grouped,
            value => Variant_::Unknown(value.to_string().into_boxed_str()),
        };
        Ok(v)
    }
}
///An unknown variant of the ComputeNodeAppendResponse 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_
    }
}
