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

//! Generated bindings for the `sh.weaver.notification` Lexicon namespace/module.
pub mod get_subscription_updates;
pub mod get_unread_count;
pub mod list_notifications;
pub mod update_seen;


#[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::{AtUri, Cid, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, 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::sh_weaver::actor::ProfileViewBasic;
use crate::sh_weaver::notebook::EntryView;
use crate::sh_weaver::notebook::NotebookView;
use crate::sh_weaver::notification;
/// A notification for a user.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Notification<S: BosStr = DefaultStr> {
    pub author: ProfileViewBasic<S>,
    pub cid: Cid<S>,
    pub indexed_at: Datetime,
    pub is_read: bool,
    pub reason: notification::NotificationReason<S>,
    ///The subject of the notification (entry, notebook, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reason_subject: Option<AtUri<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub record: Option<Data<S>>,
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Grouped notifications (e.g., '5 people liked your entry').

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct NotificationGroup<S: BosStr = DefaultStr> {
    ///Most recent actors (up to 5).
    pub actors: Vec<ProfileViewBasic<S>>,
    pub count: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_read: Option<bool>,
    pub most_recent_at: Datetime,
    pub reason: notification::NotificationReason<S>,
    pub subject: NotificationGroupSubject<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum NotificationGroupSubject<S: BosStr = DefaultStr> {
    #[serde(rename = "sh.weaver.notebook.defs#notebookView")]
    NotebookView(Box<NotebookView<S>>),
    #[serde(rename = "sh.weaver.notebook.defs#entryView")]
    EntryView(Box<EntryView<S>>),
}

/// Why this notification was generated.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum NotificationReason<S: BosStr = DefaultStr> {
    Like,
    Bookmark,
    Follow,
    FollowAccept,
    Subscribe,
    SubscribeAccept,
    CollaborationInvite,
    CollaborationAccept,
    NewEntry,
    EntryUpdate,
    Mention,
    Tag,
    Comment,
    Other(S),
}

impl<S: BosStr> NotificationReason<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Like => "like",
            Self::Bookmark => "bookmark",
            Self::Follow => "follow",
            Self::FollowAccept => "followAccept",
            Self::Subscribe => "subscribe",
            Self::SubscribeAccept => "subscribeAccept",
            Self::CollaborationInvite => "collaborationInvite",
            Self::CollaborationAccept => "collaborationAccept",
            Self::NewEntry => "newEntry",
            Self::EntryUpdate => "entryUpdate",
            Self::Mention => "mention",
            Self::Tag => "tag",
            Self::Comment => "comment",
            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() {
            "like" => Self::Like,
            "bookmark" => Self::Bookmark,
            "follow" => Self::Follow,
            "followAccept" => Self::FollowAccept,
            "subscribe" => Self::Subscribe,
            "subscribeAccept" => Self::SubscribeAccept,
            "collaborationInvite" => Self::CollaborationInvite,
            "collaborationAccept" => Self::CollaborationAccept,
            "newEntry" => Self::NewEntry,
            "entryUpdate" => Self::EntryUpdate,
            "mention" => Self::Mention,
            "tag" => Self::Tag,
            "comment" => Self::Comment,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for NotificationReason<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 NotificationReason<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> jacquard_common::IntoStatic for NotificationReason<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = NotificationReason<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            NotificationReason::Like => NotificationReason::Like,
            NotificationReason::Bookmark => NotificationReason::Bookmark,
            NotificationReason::Follow => NotificationReason::Follow,
            NotificationReason::FollowAccept => NotificationReason::FollowAccept,
            NotificationReason::Subscribe => NotificationReason::Subscribe,
            NotificationReason::SubscribeAccept => NotificationReason::SubscribeAccept,
            NotificationReason::CollaborationInvite => {
                NotificationReason::CollaborationInvite
            }
            NotificationReason::CollaborationAccept => {
                NotificationReason::CollaborationAccept
            }
            NotificationReason::NewEntry => NotificationReason::NewEntry,
            NotificationReason::EntryUpdate => NotificationReason::EntryUpdate,
            NotificationReason::Mention => NotificationReason::Mention,
            NotificationReason::Tag => NotificationReason::Tag,
            NotificationReason::Comment => NotificationReason::Comment,
            NotificationReason::Other(v) => NotificationReason::Other(v.into_static()),
        }
    }
}

