#[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>>,
pub result: BatchEntryResult<S>,
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(),
}
}
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> {}
#[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>,
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>>>,
}
#[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(())
}
}
#[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 {}
}
pub trait State: sealed::Sealed {
type T;
type Result;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type T = Unset;
type Result = Unset;
}
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 T = Set<members::t>;
type Result = St::Result;
}
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 T = St::T;
type Result = Set<members::result>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct t(());
pub struct result(());
}
}
pub struct BatchEntryBuilder<S: BosStr, St: batch_entry_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (Option<BatchEntryQ<S>>, Option<BatchEntryResult<S>>, Option<Datetime>),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> BatchEntry<S> {
pub fn new() -> BatchEntryBuilder<S, batch_entry_state::Empty> {
BatchEntryBuilder::new()
}
}
impl<S: BosStr> BatchEntryBuilder<S, batch_entry_state::Empty> {
pub fn new() -> Self {
BatchEntryBuilder {
_state: PhantomData,
_fields: (None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: batch_entry_state::State> BatchEntryBuilder<S, St> {
pub fn q(mut self, value: impl Into<Option<BatchEntryQ<S>>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_q(mut self, value: Option<BatchEntryQ<S>>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St> BatchEntryBuilder<S, St>
where
St: batch_entry_state::State,
St::Result: batch_entry_state::IsUnset,
{
pub fn result(
mut self,
value: impl Into<BatchEntryResult<S>>,
) -> BatchEntryBuilder<S, batch_entry_state::SetResult<St>> {
self._fields.1 = Option::Some(value.into());
BatchEntryBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BatchEntryBuilder<S, St>
where
St: batch_entry_state::State,
St::T: batch_entry_state::IsUnset,
{
pub fn t(
mut self,
value: impl Into<Datetime>,
) -> BatchEntryBuilder<S, batch_entry_state::SetT<St>> {
self._fields.2 = Option::Some(value.into());
BatchEntryBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BatchEntryBuilder<S, St>
where
St: batch_entry_state::State,
St::T: batch_entry_state::IsSet,
St::Result: batch_entry_state::IsSet,
{
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(),
}
}
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 {}
}
pub trait State: sealed::Sealed {
type Datastream;
type WindowEnd;
type Observations;
type WindowStart;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Datastream = Unset;
type WindowEnd = Unset;
type Observations = Unset;
type WindowStart = Unset;
}
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 WindowEnd = St::WindowEnd;
type Observations = St::Observations;
type WindowStart = St::WindowStart;
}
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 WindowEnd = Set<members::window_end>;
type Observations = St::Observations;
type WindowStart = St::WindowStart;
}
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 WindowEnd = St::WindowEnd;
type Observations = Set<members::observations>;
type WindowStart = St::WindowStart;
}
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 WindowEnd = St::WindowEnd;
type Observations = St::Observations;
type WindowStart = Set<members::window_start>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct datastream(());
pub struct window_end(());
pub struct observations(());
pub struct window_start(());
}
}
pub struct ObservationBatchBuilder<S: BosStr, St: observation_batch_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<AtUri<S>>,
Option<Vec<observation_batch::BatchEntry<S>>>,
Option<Datetime>,
Option<Datetime>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> ObservationBatch<S> {
pub fn new() -> ObservationBatchBuilder<S, observation_batch_state::Empty> {
ObservationBatchBuilder::new()
}
}
impl<S: BosStr> ObservationBatchBuilder<S, observation_batch_state::Empty> {
pub fn new() -> Self {
ObservationBatchBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ObservationBatchBuilder<S, St>
where
St: observation_batch_state::State,
St::Datastream: observation_batch_state::IsUnset,
{
pub fn datastream(
mut self,
value: impl Into<AtUri<S>>,
) -> ObservationBatchBuilder<S, observation_batch_state::SetDatastream<St>> {
self._fields.0 = Option::Some(value.into());
ObservationBatchBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ObservationBatchBuilder<S, St>
where
St: observation_batch_state::State,
St::Observations: observation_batch_state::IsUnset,
{
pub fn observations(
mut self,
value: impl Into<Vec<observation_batch::BatchEntry<S>>>,
) -> ObservationBatchBuilder<S, observation_batch_state::SetObservations<St>> {
self._fields.1 = Option::Some(value.into());
ObservationBatchBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ObservationBatchBuilder<S, St>
where
St: observation_batch_state::State,
St::WindowEnd: observation_batch_state::IsUnset,
{
pub fn window_end(
mut self,
value: impl Into<Datetime>,
) -> ObservationBatchBuilder<S, observation_batch_state::SetWindowEnd<St>> {
self._fields.2 = Option::Some(value.into());
ObservationBatchBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ObservationBatchBuilder<S, St>
where
St: observation_batch_state::State,
St::WindowStart: observation_batch_state::IsUnset,
{
pub fn window_start(
mut self,
value: impl Into<Datetime>,
) -> ObservationBatchBuilder<S, observation_batch_state::SetWindowStart<St>> {
self._fields.3 = Option::Some(value.into());
ObservationBatchBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> ObservationBatchBuilder<S, St>
where
St: observation_batch_state::State,
St::Datastream: observation_batch_state::IsSet,
St::WindowEnd: observation_batch_state::IsSet,
St::Observations: observation_batch_state::IsSet,
St::WindowStart: observation_batch_state::IsSet,
{
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(),
}
}
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),
}
}
}