// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.passingreads.book.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

//! Generated bindings for the `org.passingreads.book` Lexicon namespace/module.
pub mod checkin;
pub mod drop;
pub mod event;
pub mod find;
pub mod get_book;
pub mod get_books;
pub mod get_library;
pub mod get_location_books;
pub mod list_book_ids;
pub mod list_dropped_books;
pub mod registration;


#[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::string::{Did, AtUri, Datetime, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::community_lexicon::location::hthree::Hthree;
use crate::org_passingreads::Actor;
use crate::org_passingreads::AspectRatio;
use crate::org_passingreads::book;
/// A confirmed book event for display purposes. Omits cryptographic fields (bookPub, bookSig) and book reference since it's shown in context of a book.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ConfirmedEvent<S: BosStr = DefaultStr> {
    ///The person who performed this event
    pub actor: Actor<S>,
    ///What event occurred
    pub event: ConfirmedEventEvent<S>,
    ///Where this event occurred
    pub location: Hthree<S>,
    ///When this event occurred
    pub occurred_at: Datetime,
    ///The AT URI of this event record
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// What event occurred

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConfirmedEventEvent<S: BosStr = DefaultStr> {
    OrgPassingreadsBookCheckin,
    OrgPassingreadsBookDrop,
    OrgPassingreadsBookFind,
    Other(S),
}

impl<S: BosStr> ConfirmedEventEvent<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(),
        }
    }
    /// Construct from a string-like value, matching known values.
    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 ConfirmedEventEvent<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for ConfirmedEventEvent<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for ConfirmedEventEvent<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 ConfirmedEventEvent<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 ConfirmedEventEvent<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ConfirmedEventEvent<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ConfirmedEventEvent<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ConfirmedEventEvent::OrgPassingreadsBookCheckin => {
                ConfirmedEventEvent::OrgPassingreadsBookCheckin
            }
            ConfirmedEventEvent::OrgPassingreadsBookDrop => {
                ConfirmedEventEvent::OrgPassingreadsBookDrop
            }
            ConfirmedEventEvent::OrgPassingreadsBookFind => {
                ConfirmedEventEvent::OrgPassingreadsBookFind
            }
            ConfirmedEventEvent::Other(v) => ConfirmedEventEvent::Other(v.into_static()),
        }
    }
}

/// A view of a book registration for API responses. Omits cryptographic fields (bookPub, bookSig) and the cover blob.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RegistrationView<S: BosStr = DefaultStr> {
    ///Authors of this book, in order of credit
    pub authors: Vec<S>,
    ///The book's ID (as defined on its QR Code)
    pub book_id: S,
    ///When the book was registered
    pub occurred_at: Datetime,
    ///The book's Open Library Edition ID
    #[serde(skip_serializing_if = "Option::is_none")]
    pub publication_id: Option<S>,
    ///The person who registered the book
    pub registered_by: Actor<S>,
    ///The title of the book
    pub title: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A book with its current state, combining registration data with computed state information.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct StatefulBook<S: BosStr = DefaultStr> {
    ///Aspect ratio of the cover image
    #[serde(skip_serializing_if = "Option::is_none")]
    pub aspect_ratio: Option<AspectRatio<S>>,
    ///The CID of the book registration record
    pub cid: S,
    ///Resolved URL to the cover image (from the registration blob)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cover_url: Option<UriValue<S>>,
    ///The DID of the current holder of the book
    pub current_holder: Did<S>,
    ///The current location of the book (only present if state is 'org.passingreads.book.drop')
    #[serde(skip_serializing_if = "Option::is_none")]
    pub current_location: Option<Hthree<S>>,
    ///List of confirmed events for this book, in chronological order
    #[serde(skip_serializing_if = "Option::is_none")]
    pub events: Option<Vec<book::ConfirmedEvent<S>>>,
    ///The book registration data (without cryptographic fields)
    pub registration: book::RegistrationView<S>,
    ///The current state of the book, derived from the latest event
    pub state: StatefulBookState<S>,
    ///The AT URI of the book registration record
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// The current state of the book, derived from the latest event

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum StatefulBookState<S: BosStr = DefaultStr> {
    OrgPassingreadsBookCheckin,
    OrgPassingreadsBookDrop,
    OrgPassingreadsBookFind,
    OrgPassingreadsBookRegistration,
    Other(S),
}

impl<S: BosStr> StatefulBookState<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::OrgPassingreadsBookRegistration => "org.passingreads.book.registration",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    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,
            "org.passingreads.book.registration" => Self::OrgPassingreadsBookRegistration,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for StatefulBookState<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for StatefulBookState<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for StatefulBookState<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 StatefulBookState<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 StatefulBookState<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for StatefulBookState<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = StatefulBookState<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            StatefulBookState::OrgPassingreadsBookCheckin => {
                StatefulBookState::OrgPassingreadsBookCheckin
            }
            StatefulBookState::OrgPassingreadsBookDrop => {
                StatefulBookState::OrgPassingreadsBookDrop
            }
            StatefulBookState::OrgPassingreadsBookFind => {
                StatefulBookState::OrgPassingreadsBookFind
            }
            StatefulBookState::OrgPassingreadsBookRegistration => {
                StatefulBookState::OrgPassingreadsBookRegistration
            }
            StatefulBookState::Other(v) => StatefulBookState::Other(v.into_static()),
        }
    }
}