/// New content from a notebook subscription.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct SubscriptionUpdateView<S: BosStr = DefaultStr> {
    ///New entries since last check.
    pub new_entries: Vec<EntryView<S>>,
    pub notebook: NotebookView<S>,
    pub updated_at: Datetime,
    ///Entries that were updated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_entries: Option<Vec<EntryView<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Notification<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notification.defs"
    }
    fn def_name() -> &'static str {
        "notification"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notification_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for NotificationGroup<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notification.defs"
    }
    fn def_name() -> &'static str {
        "notificationGroup"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notification_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.actors;
            #[allow(unused_comparisons)]
            if value.len() > 5usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("actors"),
                    max: 5usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for SubscriptionUpdateView<S> {
    fn nsid() -> &'static str {
        "sh.weaver.notification.defs"
    }
    fn def_name() -> &'static str {
        "subscriptionUpdateView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_notification_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod notification_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 Author;
        type Cid;
        type IndexedAt;
        type IsRead;
        type Reason;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Author = Unset;
        type Cid = Unset;
        type IndexedAt = Unset;
        type IsRead = Unset;
        type Reason = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `author` field to Set
    pub struct SetAuthor<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAuthor<St> {}
    impl<St: State> State for SetAuthor<St> {
        type Author = Set<members::author>;
        type Cid = St::Cid;
        type IndexedAt = St::IndexedAt;
        type IsRead = St::IsRead;
        type Reason = St::Reason;
        type Uri = St::Uri;
    }
    ///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 Author = St::Author;
        type Cid = Set<members::cid>;
        type IndexedAt = St::IndexedAt;
        type IsRead = St::IsRead;
        type Reason = St::Reason;
        type Uri = St::Uri;
    }
    ///State transition - sets the `indexed_at` field to Set
    pub struct SetIndexedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetIndexedAt<St> {}
    impl<St: State> State for SetIndexedAt<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type IndexedAt = Set<members::indexed_at>;
        type IsRead = St::IsRead;
        type Reason = St::Reason;
        type Uri = St::Uri;
    }
    ///State transition - sets the `is_read` field to Set
    pub struct SetIsRead<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetIsRead<St> {}
    impl<St: State> State for SetIsRead<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type IndexedAt = St::IndexedAt;
        type IsRead = Set<members::is_read>;
        type Reason = St::Reason;
        type Uri = St::Uri;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReason<St> {}
    impl<St: State> State for SetReason<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type IndexedAt = St::IndexedAt;
        type IsRead = St::IsRead;
        type Reason = Set<members::reason>;
        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 Author = St::Author;
        type Cid = St::Cid;
        type IndexedAt = St::IndexedAt;
        type IsRead = St::IsRead;
        type Reason = St::Reason;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `author` field
        pub struct author(());
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `indexed_at` field
        pub struct indexed_at(());
        ///Marker type for the `is_read` field
        pub struct is_read(());
        ///Marker type for the `reason` field
        pub struct reason(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type.
pub struct NotificationBuilder<St: notification_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<ProfileViewBasic<S>>,
        Option<Cid<S>>,
        Option<Datetime>,
        Option<bool>,
        Option<notification::NotificationReason<S>>,
        Option<AtUri<S>>,
        Option<Data<S>>,
        Option<AtUri<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Notification<S> {
    /// Create a new builder for this type
    pub fn builder() -> NotificationBuilder<notification_state::Empty, S> {
        NotificationBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> NotificationBuilder<St, S>
where
    St: notification_state::State,
    St::Author: notification_state::IsUnset,
{
    /// Set the `author` field (required)
    pub fn author(
        mut self,
        value: impl Into<ProfileViewBasic<S>>,
    ) -> NotificationBuilder<notification_state::SetAuthor<St>, S> {
        self._fields.0 = Option::Some(value.into());
        NotificationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> NotificationBuilder<St, S>
where
    St: notification_state::State,
    St::IndexedAt: notification_state::IsUnset,
{
    /// Set the `indexedAt` field (required)
    pub fn indexed_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> NotificationBuilder<notification_state::SetIndexedAt<St>, S> {
        self._fields.2 = Option::Some(value.into());
        NotificationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> NotificationBuilder<St, S>
where
    St: notification_state::State,
    St::IsRead: notification_state::IsUnset,
{
    /// Set the `isRead` field (required)
    pub fn is_read(
        mut self,
        value: impl Into<bool>,
    ) -> NotificationBuilder<notification_state::SetIsRead<St>, S> {
        self._fields.3 = Option::Some(value.into());
        NotificationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> NotificationBuilder<St, S>
where
    St: notification_state::State,
    St::Reason: notification_state::IsUnset,
{
    /// Set the `reason` field (required)
    pub fn reason(
        mut self,
        value: impl Into<notification::NotificationReason<S>>,
    ) -> NotificationBuilder<notification_state::SetReason<St>, S> {
        self._fields.4 = Option::Some(value.into());
        NotificationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: notification_state::State, S: BosStr> NotificationBuilder<St, S> {
    /// Set the `reasonSubject` field (optional)
    pub fn reason_subject(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `reasonSubject` field to an Option value (optional)
    pub fn maybe_reason_subject(mut self, value: Option<AtUri<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: notification_state::State, S: BosStr> NotificationBuilder<St, S> {
    /// Set the `record` field (optional)
    pub fn record(mut self, value: impl Into<Option<Data<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `record` field to an Option value (optional)
    pub fn maybe_record(mut self, value: Option<Data<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

impl<St, S: BosStr> NotificationBuilder<St, S>
where
    St: notification_state::State,
    St::Author: notification_state::IsSet,
    St::Cid: notification_state::IsSet,
    St::IndexedAt: notification_state::IsSet,
    St::IsRead: notification_state::IsSet,
    St::Reason: notification_state::IsSet,
    St::Uri: notification_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Notification<S> {
        Notification {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            indexed_at: self._fields.2.unwrap(),
            is_read: self._fields.3.unwrap(),
            reason: self._fields.4.unwrap(),
            reason_subject: self._fields.5,
            record: self._fields.6,
            uri: self._fields.7.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>>,
    ) -> Notification<S> {
        Notification {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            indexed_at: self._fields.2.unwrap(),
            is_read: self._fields.3.unwrap(),
            reason: self._fields.4.unwrap(),
            reason_subject: self._fields.5,
            record: self._fields.6,
            uri: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_notification_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("sh.weaver.notification.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("notification"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A notification for a user.")),
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("author"), SmolStr::new_static("reason"),
                            SmolStr::new_static("isRead"),
                            SmolStr::new_static("indexedAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("author"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.actor.defs#profileViewBasic",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("indexedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isRead"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reason"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#notificationReason"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reasonSubject"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The subject of the notification (entry, notebook, etc).",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("record"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("notificationGroup"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Grouped notifications (e.g., '5 people liked your entry').",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("reason"),
                            SmolStr::new_static("subject"), SmolStr::new_static("count"),
                            SmolStr::new_static("actors"),
                            SmolStr::new_static("mostRecentAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("actors"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("Most recent actors (up to 5)."),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "sh.weaver.actor.defs#profileViewBasic",
                                    ),
                                    ..Default::default()
                                }),
                                max_length: Some(5usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("count"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isRead"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("mostRecentAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reason"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#notificationReason"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("subject"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("sh.weaver.notebook.defs#notebookView"),
                                    CowStr::new_static("sh.weaver.notebook.defs#entryView")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("notificationReason"),
                LexUserType::String(LexString {
                    description: Some(
                        CowStr::new_static("Why this notification was generated."),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("subscriptionUpdateView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("New content from a notebook subscription."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("notebook"),
                            SmolStr::new_static("newEntries"),
                            SmolStr::new_static("updatedAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("newEntries"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("New entries since last check."),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "sh.weaver.notebook.defs#entryView",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("notebook"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "sh.weaver.notebook.defs#notebookView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("updatedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("updatedEntries"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("Entries that were updated."),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "sh.weaver.notebook.defs#entryView",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod notification_group_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 Actors;
        type Count;
        type MostRecentAt;
        type Reason;
        type Subject;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Actors = Unset;
        type Count = Unset;
        type MostRecentAt = Unset;
        type Reason = Unset;
        type Subject = Unset;
    }
    ///State transition - sets the `actors` field to Set
    pub struct SetActors<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetActors<St> {}
    impl<St: State> State for SetActors<St> {
        type Actors = Set<members::actors>;
        type Count = St::Count;
        type MostRecentAt = St::MostRecentAt;
        type Reason = St::Reason;
        type Subject = St::Subject;
    }
    ///State transition - sets the `count` field to Set
    pub struct SetCount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCount<St> {}
    impl<St: State> State for SetCount<St> {
        type Actors = St::Actors;
        type Count = Set<members::count>;
        type MostRecentAt = St::MostRecentAt;
        type Reason = St::Reason;
        type Subject = St::Subject;
    }
    ///State transition - sets the `most_recent_at` field to Set
    pub struct SetMostRecentAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMostRecentAt<St> {}
    impl<St: State> State for SetMostRecentAt<St> {
        type Actors = St::Actors;
        type Count = St::Count;
        type MostRecentAt = Set<members::most_recent_at>;
        type Reason = St::Reason;
        type Subject = St::Subject;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReason<St> {}
    impl<St: State> State for SetReason<St> {
        type Actors = St::Actors;
        type Count = St::Count;
        type MostRecentAt = St::MostRecentAt;
        type Reason = Set<members::reason>;
        type Subject = St::Subject;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type Actors = St::Actors;
        type Count = St::Count;
        type MostRecentAt = St::MostRecentAt;
        type Reason = St::Reason;
        type Subject = Set<members::subject>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `actors` field
        pub struct actors(());
        ///Marker type for the `count` field
        pub struct count(());
        ///Marker type for the `most_recent_at` field
        pub struct most_recent_at(());
        ///Marker type for the `reason` field
        pub struct reason(());
        ///Marker type for the `subject` field
        pub struct subject(());
    }
}

/// Builder for constructing an instance of this type.
pub struct NotificationGroupBuilder<
    St: notification_group_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<ProfileViewBasic<S>>>,
        Option<i64>,
        Option<bool>,
        Option<Datetime>,
        Option<notification::NotificationReason<S>>,
        Option<NotificationGroupSubject<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> NotificationGroup<S> {
    /// Create a new builder for this type
    pub fn builder() -> NotificationGroupBuilder<notification_group_state::Empty, S> {
        NotificationGroupBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> NotificationGroupBuilder<St, S>
where
    St: notification_group_state::State,
    St::Actors: notification_group_state::IsUnset,
{
    /// Set the `actors` field (required)
    pub fn actors(
        mut self,
        value: impl Into<Vec<ProfileViewBasic<S>>>,
    ) -> NotificationGroupBuilder<notification_group_state::SetActors<St>, S> {
        self._fields.0 = Option::Some(value.into());
        NotificationGroupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> NotificationGroupBuilder<St, S>
where
    St: notification_group_state::State,
    St::Count: notification_group_state::IsUnset,
{
    /// Set the `count` field (required)
    pub fn count(
        mut self,
        value: impl Into<i64>,
    ) -> NotificationGroupBuilder<notification_group_state::SetCount<St>, S> {
        self._fields.1 = Option::Some(value.into());
        NotificationGroupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: notification_group_state::State, S: BosStr> NotificationGroupBuilder<St, S> {
    /// Set the `isRead` field (optional)
    pub fn is_read(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `isRead` field to an Option value (optional)
    pub fn maybe_is_read(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> NotificationGroupBuilder<St, S>
where
    St: notification_group_state::State,
    St::MostRecentAt: notification_group_state::IsUnset,
{
    /// Set the `mostRecentAt` field (required)
    pub fn most_recent_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> NotificationGroupBuilder<notification_group_state::SetMostRecentAt<St>, S> {
        self._fields.3 = Option::Some(value.into());
        NotificationGroupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> NotificationGroupBuilder<St, S>
where
    St: notification_group_state::State,
    St::Reason: notification_group_state::IsUnset,
{
    /// Set the `reason` field (required)
    pub fn reason(
        mut self,
        value: impl Into<notification::NotificationReason<S>>,
    ) -> NotificationGroupBuilder<notification_group_state::SetReason<St>, S> {
        self._fields.4 = Option::Some(value.into());
        NotificationGroupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> NotificationGroupBuilder<St, S>
where
    St: notification_group_state::State,
    St::Subject: notification_group_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<NotificationGroupSubject<S>>,
    ) -> NotificationGroupBuilder<notification_group_state::SetSubject<St>, S> {
        self._fields.5 = Option::Some(value.into());
        NotificationGroupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> NotificationGroupBuilder<St, S>
where
    St: notification_group_state::State,
    St::Actors: notification_group_state::IsSet,
    St::Count: notification_group_state::IsSet,
    St::MostRecentAt: notification_group_state::IsSet,
    St::Reason: notification_group_state::IsSet,
    St::Subject: notification_group_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> NotificationGroup<S> {
        NotificationGroup {
            actors: self._fields.0.unwrap(),
            count: self._fields.1.unwrap(),
            is_read: self._fields.2,
            most_recent_at: self._fields.3.unwrap(),
            reason: self._fields.4.unwrap(),
            subject: 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>>,
    ) -> NotificationGroup<S> {
        NotificationGroup {
            actors: self._fields.0.unwrap(),
            count: self._fields.1.unwrap(),
            is_read: self._fields.2,
            most_recent_at: self._fields.3.unwrap(),
            reason: self._fields.4.unwrap(),
            subject: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod subscription_update_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 NewEntries;
        type Notebook;
        type UpdatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type NewEntries = Unset;
        type Notebook = Unset;
        type UpdatedAt = Unset;
    }
    ///State transition - sets the `new_entries` field to Set
    pub struct SetNewEntries<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetNewEntries<St> {}
    impl<St: State> State for SetNewEntries<St> {
        type NewEntries = Set<members::new_entries>;
        type Notebook = St::Notebook;
        type UpdatedAt = St::UpdatedAt;
    }
    ///State transition - sets the `notebook` field to Set
    pub struct SetNotebook<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetNotebook<St> {}
    impl<St: State> State for SetNotebook<St> {
        type NewEntries = St::NewEntries;
        type Notebook = Set<members::notebook>;
        type UpdatedAt = St::UpdatedAt;
    }
    ///State transition - sets the `updated_at` field to Set
    pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
    impl<St: State> State for SetUpdatedAt<St> {
        type NewEntries = St::NewEntries;
        type Notebook = St::Notebook;
        type UpdatedAt = Set<members::updated_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `new_entries` field
        pub struct new_entries(());
        ///Marker type for the `notebook` field
        pub struct notebook(());
        ///Marker type for the `updated_at` field
        pub struct updated_at(());
    }
}

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

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

impl<S: BosStr> SubscriptionUpdateView<S> {
    /// Create a new builder for this type
    pub fn builder() -> SubscriptionUpdateViewBuilder<
        subscription_update_view_state::Empty,
        S,
    > {
        SubscriptionUpdateViewBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SubscriptionUpdateViewBuilder<St, S>
where
    St: subscription_update_view_state::State,
    St::NewEntries: subscription_update_view_state::IsUnset,
{
    /// Set the `newEntries` field (required)
    pub fn new_entries(
        mut self,
        value: impl Into<Vec<EntryView<S>>>,
    ) -> SubscriptionUpdateViewBuilder<
        subscription_update_view_state::SetNewEntries<St>,
        S,
    > {
        self._fields.0 = Option::Some(value.into());
        SubscriptionUpdateViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SubscriptionUpdateViewBuilder<St, S>
where
    St: subscription_update_view_state::State,
    St::Notebook: subscription_update_view_state::IsUnset,
{
    /// Set the `notebook` field (required)
    pub fn notebook(
        mut self,
        value: impl Into<NotebookView<S>>,
    ) -> SubscriptionUpdateViewBuilder<
        subscription_update_view_state::SetNotebook<St>,
        S,
    > {
        self._fields.1 = Option::Some(value.into());
        SubscriptionUpdateViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SubscriptionUpdateViewBuilder<St, S>
where
    St: subscription_update_view_state::State,
    St::UpdatedAt: subscription_update_view_state::IsUnset,
{
    /// Set the `updatedAt` field (required)
    pub fn updated_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SubscriptionUpdateViewBuilder<
        subscription_update_view_state::SetUpdatedAt<St>,
        S,
    > {
        self._fields.2 = Option::Some(value.into());
        SubscriptionUpdateViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<
    St: subscription_update_view_state::State,
    S: BosStr,
> SubscriptionUpdateViewBuilder<St, S> {
    /// Set the `updatedEntries` field (optional)
    pub fn updated_entries(
        mut self,
        value: impl Into<Option<Vec<EntryView<S>>>>,
    ) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `updatedEntries` field to an Option value (optional)
    pub fn maybe_updated_entries(mut self, value: Option<Vec<EntryView<S>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> SubscriptionUpdateViewBuilder<St, S>
where
    St: subscription_update_view_state::State,
    St::NewEntries: subscription_update_view_state::IsSet,
    St::Notebook: subscription_update_view_state::IsSet,
    St::UpdatedAt: subscription_update_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SubscriptionUpdateView<S> {
        SubscriptionUpdateView {
            new_entries: self._fields.0.unwrap(),
            notebook: self._fields.1.unwrap(),
            updated_at: self._fields.2.unwrap(),
            updated_entries: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> SubscriptionUpdateView<S> {
        SubscriptionUpdateView {
            new_entries: self._fields.0.unwrap(),
            notebook: self._fields.1.unwrap(),
            updated_at: self._fields.2.unwrap(),
            updated_entries: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}