// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: dev.sensorthings.observationBatch
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::dev_sensorthings::observation_batch;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct BatchEntry<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub q: Option<BatchEntryQ<S>>,
    ///Observation result, same union as dev.sensorthings.observation
    pub result: BatchEntryResult<S>,
    ///phenomenonTime
    pub t: Datetime,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BatchEntryQ<S: BosStr = DefaultStr> {
    Good,
    Suspect,
    Missing,
    Other(S),
}

impl<S: BosStr> BatchEntryQ<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Good => "dev.sensorthings.quality#good",
            Self::Suspect => "dev.sensorthings.quality#suspect",
            Self::Missing => "dev.sensorthings.quality#missing",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "dev.sensorthings.quality#good" => Self::Good,
            "dev.sensorthings.quality#suspect" => Self::Suspect,
            "dev.sensorthings.quality#missing" => Self::Missing,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for BatchEntryQ<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for BatchEntryQ<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for BatchEntryQ<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for BatchEntryQ<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for BatchEntryQ<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for BatchEntryQ<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = BatchEntryQ<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            BatchEntryQ::Good => BatchEntryQ::Good,
            BatchEntryQ::Suspect => BatchEntryQ::Suspect,
            BatchEntryQ::Missing => BatchEntryQ::Missing,
            BatchEntryQ::Other(v) => BatchEntryQ::Other(v.into_static()),
        }
    }
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum BatchEntryResult<S: BosStr = DefaultStr> {}
/// A batch of observations for a single Datastream, covering a contiguous time window. Trades individual addressability for reduced commit overhead.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "dev.sensorthings.observationBatch",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ObservationBatch<S: BosStr = DefaultStr> {
    pub datastream: AtUri<S>,
    ///Array of observations in chronological order
    pub observations: Vec<observation_batch::BatchEntry<S>>,
    pub window_end: Datetime,
    pub window_start: Datetime,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ObservationBatchGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: ObservationBatch<S>,
}

impl<S: BosStr> ObservationBatch<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, ObservationBatchRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

impl<S: BosStr> LexiconSchema for BatchEntry<S> {
    fn nsid() -> &'static str {
        "dev.sensorthings.observationBatch"
    }
    fn def_name() -> &'static str {
        "batchEntry"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_sensorthings_observationBatch()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct ObservationBatchRecord;
impl XrpcResp for ObservationBatchRecord {
    const NSID: &'static str = "dev.sensorthings.observationBatch";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ObservationBatchGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<ObservationBatchGetRecordOutput<S>> for ObservationBatch<S> {
    fn from(output: ObservationBatchGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for ObservationBatch<S> {
    const NSID: &'static str = "dev.sensorthings.observationBatch";
    type Record = ObservationBatchRecord;
}

impl Collection for ObservationBatchRecord {
    const NSID: &'static str = "dev.sensorthings.observationBatch";
    type Record = ObservationBatchRecord;
}

impl<S: BosStr> LexiconSchema for ObservationBatch<S> {
    fn nsid() -> &'static str {
        "dev.sensorthings.observationBatch"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_sensorthings_observationBatch()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.observations;
            #[allow(unused_comparisons)]
            if value.len() > 1440usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("observations"),
                    max: 1440usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

pub mod batch_entry_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Result;
        type T;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Result = Unset;
        type T = Unset;
    }
    ///State transition - sets the `result` field to Set
    pub struct SetResult<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetResult<St> {}
    impl<St: State> State for SetResult<St> {
        type Result = Set<members::result>;
        type T = St::T;
    }
    ///State transition - sets the `t` field to Set
    pub struct SetT<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetT<St> {}
    impl<St: State> State for SetT<St> {
        type Result = St::Result;
        type T = Set<members::t>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `result` field
        pub struct result(());
        ///Marker type for the `t` field
        pub struct t(());
    }
}

/// Builder for constructing an instance of this type.
pub struct BatchEntryBuilder<St: batch_entry_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<BatchEntryQ<S>>, Option<BatchEntryResult<S>>, Option<Datetime>),
    _type: PhantomData<fn() -> S>,
}

