#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::bytes::Bytes;
#[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::{Did, 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::com_atproto::repo::strong_ref::StrongRef;
use crate::community_lexicon::location::hthree::Hthree;
use crate::org_passingreads::book::event;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "org.passingreads.book.event",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Event<S: BosStr = DefaultStr> {
pub book: StrongRef<S>,
#[serde(with = "jacquard_common::serde_bytes_helper")]
pub book_pub: Bytes,
#[serde(with = "jacquard_common::serde_bytes_helper")]
pub book_sig: Bytes,
pub did: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub event: Option<EventEvent<S>>,
pub location: EventLocation<S>,
pub occurred_at: 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 EventEvent<S: BosStr = DefaultStr> {
OrgPassingreadsBookCheckin,
OrgPassingreadsBookDrop,
OrgPassingreadsBookFind,
Other(S),
}
impl<S: BosStr> EventEvent<S> {
pub fn as_str(&self) -> &str {
match self {
Self::OrgPassingreadsBookCheckin => "org.passingreads.book.checkin",
Self::OrgPassingreadsBookDrop => "org.passingreads.book.drop",
Self::OrgPassingreadsBookFind => "org.passingreads.book.find",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"org.passingreads.book.checkin" => Self::OrgPassingreadsBookCheckin,
"org.passingreads.book.drop" => Self::OrgPassingreadsBookDrop,
"org.passingreads.book.find" => Self::OrgPassingreadsBookFind,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for EventEvent<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for EventEvent<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for EventEvent<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 EventEvent<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 EventEvent<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for EventEvent<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = EventEvent<S::Output>;
fn into_static(self) -> Self::Output {
match self {
EventEvent::OrgPassingreadsBookCheckin => {
EventEvent::OrgPassingreadsBookCheckin
}
EventEvent::OrgPassingreadsBookDrop => EventEvent::OrgPassingreadsBookDrop,
EventEvent::OrgPassingreadsBookFind => EventEvent::OrgPassingreadsBookFind,
EventEvent::Other(v) => EventEvent::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 EventLocation<S: BosStr = DefaultStr> {
#[serde(rename = "com.atproto.repo.strongRef#main")]
StrongRef(Box<StrongRef<S>>),
#[serde(rename = "community.lexicon.location.hthree#main")]
Hthree(Box<Hthree<S>>),
#[serde(rename = "org.passingreads.book.event#osmLocation")]
OsmLocation(Box<event::OsmLocation<S>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EventGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Event<S>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct OsmLocation<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub category: Option<S>,
pub name: S,
pub osm_id: S,
pub value: S,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
impl<S: BosStr> Event<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, EventRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EventRecord;
impl XrpcResp for EventRecord {
const NSID: &'static str = "org.passingreads.book.event";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = EventGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<EventGetRecordOutput<S>> for Event<S> {
fn from(output: EventGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Event<S> {
const NSID: &'static str = "org.passingreads.book.event";
type Record = EventRecord;
}
impl Collection for EventRecord {
const NSID: &'static str = "org.passingreads.book.event";
type Record = EventRecord;
}
impl<S: BosStr> LexiconSchema for Event<S> {
fn nsid() -> &'static str {
"org.passingreads.book.event"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_passingreads_book_event()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
impl<S: BosStr> LexiconSchema for OsmLocation<S> {
fn nsid() -> &'static str {
"org.passingreads.book.event"
}
fn def_name() -> &'static str {
"osmLocation"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_org_passingreads_book_event()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod event_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 BookPub;
type Book;
type Location;
type OccurredAt;
type Did;
type BookSig;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type BookPub = Unset;
type Book = Unset;
type Location = Unset;
type OccurredAt = Unset;
type Did = Unset;
type BookSig = Unset;
}
pub struct SetBookPub<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBookPub<St> {}
impl<St: State> State for SetBookPub<St> {
type BookPub = Set<members::book_pub>;
type Book = St::Book;
type Location = St::Location;
type OccurredAt = St::OccurredAt;
type Did = St::Did;
type BookSig = St::BookSig;
}
pub struct SetBook<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBook<St> {}
impl<St: State> State for SetBook<St> {
type BookPub = St::BookPub;
type Book = Set<members::book>;
type Location = St::Location;
type OccurredAt = St::OccurredAt;
type Did = St::Did;
type BookSig = St::BookSig;
}
pub struct SetLocation<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLocation<St> {}
impl<St: State> State for SetLocation<St> {
type BookPub = St::BookPub;
type Book = St::Book;
type Location = Set<members::location>;
type OccurredAt = St::OccurredAt;
type Did = St::Did;
type BookSig = St::BookSig;
}
pub struct SetOccurredAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetOccurredAt<St> {}
impl<St: State> State for SetOccurredAt<St> {
type BookPub = St::BookPub;
type Book = St::Book;
type Location = St::Location;
type OccurredAt = Set<members::occurred_at>;
type Did = St::Did;
type BookSig = St::BookSig;
}
pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetDid<St> {}
impl<St: State> State for SetDid<St> {
type BookPub = St::BookPub;
type Book = St::Book;
type Location = St::Location;
type OccurredAt = St::OccurredAt;
type Did = Set<members::did>;
type BookSig = St::BookSig;
}
pub struct SetBookSig<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBookSig<St> {}
impl<St: State> State for SetBookSig<St> {
type BookPub = St::BookPub;
type Book = St::Book;
type Location = St::Location;
type OccurredAt = St::OccurredAt;
type Did = St::Did;
type BookSig = Set<members::book_sig>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct book_pub(());
pub struct book(());
pub struct location(());
pub struct occurred_at(());
pub struct did(());
pub struct book_sig(());
}
}
pub struct EventBuilder<S: BosStr, St: event_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<StrongRef<S>>,
Option<Bytes>,
Option<Bytes>,
Option<Did<S>>,
Option<EventEvent<S>>,
Option<EventLocation<S>>,
Option<Datetime>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Event<S> {
pub fn new() -> EventBuilder<S, event_state::Empty> {
EventBuilder::new()
}
}
impl<S: BosStr> EventBuilder<S, event_state::Empty> {
pub fn new() -> Self {
EventBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Book: event_state::IsUnset,
{
pub fn book(
mut self,
value: impl Into<StrongRef<S>>,
) -> EventBuilder<S, event_state::SetBook<St>> {
self._fields.0 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::BookPub: event_state::IsUnset,
{
pub fn book_pub(
mut self,
value: impl Into<Bytes>,
) -> EventBuilder<S, event_state::SetBookPub<St>> {
self._fields.1 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::BookSig: event_state::IsUnset,
{
pub fn book_sig(
mut self,
value: impl Into<Bytes>,
) -> EventBuilder<S, event_state::SetBookSig<St>> {
self._fields.2 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Did: event_state::IsUnset,
{
pub fn did(
mut self,
value: impl Into<Did<S>>,
) -> EventBuilder<S, event_state::SetDid<St>> {
self._fields.3 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: event_state::State> EventBuilder<S, St> {
pub fn event(mut self, value: impl Into<Option<EventEvent<S>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_event(mut self, value: Option<EventEvent<S>>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::Location: event_state::IsUnset,
{
pub fn location(
mut self,
value: impl Into<EventLocation<S>>,
) -> EventBuilder<S, event_state::SetLocation<St>> {
self._fields.5 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::OccurredAt: event_state::IsUnset,
{
pub fn occurred_at(
mut self,
value: impl Into<Datetime>,
) -> EventBuilder<S, event_state::SetOccurredAt<St>> {
self._fields.6 = Option::Some(value.into());
EventBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> EventBuilder<S, St>
where
St: event_state::State,
St::BookPub: event_state::IsSet,
St::Book: event_state::IsSet,
St::Location: event_state::IsSet,
St::OccurredAt: event_state::IsSet,
St::Did: event_state::IsSet,
St::BookSig: event_state::IsSet,
{
pub fn build(self) -> Event<S> {
Event {
book: self._fields.0.unwrap(),
book_pub: self._fields.1.unwrap(),
book_sig: self._fields.2.unwrap(),
did: self._fields.3.unwrap(),
event: self._fields.4,
location: self._fields.5.unwrap(),
occurred_at: self._fields.6.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Event<S> {
Event {
book: self._fields.0.unwrap(),
book_pub: self._fields.1.unwrap(),
book_sig: self._fields.2.unwrap(),
did: self._fields.3.unwrap(),
event: self._fields.4,
location: self._fields.5.unwrap(),
occurred_at: self._fields.6.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_org_passingreads_book_event() -> 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("org.passingreads.book.event"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static("The status of a book has changed."),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("did"), SmolStr::new_static("book"),
SmolStr::new_static("occurredAt"),
SmolStr::new_static("location"),
SmolStr::new_static("bookPub"),
SmolStr::new_static("bookSig")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("book"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static(
"com.atproto.repo.strongRef#main",
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("bookPub"),
LexObjectProperty::Bytes(LexBytes { ..Default::default() }),
);
map.insert(
SmolStr::new_static("bookSig"),
LexObjectProperty::Bytes(LexBytes { ..Default::default() }),
);
map.insert(
SmolStr::new_static("did"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The DID of the person who registered the book. Included here, so it's verifiable with the bookSig.",
),
),
format: Some(LexStringFormat::Did),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("event"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("What event has occurred"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("location"),
LexObjectProperty::Union(LexRefUnion {
description: Some(
CowStr::new_static(
"Where this event occurred (an h3 cell, an OSM place, or a link to an outpost — org.passingreads.outpost.registration)",
),
),
refs: vec![
CowStr::new_static("com.atproto.repo.strongRef#main"),
CowStr::new_static("community.lexicon.location.hthree#main"),
CowStr::new_static("#osmLocation")
],
..Default::default()
}),
);
map.insert(
SmolStr::new_static("occurredAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Client-declared timestamp of when the book was dropped",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("osmLocation"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static("A physical location from OpenStreetMap."),
),
required: Some(
vec![
SmolStr::new_static("osmId"), SmolStr::new_static("name"),
SmolStr::new_static("value")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("category"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The type of place (e.g., cafe, library, park).",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("name"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The name of the place from OpenStreetMap.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("osmId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The OpenStreetMap element ID in interoperable format: N (node), W (way), or R (relation) prefix followed by numeric ID. Example: N123456789",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("value"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The H3 cell index for proximity queries.",
),
),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}