#[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};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "app.gainforest.dwc.measurement",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Measurement<S: BosStr = DefaultStr> {
pub created_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub measurement_accuracy: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub measurement_determined_by: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub measurement_determined_date: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub measurement_id: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub measurement_method: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub measurement_remarks: Option<S>,
pub measurement_type: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub measurement_unit: Option<S>,
pub measurement_value: S,
#[serde(skip_serializing_if = "Option::is_none")]
pub occurrence_id: Option<S>,
pub occurrence_ref: AtUri<S>,
#[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 MeasurementGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Measurement<S>,
}
impl<S: BosStr> Measurement<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, MeasurementRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct MeasurementRecord;
impl XrpcResp for MeasurementRecord {
const NSID: &'static str = "app.gainforest.dwc.measurement";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = MeasurementGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<MeasurementGetRecordOutput<S>> for Measurement<S> {
fn from(output: MeasurementGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Measurement<S> {
const NSID: &'static str = "app.gainforest.dwc.measurement";
type Record = MeasurementRecord;
}
impl Collection for MeasurementRecord {
const NSID: &'static str = "app.gainforest.dwc.measurement";
type Record = MeasurementRecord;
}
impl<S: BosStr> LexiconSchema for Measurement<S> {
fn nsid() -> &'static str {
"app.gainforest.dwc.measurement"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_app_gainforest_dwc_measurement()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.measurement_accuracy {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 256usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_accuracy"),
max: 256usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.measurement_determined_by {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 512usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_determined_by"),
max: 512usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.measurement_determined_date {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 64usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_determined_date"),
max: 64usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.measurement_id {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 256usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_id"),
max: 256usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.measurement_method {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 1024usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_method"),
max: 1024usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.measurement_remarks {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 5000usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_remarks"),
max: 5000usize,
actual: count,
});
}
}
}
{
let value = &self.measurement_type;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 256usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_type"),
max: 256usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.measurement_unit {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 64usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_unit"),
max: 64usize,
actual: count,
});
}
}
}
{
let value = &self.measurement_value;
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 1024usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("measurement_value"),
max: 1024usize,
actual: count,
});
}
}
}
if let Some(ref value) = self.occurrence_id {
{
let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
if count > 256usize {
return Err(ConstraintError::MaxGraphemes {
path: ValidationPath::from_field("occurrence_id"),
max: 256usize,
actual: count,
});
}
}
}
Ok(())
}
}
pub mod measurement_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 MeasurementValue;
type MeasurementType;
type CreatedAt;
type OccurrenceRef;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type MeasurementValue = Unset;
type MeasurementType = Unset;
type CreatedAt = Unset;
type OccurrenceRef = Unset;
}
pub struct SetMeasurementValue<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMeasurementValue<St> {}
impl<St: State> State for SetMeasurementValue<St> {
type MeasurementValue = Set<members::measurement_value>;
type MeasurementType = St::MeasurementType;
type CreatedAt = St::CreatedAt;
type OccurrenceRef = St::OccurrenceRef;
}
pub struct SetMeasurementType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetMeasurementType<St> {}
impl<St: State> State for SetMeasurementType<St> {
type MeasurementValue = St::MeasurementValue;
type MeasurementType = Set<members::measurement_type>;
type CreatedAt = St::CreatedAt;
type OccurrenceRef = St::OccurrenceRef;
}
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 MeasurementValue = St::MeasurementValue;
type MeasurementType = St::MeasurementType;
type CreatedAt = Set<members::created_at>;
type OccurrenceRef = St::OccurrenceRef;
}
pub struct SetOccurrenceRef<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetOccurrenceRef<St> {}
impl<St: State> State for SetOccurrenceRef<St> {
type MeasurementValue = St::MeasurementValue;
type MeasurementType = St::MeasurementType;
type CreatedAt = St::CreatedAt;
type OccurrenceRef = Set<members::occurrence_ref>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct measurement_value(());
pub struct measurement_type(());
pub struct created_at(());
pub struct occurrence_ref(());
}
}
pub struct MeasurementBuilder<S: BosStr, St: measurement_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<AtUri<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Measurement<S> {
pub fn new() -> MeasurementBuilder<S, measurement_state::Empty> {
MeasurementBuilder::new()
}
}
impl<S: BosStr> MeasurementBuilder<S, measurement_state::Empty> {
pub fn new() -> Self {
MeasurementBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> MeasurementBuilder<S, St>
where
St: measurement_state::State,
St::CreatedAt: measurement_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> MeasurementBuilder<S, measurement_state::SetCreatedAt<St>> {
self._fields.0 = Option::Some(value.into());
MeasurementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn measurement_accuracy(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_measurement_accuracy(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn measurement_determined_by(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_measurement_determined_by(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn measurement_determined_date(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_measurement_determined_date(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn measurement_id(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_measurement_id(mut self, value: Option<S>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn measurement_method(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_measurement_method(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn measurement_remarks(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_measurement_remarks(mut self, value: Option<S>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St> MeasurementBuilder<S, St>
where
St: measurement_state::State,
St::MeasurementType: measurement_state::IsUnset,
{
pub fn measurement_type(
mut self,
value: impl Into<S>,
) -> MeasurementBuilder<S, measurement_state::SetMeasurementType<St>> {
self._fields.7 = Option::Some(value.into());
MeasurementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn measurement_unit(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_measurement_unit(mut self, value: Option<S>) -> Self {
self._fields.8 = value;
self
}
}
impl<S: BosStr, St> MeasurementBuilder<S, St>
where
St: measurement_state::State,
St::MeasurementValue: measurement_state::IsUnset,
{
pub fn measurement_value(
mut self,
value: impl Into<S>,
) -> MeasurementBuilder<S, measurement_state::SetMeasurementValue<St>> {
self._fields.9 = Option::Some(value.into());
MeasurementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: measurement_state::State> MeasurementBuilder<S, St> {
pub fn occurrence_id(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.10 = value.into();
self
}
pub fn maybe_occurrence_id(mut self, value: Option<S>) -> Self {
self._fields.10 = value;
self
}
}
impl<S: BosStr, St> MeasurementBuilder<S, St>
where
St: measurement_state::State,
St::OccurrenceRef: measurement_state::IsUnset,
{
pub fn occurrence_ref(
mut self,
value: impl Into<AtUri<S>>,
) -> MeasurementBuilder<S, measurement_state::SetOccurrenceRef<St>> {
self._fields.11 = Option::Some(value.into());
MeasurementBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> MeasurementBuilder<S, St>
where
St: measurement_state::State,
St::MeasurementValue: measurement_state::IsSet,
St::MeasurementType: measurement_state::IsSet,
St::CreatedAt: measurement_state::IsSet,
St::OccurrenceRef: measurement_state::IsSet,
{
pub fn build(self) -> Measurement<S> {
Measurement {
created_at: self._fields.0.unwrap(),
measurement_accuracy: self._fields.1,
measurement_determined_by: self._fields.2,
measurement_determined_date: self._fields.3,
measurement_id: self._fields.4,
measurement_method: self._fields.5,
measurement_remarks: self._fields.6,
measurement_type: self._fields.7.unwrap(),
measurement_unit: self._fields.8,
measurement_value: self._fields.9.unwrap(),
occurrence_id: self._fields.10,
occurrence_ref: self._fields.11.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> Measurement<S> {
Measurement {
created_at: self._fields.0.unwrap(),
measurement_accuracy: self._fields.1,
measurement_determined_by: self._fields.2,
measurement_determined_date: self._fields.3,
measurement_id: self._fields.4,
measurement_method: self._fields.5,
measurement_remarks: self._fields.6,
measurement_type: self._fields.7.unwrap(),
measurement_unit: self._fields.8,
measurement_value: self._fields.9.unwrap(),
occurrence_id: self._fields.10,
occurrence_ref: self._fields.11.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_app_gainforest_dwc_measurement() -> 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("app.gainforest.dwc.measurement"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A measurement, fact, characteristic, or assertion about an occurrence. Multiple measurement records can reference the same occurrence, solving the Simple DwC one-measurement-per-record limitation.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("occurrenceRef"),
SmolStr::new_static("measurementType"),
SmolStr::new_static("measurementValue"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp of record creation in the ATProto PDS.",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementAccuracy"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The description of the potential error associated with the measurementValue (e.g., '0.5 cm', '5%').",
),
),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementDeterminedBy"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Person(s) who determined the measurement. Pipe-delimited for multiple.",
),
),
max_graphemes: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementDeterminedDate"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The date the measurement was made. ISO 8601 format.",
),
),
max_graphemes: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementID"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"An identifier for the measurement. Should be unique within the dataset.",
),
),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementMethod"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The description of or reference to the method used to determine the measurement (e.g., 'diameter tape at 1.3m height', 'laser rangefinder', 'Bitterlich method').",
),
),
max_graphemes: Some(1024usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementRemarks"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Comments or notes accompanying the measurement.",
),
),
max_graphemes: Some(5000usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The nature of the measurement, fact, characteristic, or assertion (e.g., 'DBH', 'tree height', 'canopy cover', 'tail length', 'body mass', 'soil pH', 'water temperature').",
),
),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementUnit"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The units for the measurementValue (e.g., 'cm', 'm', 'kg', 'mm', '%', 'degrees Celsius').",
),
),
max_graphemes: Some(64usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("measurementValue"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The value of the measurement, fact, characteristic, or assertion (e.g., '45.2', 'present', 'blue').",
),
),
max_graphemes: Some(1024usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("occurrenceID"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The occurrenceID of the linked occurrence record (for cross-system interoperability).",
),
),
max_graphemes: Some(256usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("occurrenceRef"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"AT-URI reference to the app.gainforest.dwc.occurrence record this measurement belongs to.",
),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}