impl BatchEntry<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> BatchEntryBuilder<batch_entry_state::Empty, DefaultStr> {
        BatchEntryBuilder::new()
    }
}

impl<S: BosStr> BatchEntry<S> {
    /// Create a new builder for this type
    pub fn builder() -> BatchEntryBuilder<batch_entry_state::Empty, S> {
        BatchEntryBuilder::builder()
    }
}

impl BatchEntryBuilder<batch_entry_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        BatchEntryBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> BatchEntryBuilder<batch_entry_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        BatchEntryBuilder {
            _state: PhantomData,
            _fields: (None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St: batch_entry_state::State, S: BosStr> BatchEntryBuilder<St, S> {
    /// Set the `q` field (optional)
    pub fn q(mut self, value: impl Into<Option<BatchEntryQ<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `q` field to an Option value (optional)
    pub fn maybe_q(mut self, value: Option<BatchEntryQ<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> BatchEntryBuilder<St, S>
where
    St: batch_entry_state::State,
    St::Result: batch_entry_state::IsUnset,
{
    /// Set the `result` field (required)
    pub fn result(
        mut self,
        value: impl Into<BatchEntryResult<S>>,
    ) -> BatchEntryBuilder<batch_entry_state::SetResult<St>, S> {
        self._fields.1 = Option::Some(value.into());
        BatchEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BatchEntryBuilder<St, S>
where
    St: batch_entry_state::State,
    St::T: batch_entry_state::IsUnset,
{
    /// Set the `t` field (required)
    pub fn t(
        mut self,
        value: impl Into<Datetime>,
    ) -> BatchEntryBuilder<batch_entry_state::SetT<St>, S> {
        self._fields.2 = Option::Some(value.into());
        BatchEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BatchEntryBuilder<St, S>
where
    St: batch_entry_state::State,
    St::Result: batch_entry_state::IsSet,
    St::T: batch_entry_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> BatchEntry<S> {
        BatchEntry {
            q: self._fields.0,
            result: self._fields.1.unwrap(),
            t: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> BatchEntry<S> {
        BatchEntry {
            q: self._fields.0,
            result: self._fields.1.unwrap(),
            t: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_dev_sensorthings_observationBatch() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("dev.sensorthings.observationBatch"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("batchEntry"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("t"), SmolStr::new_static("result")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("q"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("result"),
                            LexObjectProperty::Union(LexRefUnion {
                                description: Some(
                                    CowStr::new_static(
                                        "Observation result, same union as dev.sensorthings.observation",
                                    ),
                                ),
                                refs: vec![
                                    CowStr::new_static("dev.sensorthings.observation#numericResult"),
                                    CowStr::new_static("dev.sensorthings.observation#categoryResult"),
                                    CowStr::new_static("dev.sensorthings.observation#booleanResult"),
                                    CowStr::new_static("dev.sensorthings.observation#arrayResult"),
                                    CowStr::new_static("dev.sensorthings.observation#geoPointResult")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("t"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("phenomenonTime")),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A batch of observations for a single Datastream, covering a contiguous time window. Trades individual addressability for reduced commit overhead.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("datastream"),
                                SmolStr::new_static("windowStart"),
                                SmolStr::new_static("windowEnd"),
                                SmolStr::new_static("observations")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("datastream"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("observations"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Array of observations in chronological order",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#batchEntry"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(1440usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("windowEnd"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("windowStart"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod observation_batch_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Datastream;
        type Observations;
        type WindowEnd;
        type WindowStart;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Datastream = Unset;
        type Observations = Unset;
        type WindowEnd = Unset;
        type WindowStart = Unset;
    }
    ///State transition - sets the `datastream` field to Set
    pub struct SetDatastream<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDatastream<St> {}
    impl<St: State> State for SetDatastream<St> {
        type Datastream = Set<members::datastream>;
        type Observations = St::Observations;
        type WindowEnd = St::WindowEnd;
        type WindowStart = St::WindowStart;
    }
    ///State transition - sets the `observations` field to Set
    pub struct SetObservations<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetObservations<St> {}
    impl<St: State> State for SetObservations<St> {
        type Datastream = St::Datastream;
        type Observations = Set<members::observations>;
        type WindowEnd = St::WindowEnd;
        type WindowStart = St::WindowStart;
    }
    ///State transition - sets the `window_end` field to Set
    pub struct SetWindowEnd<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetWindowEnd<St> {}
    impl<St: State> State for SetWindowEnd<St> {
        type Datastream = St::Datastream;
        type Observations = St::Observations;
        type WindowEnd = Set<members::window_end>;
        type WindowStart = St::WindowStart;
    }
    ///State transition - sets the `window_start` field to Set
    pub struct SetWindowStart<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetWindowStart<St> {}
    impl<St: State> State for SetWindowStart<St> {
        type Datastream = St::Datastream;
        type Observations = St::Observations;
        type WindowEnd = St::WindowEnd;
        type WindowStart = Set<members::window_start>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `datastream` field
        pub struct datastream(());
        ///Marker type for the `observations` field
        pub struct observations(());
        ///Marker type for the `window_end` field
        pub struct window_end(());
        ///Marker type for the `window_start` field
        pub struct window_start(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ObservationBatchBuilder<
    St: observation_batch_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<AtUri<S>>,
        Option<Vec<observation_batch::BatchEntry<S>>>,
        Option<Datetime>,
        Option<Datetime>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl ObservationBatch<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> ObservationBatchBuilder<observation_batch_state::Empty, DefaultStr> {
        ObservationBatchBuilder::new()
    }
}

impl<S: BosStr> ObservationBatch<S> {
    /// Create a new builder for this type
    pub fn builder() -> ObservationBatchBuilder<observation_batch_state::Empty, S> {
        ObservationBatchBuilder::builder()
    }
}

impl ObservationBatchBuilder<observation_batch_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        ObservationBatchBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> ObservationBatchBuilder<observation_batch_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        ObservationBatchBuilder {
            _state: PhantomData,
            _fields: (None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ObservationBatchBuilder<St, S>
where
    St: observation_batch_state::State,
    St::Datastream: observation_batch_state::IsUnset,
{
    /// Set the `datastream` field (required)
    pub fn datastream(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ObservationBatchBuilder<observation_batch_state::SetDatastream<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ObservationBatchBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ObservationBatchBuilder<St, S>
where
    St: observation_batch_state::State,
    St::Observations: observation_batch_state::IsUnset,
{
    /// Set the `observations` field (required)
    pub fn observations(
        mut self,
        value: impl Into<Vec<observation_batch::BatchEntry<S>>>,
    ) -> ObservationBatchBuilder<observation_batch_state::SetObservations<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ObservationBatchBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ObservationBatchBuilder<St, S>
where
    St: observation_batch_state::State,
    St::WindowEnd: observation_batch_state::IsUnset,
{
    /// Set the `windowEnd` field (required)
    pub fn window_end(
        mut self,
        value: impl Into<Datetime>,
    ) -> ObservationBatchBuilder<observation_batch_state::SetWindowEnd<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ObservationBatchBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ObservationBatchBuilder<St, S>
where
    St: observation_batch_state::State,
    St::WindowStart: observation_batch_state::IsUnset,
{
    /// Set the `windowStart` field (required)
    pub fn window_start(
        mut self,
        value: impl Into<Datetime>,
    ) -> ObservationBatchBuilder<observation_batch_state::SetWindowStart<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ObservationBatchBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ObservationBatchBuilder<St, S>
where
    St: observation_batch_state::State,
    St::Datastream: observation_batch_state::IsSet,
    St::Observations: observation_batch_state::IsSet,
    St::WindowEnd: observation_batch_state::IsSet,
    St::WindowStart: observation_batch_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ObservationBatch<S> {
        ObservationBatch {
            datastream: self._fields.0.unwrap(),
            observations: self._fields.1.unwrap(),
            window_end: self._fields.2.unwrap(),
            window_start: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ObservationBatch<S> {
        ObservationBatch {
            datastream: self._fields.0.unwrap(),
            observations: self._fields.1.unwrap(),
            window_end: self._fields.2.unwrap(),
            window_start: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}