#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, 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;
use crate::net_anisota::lab::nightsky::session;
#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ChronicleSignature<S: BosStr = DefaultStr> {
pub alg: S,
pub kid: S,
pub nonce: S,
pub sig: S,
pub signed_at: Datetime,
pub version: i64,
#[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",
rename = "net.anisota.lab.nightsky.session",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Session<S: BosStr = DefaultStr> {
pub created_at: Datetime,
pub duration_ms: i64,
pub ended_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub look_around: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature: Option<session::ChronicleSignature<S>>,
pub started_at: Datetime,
#[serde(skip_serializing_if = "Option::is_none")]
pub time_modes: Option<Vec<S>>,
pub total_witnessed: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub witnessed: Option<session::WitnessedTally<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 SessionGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Session<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct WitnessedTally<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub anomalies: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub auroras: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bats: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub birds: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bugs: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub comets: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub critters: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub glints: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub jet_trails: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub meteor_showers: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub meteor_storms: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub moonrises: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub owls: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub planes: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rains: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub satellites: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub shooting_stars: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ufos: Option<i64>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Session<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, SessionRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for ChronicleSignature<S> {
fn nsid() -> &'static str {
"net.anisota.lab.nightsky.session"
}
fn def_name() -> &'static str {
"chronicleSignature"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_nightsky_session()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SessionRecord;
impl XrpcResp for SessionRecord {
const NSID: &'static str = "net.anisota.lab.nightsky.session";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = SessionGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<SessionGetRecordOutput<S>> for Session<S> {
fn from(output: SessionGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Session<S> {
const NSID: &'static str = "net.anisota.lab.nightsky.session";
type Record = SessionRecord;
}
impl Collection for SessionRecord {
const NSID: &'static str = "net.anisota.lab.nightsky.session";
type Record = SessionRecord;
}
impl<S: BosStr> LexiconSchema for Session<S> {
fn nsid() -> &'static str {
"net.anisota.lab.nightsky.session"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_nightsky_session()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.duration_ms;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("duration_ms"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.time_modes {
#[allow(unused_comparisons)]
if value.len() > 8usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("time_modes"),
max: 8usize,
actual: value.len(),
});
}
}
{
let value = &self.total_witnessed;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("total_witnessed"),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
impl<S: BosStr> LexiconSchema for WitnessedTally<S> {
fn nsid() -> &'static str {
"net.anisota.lab.nightsky.session"
}
fn def_name() -> &'static str {
"witnessedTally"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_lab_nightsky_session()
}
fn validate(&self) -> Result<(), ConstraintError> {
if let Some(ref value) = self.anomalies {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("anomalies"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.auroras {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("auroras"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.bats {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("bats"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.birds {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("birds"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.bugs {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("bugs"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.comets {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("comets"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.critters {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("critters"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.glints {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("glints"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.jet_trails {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("jet_trails"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.meteor_showers {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("meteor_showers"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.meteor_storms {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("meteor_storms"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.moonrises {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("moonrises"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.owls {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("owls"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.planes {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("planes"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.rains {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("rains"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.satellites {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("satellites"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.shooting_stars {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("shooting_stars"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.ufos {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("ufos"),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
pub mod chronicle_signature_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Alg;
type Kid;
type Nonce;
type Sig;
type SignedAt;
type Version;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Alg = Unset;
type Kid = Unset;
type Nonce = Unset;
type Sig = Unset;
type SignedAt = Unset;
type Version = Unset;
}
pub struct SetAlg<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAlg<St> {}
impl<St: State> State for SetAlg<St> {
type Alg = Set<members::alg>;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetKid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetKid<St> {}
impl<St: State> State for SetKid<St> {
type Alg = St::Alg;
type Kid = Set<members::kid>;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetNonce<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetNonce<St> {}
impl<St: State> State for SetNonce<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = Set<members::nonce>;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetSig<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSig<St> {}
impl<St: State> State for SetSig<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = Set<members::sig>;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetSignedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSignedAt<St> {}
impl<St: State> State for SetSignedAt<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = Set<members::signed_at>;
type Version = St::Version;
}
pub struct SetVersion<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetVersion<St> {}
impl<St: State> State for SetVersion<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = Set<members::version>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct alg(());
pub struct kid(());
pub struct nonce(());
pub struct sig(());
pub struct signed_at(());
pub struct version(());
}
}
pub struct ChronicleSignatureBuilder<St: chronicle_signature_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<Datetime>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl ChronicleSignature<DefaultStr> {
pub fn new() -> ChronicleSignatureBuilder<chronicle_signature_state::Empty, DefaultStr> {
ChronicleSignatureBuilder::new()
}
}
impl<S: BosStr> ChronicleSignature<S> {
pub fn builder() -> ChronicleSignatureBuilder<chronicle_signature_state::Empty, S> {
ChronicleSignatureBuilder::builder()
}
}
impl ChronicleSignatureBuilder<chronicle_signature_state::Empty, DefaultStr> {
pub fn new() -> Self {
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> ChronicleSignatureBuilder<chronicle_signature_state::Empty, S> {
pub fn builder() -> Self {
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Alg: chronicle_signature_state::IsUnset,
{
pub fn alg(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetAlg<St>, S> {
self._fields.0 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Kid: chronicle_signature_state::IsUnset,
{
pub fn kid(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetKid<St>, S> {
self._fields.1 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Nonce: chronicle_signature_state::IsUnset,
{
pub fn nonce(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetNonce<St>, S> {
self._fields.2 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Sig: chronicle_signature_state::IsUnset,
{
pub fn sig(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetSig<St>, S> {
self._fields.3 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::SignedAt: chronicle_signature_state::IsUnset,
{
pub fn signed_at(
mut self,
value: impl Into<Datetime>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetSignedAt<St>, S> {
self._fields.4 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Version: chronicle_signature_state::IsUnset,
{
pub fn version(
mut self,
value: impl Into<i64>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetVersion<St>, S> {
self._fields.5 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Alg: chronicle_signature_state::IsSet,
St::Kid: chronicle_signature_state::IsSet,
St::Nonce: chronicle_signature_state::IsSet,
St::Sig: chronicle_signature_state::IsSet,
St::SignedAt: chronicle_signature_state::IsSet,
St::Version: chronicle_signature_state::IsSet,
{
pub fn build(self) -> ChronicleSignature<S> {
ChronicleSignature {
alg: self._fields.0.unwrap(),
kid: self._fields.1.unwrap(),
nonce: self._fields.2.unwrap(),
sig: self._fields.3.unwrap(),
signed_at: self._fields.4.unwrap(),
version: self._fields.5.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ChronicleSignature<S> {
ChronicleSignature {
alg: self._fields.0.unwrap(),
kid: self._fields.1.unwrap(),
nonce: self._fields.2.unwrap(),
sig: self._fields.3.unwrap(),
signed_at: self._fields.4.unwrap(),
version: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_lab_nightsky_session() -> LexiconDoc<'static> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
LexiconDoc {
lexicon: Lexicon::Lexicon1,
id: CowStr::new_static("net.anisota.lab.nightsky.session"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("chronicleSignature"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static(
"ES256 cryptographic signature proving record authenticity",
)),
required: Some(vec![
SmolStr::new_static("sig"),
SmolStr::new_static("alg"),
SmolStr::new_static("kid"),
SmolStr::new_static("signedAt"),
SmolStr::new_static("nonce"),
SmolStr::new_static("version"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("alg"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Signing algorithm (ES256)")),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("kid"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Key identifier for the signing key",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("nonce"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Unique random nonce to prevent replay",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sig"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Base64-encoded ES256 signature",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signedAt"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("When the record was signed")),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("version"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A record of one sky-gazing session in the Anisota Lab's Nightsky experiment, saved to the gazer's PDS. Captures how long they watched, how they were watching, and a tally of everything their viewfinder witnessed. Like Chronicle records, each session carries an ES256 signature minted by the Anisota backend, so the data can be verified to have come from the app rather than being hand-written.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("startedAt"),
SmolStr::new_static("endedAt"),
SmolStr::new_static("durationMs"),
SmolStr::new_static("totalWitnessed"),
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("When the session record was created"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("durationMs"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("endedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the gazing session ended"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("lookAround"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signature"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#chronicleSignature"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("startedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the gazing session began"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("timeModes"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Which time-of-day modes were viewed during the session",
),
),
items: LexArrayItem::String(LexString {
..Default::default()
}),
max_length: Some(8usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("totalWitnessed"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("witnessed"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#witnessedTally"),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("witnessedTally"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Per-kind counts of celestial and daytime sights witnessed in the viewfinder",
),
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("anomalies"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("auroras"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("bats"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("birds"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("bugs"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("comets"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("critters"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("glints"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("jetTrails"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("meteorShowers"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("meteorStorms"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("moonrises"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("owls"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("planes"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rains"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("satellites"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("shootingStars"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("ufos"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod session_state {
pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type CreatedAt;
type DurationMs;
type EndedAt;
type StartedAt;
type TotalWitnessed;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type DurationMs = Unset;
type EndedAt = Unset;
type StartedAt = Unset;
type TotalWitnessed = Unset;
}
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 DurationMs = St::DurationMs;
type EndedAt = St::EndedAt;
type StartedAt = St::StartedAt;
type TotalWitnessed = St::TotalWitnessed;
}
pub struct SetDurationMs<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDurationMs<St> {}
impl<St: State> State for SetDurationMs<St> {
type CreatedAt = St::CreatedAt;
type DurationMs = Set<members::duration_ms>;
type EndedAt = St::EndedAt;
type StartedAt = St::StartedAt;
type TotalWitnessed = St::TotalWitnessed;
}
pub struct SetEndedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetEndedAt<St> {}
impl<St: State> State for SetEndedAt<St> {
type CreatedAt = St::CreatedAt;
type DurationMs = St::DurationMs;
type EndedAt = Set<members::ended_at>;
type StartedAt = St::StartedAt;
type TotalWitnessed = St::TotalWitnessed;
}
pub struct SetStartedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetStartedAt<St> {}
impl<St: State> State for SetStartedAt<St> {
type CreatedAt = St::CreatedAt;
type DurationMs = St::DurationMs;
type EndedAt = St::EndedAt;
type StartedAt = Set<members::started_at>;
type TotalWitnessed = St::TotalWitnessed;
}
pub struct SetTotalWitnessed<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTotalWitnessed<St> {}
impl<St: State> State for SetTotalWitnessed<St> {
type CreatedAt = St::CreatedAt;
type DurationMs = St::DurationMs;
type EndedAt = St::EndedAt;
type StartedAt = St::StartedAt;
type TotalWitnessed = Set<members::total_witnessed>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct duration_ms(());
pub struct ended_at(());
pub struct started_at(());
pub struct total_witnessed(());
}
}
pub struct SessionBuilder<St: session_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<i64>,
Option<Datetime>,
Option<bool>,
Option<session::ChronicleSignature<S>>,
Option<Datetime>,
Option<Vec<S>>,
Option<i64>,
Option<session::WitnessedTally<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl Session<DefaultStr> {
pub fn new() -> SessionBuilder<session_state::Empty, DefaultStr> {
SessionBuilder::new()
}
}
impl<S: BosStr> Session<S> {
pub fn builder() -> SessionBuilder<session_state::Empty, S> {
SessionBuilder::builder()
}
}
impl SessionBuilder<session_state::Empty, DefaultStr> {
pub fn new() -> Self {
SessionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> SessionBuilder<session_state::Empty, S> {
pub fn builder() -> Self {
SessionBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> SessionBuilder<St, S>
where
St: session_state::State,
St::CreatedAt: session_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> SessionBuilder<session_state::SetCreatedAt<St>, S> {
self._fields.0 = Option::Some(value.into());
SessionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> SessionBuilder<St, S>
where
St: session_state::State,
St::DurationMs: session_state::IsUnset,
{
pub fn duration_ms(
mut self,
value: impl Into<i64>,
) -> SessionBuilder<session_state::SetDurationMs<St>, S> {
self._fields.1 = Option::Some(value.into());
SessionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> SessionBuilder<St, S>
where
St: session_state::State,
St::EndedAt: session_state::IsUnset,
{
pub fn ended_at(
mut self,
value: impl Into<Datetime>,
) -> SessionBuilder<session_state::SetEndedAt<St>, S> {
self._fields.2 = Option::Some(value.into());
SessionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
pub fn look_around(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_look_around(mut self, value: Option<bool>) -> Self {
self._fields.3 = value;
self
}
}
impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
pub fn signature(mut self, value: impl Into<Option<session::ChronicleSignature<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_signature(mut self, value: Option<session::ChronicleSignature<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<St, S: BosStr> SessionBuilder<St, S>
where
St: session_state::State,
St::StartedAt: session_state::IsUnset,
{
pub fn started_at(
mut self,
value: impl Into<Datetime>,
) -> SessionBuilder<session_state::SetStartedAt<St>, S> {
self._fields.5 = Option::Some(value.into());
SessionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
pub fn time_modes(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_time_modes(mut self, value: Option<Vec<S>>) -> Self {
self._fields.6 = value;
self
}
}
impl<St, S: BosStr> SessionBuilder<St, S>
where
St: session_state::State,
St::TotalWitnessed: session_state::IsUnset,
{
pub fn total_witnessed(
mut self,
value: impl Into<i64>,
) -> SessionBuilder<session_state::SetTotalWitnessed<St>, S> {
self._fields.7 = Option::Some(value.into());
SessionBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: session_state::State, S: BosStr> SessionBuilder<St, S> {
pub fn witnessed(mut self, value: impl Into<Option<session::WitnessedTally<S>>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_witnessed(mut self, value: Option<session::WitnessedTally<S>>) -> Self {
self._fields.8 = value;
self
}
}
impl<St, S: BosStr> SessionBuilder<St, S>
where
St: session_state::State,
St::CreatedAt: session_state::IsSet,
St::DurationMs: session_state::IsSet,
St::EndedAt: session_state::IsSet,
St::StartedAt: session_state::IsSet,
St::TotalWitnessed: session_state::IsSet,
{
pub fn build(self) -> Session<S> {
Session {
created_at: self._fields.0.unwrap(),
duration_ms: self._fields.1.unwrap(),
ended_at: self._fields.2.unwrap(),
look_around: self._fields.3,
signature: self._fields.4,
started_at: self._fields.5.unwrap(),
time_modes: self._fields.6,
total_witnessed: self._fields.7.unwrap(),
witnessed: self._fields.8,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Session<S> {
Session {
created_at: self._fields.0.unwrap(),
duration_ms: self._fields.1.unwrap(),
ended_at: self._fields.2.unwrap(),
look_around: self._fields.3,
signature: self._fields.4,
started_at: self._fields.5.unwrap(),
time_modes: self._fields.6,
total_witnessed: self._fields.7.unwrap(),
witnessed: self._fields.8,
extra_data: Some(extra_data),
}
}
}