// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: dev.sensorthings.datastream
//
// 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, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
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::datastream;
/// Groups Observations of one ObservedProperty by one Sensor on one Thing. Carries all context needed to interpret observation results.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "dev.sensorthings.datastream",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Datastream<S: BosStr = DefaultStr> {
    pub created_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    pub name: S,
    ///O&M observation type URI, e.g. http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement
    pub observation_type: UriValue<S>,
    ///Representative location for the datastream
    #[serde(skip_serializing_if = "Option::is_none")]
    pub observed_area: Option<Data<S>>,
    ///AT-URI of the dev.sensorthings.observedProperty record
    pub observed_property: AtUri<S>,
    ///10^n divisor for numeric results. E.g. 2 means observation integers are in centi-units (÷100). Default 0. Only meaningful for numericResult and arrayResult types.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub result_scale_factor: Option<i64>,
    ///AT-URI of the dev.sensorthings.sensor record
    pub sensor: AtUri<S>,
    ///AT-URI of the dev.sensorthings.thing record
    pub thing: AtUri<S>,
    pub unit_of_measurement: datastream::UnitOfMeasurement<S>,
    ///Vertical datum reference for water level or elevation measurements. Either a URI (e.g. http://www.opengis.net/def/crs/EPSG/0/5731 for Malin Head) or a human-readable identifier (e.g. 'Chart Datum', 'local-gauge-zero'). Absent for non-vertical measurements.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub vertical_datum: Option<S>,
    #[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 DatastreamGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Datastream<S>,
}

/// UCUM-compatible unit description.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UnitOfMeasurement<S: BosStr = DefaultStr> {
    ///URI from QUDT, UCUM, or similar unit ontology
    #[serde(skip_serializing_if = "Option::is_none")]
    pub definition: Option<UriValue<S>>,
    pub name: S,
    pub symbol: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

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

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