impl<S: BosStr> LexiconSchema for ConfirmedEvent<S> {
    fn nsid() -> &'static str {
        "org.passingreads.book.defs"
    }
    fn def_name() -> &'static str {
        "confirmedEvent"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_passingreads_book_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for RegistrationView<S> {
    fn nsid() -> &'static str {
        "org.passingreads.book.defs"
    }
    fn def_name() -> &'static str {
        "registrationView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_passingreads_book_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for StatefulBook<S> {
    fn nsid() -> &'static str {
        "org.passingreads.book.defs"
    }
    fn def_name() -> &'static str {
        "statefulBook"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_passingreads_book_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod confirmed_event_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 Actor;
        type Event;
        type Location;
        type OccurredAt;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Actor = Unset;
        type Event = Unset;
        type Location = Unset;
        type OccurredAt = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `actor` field to Set
    pub struct SetActor<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetActor<St> {}
    impl<St: State> State for SetActor<St> {
        type Actor = Set<members::actor>;
        type Event = St::Event;
        type Location = St::Location;
        type OccurredAt = St::OccurredAt;
        type Uri = St::Uri;
    }
    ///State transition - sets the `event` field to Set
    pub struct SetEvent<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEvent<St> {}
    impl<St: State> State for SetEvent<St> {
        type Actor = St::Actor;
        type Event = Set<members::event>;
        type Location = St::Location;
        type OccurredAt = St::OccurredAt;
        type Uri = St::Uri;
    }
    ///State transition - sets the `location` field to Set
    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 Actor = St::Actor;
        type Event = St::Event;
        type Location = Set<members::location>;
        type OccurredAt = St::OccurredAt;
        type Uri = St::Uri;
    }
    ///State transition - sets the `occurred_at` field to Set
    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 Actor = St::Actor;
        type Event = St::Event;
        type Location = St::Location;
        type OccurredAt = Set<members::occurred_at>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Actor = St::Actor;
        type Event = St::Event;
        type Location = St::Location;
        type OccurredAt = St::OccurredAt;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `actor` field
        pub struct actor(());
        ///Marker type for the `event` field
        pub struct event(());
        ///Marker type for the `location` field
        pub struct location(());
        ///Marker type for the `occurred_at` field
        pub struct occurred_at(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ConfirmedEventBuilder<
    St: confirmed_event_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Actor<S>>,
        Option<ConfirmedEventEvent<S>>,
        Option<Hthree<S>>,
        Option<Datetime>,
        Option<AtUri<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> ConfirmedEvent<S> {
    /// Create a new builder for this type
    pub fn builder() -> ConfirmedEventBuilder<confirmed_event_state::Empty, S> {
        ConfirmedEventBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ConfirmedEventBuilder<St, S>
where
    St: confirmed_event_state::State,
    St::Actor: confirmed_event_state::IsUnset,
{
    /// Set the `actor` field (required)
    pub fn actor(
        mut self,
        value: impl Into<Actor<S>>,
    ) -> ConfirmedEventBuilder<confirmed_event_state::SetActor<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ConfirmedEventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ConfirmedEventBuilder<St, S>
where
    St: confirmed_event_state::State,
    St::Event: confirmed_event_state::IsUnset,
{
    /// Set the `event` field (required)
    pub fn event(
        mut self,
        value: impl Into<ConfirmedEventEvent<S>>,
    ) -> ConfirmedEventBuilder<confirmed_event_state::SetEvent<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ConfirmedEventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ConfirmedEventBuilder<St, S>
where
    St: confirmed_event_state::State,
    St::Location: confirmed_event_state::IsUnset,
{
    /// Set the `location` field (required)
    pub fn location(
        mut self,
        value: impl Into<Hthree<S>>,
    ) -> ConfirmedEventBuilder<confirmed_event_state::SetLocation<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ConfirmedEventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ConfirmedEventBuilder<St, S>
where
    St: confirmed_event_state::State,
    St::OccurredAt: confirmed_event_state::IsUnset,
{
    /// Set the `occurredAt` field (required)
    pub fn occurred_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> ConfirmedEventBuilder<confirmed_event_state::SetOccurredAt<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ConfirmedEventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ConfirmedEventBuilder<St, S>
where
    St: confirmed_event_state::State,
    St::Uri: confirmed_event_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ConfirmedEventBuilder<confirmed_event_state::SetUri<St>, S> {
        self._fields.4 = Option::Some(value.into());
        ConfirmedEventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ConfirmedEventBuilder<St, S>
where
    St: confirmed_event_state::State,
    St::Actor: confirmed_event_state::IsSet,
    St::Event: confirmed_event_state::IsSet,
    St::Location: confirmed_event_state::IsSet,
    St::OccurredAt: confirmed_event_state::IsSet,
    St::Uri: confirmed_event_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ConfirmedEvent<S> {
        ConfirmedEvent {
            actor: self._fields.0.unwrap(),
            event: self._fields.1.unwrap(),
            location: self._fields.2.unwrap(),
            occurred_at: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ConfirmedEvent<S> {
        ConfirmedEvent {
            actor: self._fields.0.unwrap(),
            event: self._fields.1.unwrap(),
            location: self._fields.2.unwrap(),
            occurred_at: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_passingreads_book_defs() -> 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.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("confirmedEvent"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A confirmed book event for display purposes. Omits cryptographic fields (bookPub, bookSig) and book reference since it's shown in context of a book.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("actor"),
                            SmolStr::new_static("event"),
                            SmolStr::new_static("location"),
                            SmolStr::new_static("occurredAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("actor"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("org.passingreads.defs#actor"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("event"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("What event occurred"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("location"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "community.lexicon.location.hthree#main",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("occurredAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When this event occurred"),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The AT URI of this event record"),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("registrationView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A view of a book registration for API responses. Omits cryptographic fields (bookPub, bookSig) and the cover blob.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("registeredBy"),
                            SmolStr::new_static("bookId"), SmolStr::new_static("title"),
                            SmolStr::new_static("authors"),
                            SmolStr::new_static("occurredAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("authors"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Authors of this book, in order of credit",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("bookId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The book's ID (as defined on its QR Code)",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("occurredAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When the book was registered"),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("publicationId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The book's Open Library Edition ID"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("registeredBy"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("org.passingreads.defs#actor"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The title of the book"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("statefulBook"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A book with its current state, combining registration data with computed state information.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("registration"),
                            SmolStr::new_static("state"),
                            SmolStr::new_static("currentHolder")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "org.passingreads.defs#aspectRatio",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The CID of the book registration record",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("coverUrl"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Resolved URL to the cover image (from the registration blob)",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("currentHolder"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The DID of the current holder of the book",
                                    ),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("currentLocation"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "community.lexicon.location.hthree#main",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("events"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "List of confirmed events for this book, in chronological order",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#confirmedEvent"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("registration"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#registrationView"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("state"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The current state of the book, derived from the latest event",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The AT URI of the book registration record",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod registration_view_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 Authors;
        type BookId;
        type OccurredAt;
        type RegisteredBy;
        type Title;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Authors = Unset;
        type BookId = Unset;
        type OccurredAt = Unset;
        type RegisteredBy = Unset;
        type Title = Unset;
    }
    ///State transition - sets the `authors` field to Set
    pub struct SetAuthors<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAuthors<St> {}
    impl<St: State> State for SetAuthors<St> {
        type Authors = Set<members::authors>;
        type BookId = St::BookId;
        type OccurredAt = St::OccurredAt;
        type RegisteredBy = St::RegisteredBy;
        type Title = St::Title;
    }
    ///State transition - sets the `book_id` field to Set
    pub struct SetBookId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBookId<St> {}
    impl<St: State> State for SetBookId<St> {
        type Authors = St::Authors;
        type BookId = Set<members::book_id>;
        type OccurredAt = St::OccurredAt;
        type RegisteredBy = St::RegisteredBy;
        type Title = St::Title;
    }
    ///State transition - sets the `occurred_at` field to Set
    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 Authors = St::Authors;
        type BookId = St::BookId;
        type OccurredAt = Set<members::occurred_at>;
        type RegisteredBy = St::RegisteredBy;
        type Title = St::Title;
    }
    ///State transition - sets the `registered_by` field to Set
    pub struct SetRegisteredBy<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRegisteredBy<St> {}
    impl<St: State> State for SetRegisteredBy<St> {
        type Authors = St::Authors;
        type BookId = St::BookId;
        type OccurredAt = St::OccurredAt;
        type RegisteredBy = Set<members::registered_by>;
        type Title = St::Title;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type Authors = St::Authors;
        type BookId = St::BookId;
        type OccurredAt = St::OccurredAt;
        type RegisteredBy = St::RegisteredBy;
        type Title = Set<members::title>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `authors` field
        pub struct authors(());
        ///Marker type for the `book_id` field
        pub struct book_id(());
        ///Marker type for the `occurred_at` field
        pub struct occurred_at(());
        ///Marker type for the `registered_by` field
        pub struct registered_by(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

/// Builder for constructing an instance of this type.
pub struct RegistrationViewBuilder<
    St: registration_view_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<S>>,
        Option<S>,
        Option<Datetime>,
        Option<S>,
        Option<Actor<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> RegistrationView<S> {
    /// Create a new builder for this type
    pub fn builder() -> RegistrationViewBuilder<registration_view_state::Empty, S> {
        RegistrationViewBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> RegistrationViewBuilder<St, S>
where
    St: registration_view_state::State,
    St::Authors: registration_view_state::IsUnset,
{
    /// Set the `authors` field (required)
    pub fn authors(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> RegistrationViewBuilder<registration_view_state::SetAuthors<St>, S> {
        self._fields.0 = Option::Some(value.into());
        RegistrationViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RegistrationViewBuilder<St, S>
where
    St: registration_view_state::State,
    St::BookId: registration_view_state::IsUnset,
{
    /// Set the `bookId` field (required)
    pub fn book_id(
        mut self,
        value: impl Into<S>,
    ) -> RegistrationViewBuilder<registration_view_state::SetBookId<St>, S> {
        self._fields.1 = Option::Some(value.into());
        RegistrationViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RegistrationViewBuilder<St, S>
where
    St: registration_view_state::State,
    St::OccurredAt: registration_view_state::IsUnset,
{
    /// Set the `occurredAt` field (required)
    pub fn occurred_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> RegistrationViewBuilder<registration_view_state::SetOccurredAt<St>, S> {
        self._fields.2 = Option::Some(value.into());
        RegistrationViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: registration_view_state::State, S: BosStr> RegistrationViewBuilder<St, S> {
    /// Set the `publicationId` field (optional)
    pub fn publication_id(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `publicationId` field to an Option value (optional)
    pub fn maybe_publication_id(mut self, value: Option<S>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> RegistrationViewBuilder<St, S>
where
    St: registration_view_state::State,
    St::RegisteredBy: registration_view_state::IsUnset,
{
    /// Set the `registeredBy` field (required)
    pub fn registered_by(
        mut self,
        value: impl Into<Actor<S>>,
    ) -> RegistrationViewBuilder<registration_view_state::SetRegisteredBy<St>, S> {
        self._fields.4 = Option::Some(value.into());
        RegistrationViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RegistrationViewBuilder<St, S>
where
    St: registration_view_state::State,
    St::Title: registration_view_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> RegistrationViewBuilder<registration_view_state::SetTitle<St>, S> {
        self._fields.5 = Option::Some(value.into());
        RegistrationViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RegistrationViewBuilder<St, S>
where
    St: registration_view_state::State,
    St::Authors: registration_view_state::IsSet,
    St::BookId: registration_view_state::IsSet,
    St::OccurredAt: registration_view_state::IsSet,
    St::RegisteredBy: registration_view_state::IsSet,
    St::Title: registration_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> RegistrationView<S> {
        RegistrationView {
            authors: self._fields.0.unwrap(),
            book_id: self._fields.1.unwrap(),
            occurred_at: self._fields.2.unwrap(),
            publication_id: self._fields.3,
            registered_by: self._fields.4.unwrap(),
            title: self._fields.5.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> RegistrationView<S> {
        RegistrationView {
            authors: self._fields.0.unwrap(),
            book_id: self._fields.1.unwrap(),
            occurred_at: self._fields.2.unwrap(),
            publication_id: self._fields.3,
            registered_by: self._fields.4.unwrap(),
            title: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod stateful_book_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 Cid;
        type CurrentHolder;
        type Registration;
        type State;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type CurrentHolder = Unset;
        type Registration = Unset;
        type State = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCid<St> {}
    impl<St: State> State for SetCid<St> {
        type Cid = Set<members::cid>;
        type CurrentHolder = St::CurrentHolder;
        type Registration = St::Registration;
        type State = St::State;
        type Uri = St::Uri;
    }
    ///State transition - sets the `current_holder` field to Set
    pub struct SetCurrentHolder<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCurrentHolder<St> {}
    impl<St: State> State for SetCurrentHolder<St> {
        type Cid = St::Cid;
        type CurrentHolder = Set<members::current_holder>;
        type Registration = St::Registration;
        type State = St::State;
        type Uri = St::Uri;
    }
    ///State transition - sets the `registration` field to Set
    pub struct SetRegistration<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRegistration<St> {}
    impl<St: State> State for SetRegistration<St> {
        type Cid = St::Cid;
        type CurrentHolder = St::CurrentHolder;
        type Registration = Set<members::registration>;
        type State = St::State;
        type Uri = St::Uri;
    }
    ///State transition - sets the `state` field to Set
    pub struct SetState<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetState<St> {}
    impl<St: State> State for SetState<St> {
        type Cid = St::Cid;
        type CurrentHolder = St::CurrentHolder;
        type Registration = St::Registration;
        type State = Set<members::state>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Cid = St::Cid;
        type CurrentHolder = St::CurrentHolder;
        type Registration = St::Registration;
        type State = St::State;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `current_holder` field
        pub struct current_holder(());
        ///Marker type for the `registration` field
        pub struct registration(());
        ///Marker type for the `state` field
        pub struct state(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type.
pub struct StatefulBookBuilder<St: stateful_book_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<AspectRatio<S>>,
        Option<S>,
        Option<UriValue<S>>,
        Option<Did<S>>,
        Option<Hthree<S>>,
        Option<Vec<book::ConfirmedEvent<S>>>,
        Option<book::RegistrationView<S>>,
        Option<StatefulBookState<S>>,
        Option<AtUri<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> StatefulBook<S> {
    /// Create a new builder for this type
    pub fn builder() -> StatefulBookBuilder<stateful_book_state::Empty, S> {
        StatefulBookBuilder::builder()
    }
}

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

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

impl<St: stateful_book_state::State, S: BosStr> StatefulBookBuilder<St, S> {
    /// Set the `aspectRatio` field (optional)
    pub fn aspect_ratio(mut self, value: impl Into<Option<AspectRatio<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `aspectRatio` field to an Option value (optional)
    pub fn maybe_aspect_ratio(mut self, value: Option<AspectRatio<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> StatefulBookBuilder<St, S>
where
    St: stateful_book_state::State,
    St::Cid: stateful_book_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<S>,
    ) -> StatefulBookBuilder<stateful_book_state::SetCid<St>, S> {
        self._fields.1 = Option::Some(value.into());
        StatefulBookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: stateful_book_state::State, S: BosStr> StatefulBookBuilder<St, S> {
    /// Set the `coverUrl` field (optional)
    pub fn cover_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `coverUrl` field to an Option value (optional)
    pub fn maybe_cover_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> StatefulBookBuilder<St, S>
where
    St: stateful_book_state::State,
    St::CurrentHolder: stateful_book_state::IsUnset,
{
    /// Set the `currentHolder` field (required)
    pub fn current_holder(
        mut self,
        value: impl Into<Did<S>>,
    ) -> StatefulBookBuilder<stateful_book_state::SetCurrentHolder<St>, S> {
        self._fields.3 = Option::Some(value.into());
        StatefulBookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: stateful_book_state::State, S: BosStr> StatefulBookBuilder<St, S> {
    /// Set the `currentLocation` field (optional)
    pub fn current_location(mut self, value: impl Into<Option<Hthree<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `currentLocation` field to an Option value (optional)
    pub fn maybe_current_location(mut self, value: Option<Hthree<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: stateful_book_state::State, S: BosStr> StatefulBookBuilder<St, S> {
    /// Set the `events` field (optional)
    pub fn events(
        mut self,
        value: impl Into<Option<Vec<book::ConfirmedEvent<S>>>>,
    ) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `events` field to an Option value (optional)
    pub fn maybe_events(mut self, value: Option<Vec<book::ConfirmedEvent<S>>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St, S: BosStr> StatefulBookBuilder<St, S>
where
    St: stateful_book_state::State,
    St::Registration: stateful_book_state::IsUnset,
{
    /// Set the `registration` field (required)
    pub fn registration(
        mut self,
        value: impl Into<book::RegistrationView<S>>,
    ) -> StatefulBookBuilder<stateful_book_state::SetRegistration<St>, S> {
        self._fields.6 = Option::Some(value.into());
        StatefulBookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> StatefulBookBuilder<St, S>
where
    St: stateful_book_state::State,
    St::State: stateful_book_state::IsUnset,
{
    /// Set the `state` field (required)
    pub fn state(
        mut self,
        value: impl Into<StatefulBookState<S>>,
    ) -> StatefulBookBuilder<stateful_book_state::SetState<St>, S> {
        self._fields.7 = Option::Some(value.into());
        StatefulBookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> StatefulBookBuilder<St, S>
where
    St: stateful_book_state::State,
    St::Cid: stateful_book_state::IsSet,
    St::CurrentHolder: stateful_book_state::IsSet,
    St::Registration: stateful_book_state::IsSet,
    St::State: stateful_book_state::IsSet,
    St::Uri: stateful_book_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> StatefulBook<S> {
        StatefulBook {
            aspect_ratio: self._fields.0,
            cid: self._fields.1.unwrap(),
            cover_url: self._fields.2,
            current_holder: self._fields.3.unwrap(),
            current_location: self._fields.4,
            events: self._fields.5,
            registration: self._fields.6.unwrap(),
            state: self._fields.7.unwrap(),
            uri: self._fields.8.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> StatefulBook<S> {
        StatefulBook {
            aspect_ratio: self._fields.0,
            cid: self._fields.1.unwrap(),
            cover_url: self._fields.2,
            current_holder: self._fields.3.unwrap(),
            current_location: self._fields.4,
            events: self._fields.5,
            registration: self._fields.6.unwrap(),
            state: self._fields.7.unwrap(),
            uri: self._fields.8.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}