impl<S: BosStr> LexiconSchema for Datastream<S> {
    fn nsid() -> &'static str {
        "dev.sensorthings.datastream"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_sensorthings_datastream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2048usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 2048usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.vertical_datum {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("vertical_datum"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for UnitOfMeasurement<S> {
    fn nsid() -> &'static str {
        "dev.sensorthings.datastream"
    }
    fn def_name() -> &'static str {
        "unitOfMeasurement"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_sensorthings_datastream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.symbol;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("symbol"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod datastream_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 CreatedAt;
        type Name;
        type ObservationType;
        type ObservedProperty;
        type Sensor;
        type Thing;
        type UnitOfMeasurement;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Name = Unset;
        type ObservationType = Unset;
        type ObservedProperty = Unset;
        type Sensor = Unset;
        type Thing = Unset;
        type UnitOfMeasurement = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Name = St::Name;
        type ObservationType = St::ObservationType;
        type ObservedProperty = St::ObservedProperty;
        type Sensor = St::Sensor;
        type Thing = St::Thing;
        type UnitOfMeasurement = St::UnitOfMeasurement;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type CreatedAt = St::CreatedAt;
        type Name = Set<members::name>;
        type ObservationType = St::ObservationType;
        type ObservedProperty = St::ObservedProperty;
        type Sensor = St::Sensor;
        type Thing = St::Thing;
        type UnitOfMeasurement = St::UnitOfMeasurement;
    }
    ///State transition - sets the `observation_type` field to Set
    pub struct SetObservationType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetObservationType<St> {}
    impl<St: State> State for SetObservationType<St> {
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
        type ObservationType = Set<members::observation_type>;
        type ObservedProperty = St::ObservedProperty;
        type Sensor = St::Sensor;
        type Thing = St::Thing;
        type UnitOfMeasurement = St::UnitOfMeasurement;
    }
    ///State transition - sets the `observed_property` field to Set
    pub struct SetObservedProperty<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetObservedProperty<St> {}
    impl<St: State> State for SetObservedProperty<St> {
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
        type ObservationType = St::ObservationType;
        type ObservedProperty = Set<members::observed_property>;
        type Sensor = St::Sensor;
        type Thing = St::Thing;
        type UnitOfMeasurement = St::UnitOfMeasurement;
    }
    ///State transition - sets the `sensor` field to Set
    pub struct SetSensor<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSensor<St> {}
    impl<St: State> State for SetSensor<St> {
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
        type ObservationType = St::ObservationType;
        type ObservedProperty = St::ObservedProperty;
        type Sensor = Set<members::sensor>;
        type Thing = St::Thing;
        type UnitOfMeasurement = St::UnitOfMeasurement;
    }
    ///State transition - sets the `thing` field to Set
    pub struct SetThing<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetThing<St> {}
    impl<St: State> State for SetThing<St> {
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
        type ObservationType = St::ObservationType;
        type ObservedProperty = St::ObservedProperty;
        type Sensor = St::Sensor;
        type Thing = Set<members::thing>;
        type UnitOfMeasurement = St::UnitOfMeasurement;
    }
    ///State transition - sets the `unit_of_measurement` field to Set
    pub struct SetUnitOfMeasurement<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUnitOfMeasurement<St> {}
    impl<St: State> State for SetUnitOfMeasurement<St> {
        type CreatedAt = St::CreatedAt;
        type Name = St::Name;
        type ObservationType = St::ObservationType;
        type ObservedProperty = St::ObservedProperty;
        type Sensor = St::Sensor;
        type Thing = St::Thing;
        type UnitOfMeasurement = Set<members::unit_of_measurement>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `observation_type` field
        pub struct observation_type(());
        ///Marker type for the `observed_property` field
        pub struct observed_property(());
        ///Marker type for the `sensor` field
        pub struct sensor(());
        ///Marker type for the `thing` field
        pub struct thing(());
        ///Marker type for the `unit_of_measurement` field
        pub struct unit_of_measurement(());
    }
}

/// Builder for constructing an instance of this type.
pub struct DatastreamBuilder<St: datastream_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Datetime>,
        Option<S>,
        Option<S>,
        Option<UriValue<S>>,
        Option<Data<S>>,
        Option<AtUri<S>>,
        Option<i64>,
        Option<AtUri<S>>,
        Option<AtUri<S>>,
        Option<datastream::UnitOfMeasurement<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Datastream<S> {
    /// Create a new builder for this type
    pub fn builder() -> DatastreamBuilder<datastream_state::Empty, S> {
        DatastreamBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::CreatedAt: datastream_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> DatastreamBuilder<datastream_state::SetCreatedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        DatastreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: datastream_state::State, S: BosStr> DatastreamBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::Name: datastream_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<S>,
    ) -> DatastreamBuilder<datastream_state::SetName<St>, S> {
        self._fields.2 = Option::Some(value.into());
        DatastreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::ObservationType: datastream_state::IsUnset,
{
    /// Set the `observationType` field (required)
    pub fn observation_type(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> DatastreamBuilder<datastream_state::SetObservationType<St>, S> {
        self._fields.3 = Option::Some(value.into());
        DatastreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: datastream_state::State, S: BosStr> DatastreamBuilder<St, S> {
    /// Set the `observedArea` field (optional)
    pub fn observed_area(mut self, value: impl Into<Option<Data<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `observedArea` field to an Option value (optional)
    pub fn maybe_observed_area(mut self, value: Option<Data<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::ObservedProperty: datastream_state::IsUnset,
{
    /// Set the `observedProperty` field (required)
    pub fn observed_property(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> DatastreamBuilder<datastream_state::SetObservedProperty<St>, S> {
        self._fields.5 = Option::Some(value.into());
        DatastreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: datastream_state::State, S: BosStr> DatastreamBuilder<St, S> {
    /// Set the `resultScaleFactor` field (optional)
    pub fn result_scale_factor(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `resultScaleFactor` field to an Option value (optional)
    pub fn maybe_result_scale_factor(mut self, value: Option<i64>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::Sensor: datastream_state::IsUnset,
{
    /// Set the `sensor` field (required)
    pub fn sensor(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> DatastreamBuilder<datastream_state::SetSensor<St>, S> {
        self._fields.7 = Option::Some(value.into());
        DatastreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::Thing: datastream_state::IsUnset,
{
    /// Set the `thing` field (required)
    pub fn thing(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> DatastreamBuilder<datastream_state::SetThing<St>, S> {
        self._fields.8 = Option::Some(value.into());
        DatastreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::UnitOfMeasurement: datastream_state::IsUnset,
{
    /// Set the `unitOfMeasurement` field (required)
    pub fn unit_of_measurement(
        mut self,
        value: impl Into<datastream::UnitOfMeasurement<S>>,
    ) -> DatastreamBuilder<datastream_state::SetUnitOfMeasurement<St>, S> {
        self._fields.9 = Option::Some(value.into());
        DatastreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: datastream_state::State, S: BosStr> DatastreamBuilder<St, S> {
    /// Set the `verticalDatum` field (optional)
    pub fn vertical_datum(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `verticalDatum` field to an Option value (optional)
    pub fn maybe_vertical_datum(mut self, value: Option<S>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St, S: BosStr> DatastreamBuilder<St, S>
where
    St: datastream_state::State,
    St::CreatedAt: datastream_state::IsSet,
    St::Name: datastream_state::IsSet,
    St::ObservationType: datastream_state::IsSet,
    St::ObservedProperty: datastream_state::IsSet,
    St::Sensor: datastream_state::IsSet,
    St::Thing: datastream_state::IsSet,
    St::UnitOfMeasurement: datastream_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Datastream<S> {
        Datastream {
            created_at: self._fields.0.unwrap(),
            description: self._fields.1,
            name: self._fields.2.unwrap(),
            observation_type: self._fields.3.unwrap(),
            observed_area: self._fields.4,
            observed_property: self._fields.5.unwrap(),
            result_scale_factor: self._fields.6,
            sensor: self._fields.7.unwrap(),
            thing: self._fields.8.unwrap(),
            unit_of_measurement: self._fields.9.unwrap(),
            vertical_datum: self._fields.10,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Datastream<S> {
        Datastream {
            created_at: self._fields.0.unwrap(),
            description: self._fields.1,
            name: self._fields.2.unwrap(),
            observation_type: self._fields.3.unwrap(),
            observed_area: self._fields.4,
            observed_property: self._fields.5.unwrap(),
            result_scale_factor: self._fields.6,
            sensor: self._fields.7.unwrap(),
            thing: self._fields.8.unwrap(),
            unit_of_measurement: self._fields.9.unwrap(),
            vertical_datum: self._fields.10,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_dev_sensorthings_datastream() -> 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.datastream"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Groups Observations of one ObservedProperty by one Sensor on one Thing. Carries all context needed to interpret observation results.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"), SmolStr::new_static("thing"),
                                SmolStr::new_static("sensor"),
                                SmolStr::new_static("observedProperty"),
                                SmolStr::new_static("unitOfMeasurement"),
                                SmolStr::new_static("observationType"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    max_length: Some(2048usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::String(LexString {
                                    max_length: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("observationType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "O&M observation type URI, e.g. http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("observedArea"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "dev.sensorthings.thing#geoPoint",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("observedProperty"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT-URI of the dev.sensorthings.observedProperty record",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("resultScaleFactor"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sensor"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT-URI of the dev.sensorthings.sensor record",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("thing"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT-URI of the dev.sensorthings.thing record",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("unitOfMeasurement"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#unitOfMeasurement"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("verticalDatum"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Vertical datum reference for water level or elevation measurements. Either a URI (e.g. http://www.opengis.net/def/crs/EPSG/0/5731 for Malin Head) or a human-readable identifier (e.g. 'Chart Datum', 'local-gauge-zero'). Absent for non-vertical measurements.",
                                        ),
                                    ),
                                    max_length: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("unitOfMeasurement"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("UCUM-compatible unit description."),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("name"), SmolStr::new_static("symbol")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("definition"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "URI from QUDT, UCUM, or similar unit ontology",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("symbol"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}