// @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.

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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Notification<'a> {
    #[serde(borrow)]
    pub author: ProfileViewBasic<'a>,
    #[serde(borrow)]
    pub cid: Cid<'a>,
    pub indexed_at: Datetime,
    pub is_read: bool,
    #[serde(borrow)]
    pub reason: notification::NotificationReason<'a>,
    ///The subject of the notification (entry, notebook, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub reason_subject: Option<AtUri<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub record: Option<Data<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct NotificationGroup<'a> {
    ///Most recent actors (up to 5).
    #[serde(borrow)]
    pub actors: Vec<ProfileViewBasic<'a>>,
    pub count: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_read: Option<bool>,
    pub most_recent_at: Datetime,
    #[serde(borrow)]
    pub reason: notification::NotificationReason<'a>,
    #[serde(borrow)]
    pub subject: NotificationGroupSubject<'a>,
}


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

/// Why this notification was generated.

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

impl<'a> NotificationReason<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for NotificationReason<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "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(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for NotificationReason<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "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(CowStr::from(s)),
        }
    }
}

impl<'a> AsRef<str> for NotificationReason<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'a> serde::Serialize for NotificationReason<'a> {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, 'a> serde::Deserialize<'de> for NotificationReason<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl jacquard_common::IntoStatic for NotificationReason<'_> {
    type Output = NotificationReason<'static>;
    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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SubscriptionUpdateView<'a> {
    ///New entries since last check.
    #[serde(borrow)]
    pub new_entries: Vec<EntryView<'a>>,
    #[serde(borrow)]
    pub notebook: NotebookView<'a>,
    pub updated_at: Datetime,
    ///Entries that were updated.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub updated_entries: Option<Vec<EntryView<'a>>>,
}

impl<'a> LexiconSchema for Notification<'a> {
    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<'a> LexiconSchema for NotificationGroup<'a> {
    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<'a> LexiconSchema for SubscriptionUpdateView<'a> {
    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 Cid;
        type Uri;
        type Author;
        type Reason;
        type IndexedAt;
        type IsRead;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Uri = Unset;
        type Author = Unset;
        type Reason = Unset;
        type IndexedAt = Unset;
        type IsRead = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCid<S> {}
    impl<S: State> State for SetCid<S> {
        type Cid = Set<members::cid>;
        type Uri = S::Uri;
        type Author = S::Author;
        type Reason = S::Reason;
        type IndexedAt = S::IndexedAt;
        type IsRead = S::IsRead;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Cid = S::Cid;
        type Uri = Set<members::uri>;
        type Author = S::Author;
        type Reason = S::Reason;
        type IndexedAt = S::IndexedAt;
        type IsRead = S::IsRead;
    }
    ///State transition - sets the `author` field to Set
    pub struct SetAuthor<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAuthor<S> {}
    impl<S: State> State for SetAuthor<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type Author = Set<members::author>;
        type Reason = S::Reason;
        type IndexedAt = S::IndexedAt;
        type IsRead = S::IsRead;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetReason<S> {}
    impl<S: State> State for SetReason<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type Author = S::Author;
        type Reason = Set<members::reason>;
        type IndexedAt = S::IndexedAt;
        type IsRead = S::IsRead;
    }
    ///State transition - sets the `indexed_at` field to Set
    pub struct SetIndexedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIndexedAt<S> {}
    impl<S: State> State for SetIndexedAt<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type Author = S::Author;
        type Reason = S::Reason;
        type IndexedAt = Set<members::indexed_at>;
        type IsRead = S::IsRead;
    }
    ///State transition - sets the `is_read` field to Set
    pub struct SetIsRead<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIsRead<S> {}
    impl<S: State> State for SetIsRead<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type Author = S::Author;
        type Reason = S::Reason;
        type IndexedAt = S::IndexedAt;
        type IsRead = Set<members::is_read>;
    }
    /// 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 `uri` field
        pub struct uri(());
        ///Marker type for the `author` field
        pub struct author(());
        ///Marker type for the `reason` field
        pub struct reason(());
        ///Marker type for the `indexed_at` field
        pub struct indexed_at(());
        ///Marker type for the `is_read` field
        pub struct is_read(());
    }
}

/// Builder for constructing an instance of this type
pub struct NotificationBuilder<'a, S: notification_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<ProfileViewBasic<'a>>,
        Option<Cid<'a>>,
        Option<Datetime>,
        Option<bool>,
        Option<notification::NotificationReason<'a>>,
        Option<AtUri<'a>>,
        Option<Data<'a>>,
        Option<AtUri<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

impl<'a, S: notification_state::State> NotificationBuilder<'a, S> {
    /// Set the `reasonSubject` field (optional)
    pub fn reason_subject(mut self, value: impl Into<Option<AtUri<'a>>>) -> 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<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S: notification_state::State> NotificationBuilder<'a, S> {
    /// Set the `record` field (optional)
    pub fn record(mut self, value: impl Into<Option<Data<'a>>>) -> 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<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

impl<'a, S> NotificationBuilder<'a, S>
where
    S: notification_state::State,
    S::Cid: notification_state::IsSet,
    S::Uri: notification_state::IsSet,
    S::Author: notification_state::IsSet,
    S::Reason: notification_state::IsSet,
    S::IndexedAt: notification_state::IsSet,
    S::IsRead: notification_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Notification<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Notification<'a> {
        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 Reason;
        type MostRecentAt;
        type Count;
        type Subject;
        type Actors;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Reason = Unset;
        type MostRecentAt = Unset;
        type Count = Unset;
        type Subject = Unset;
        type Actors = Unset;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetReason<S> {}
    impl<S: State> State for SetReason<S> {
        type Reason = Set<members::reason>;
        type MostRecentAt = S::MostRecentAt;
        type Count = S::Count;
        type Subject = S::Subject;
        type Actors = S::Actors;
    }
    ///State transition - sets the `most_recent_at` field to Set
    pub struct SetMostRecentAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMostRecentAt<S> {}
    impl<S: State> State for SetMostRecentAt<S> {
        type Reason = S::Reason;
        type MostRecentAt = Set<members::most_recent_at>;
        type Count = S::Count;
        type Subject = S::Subject;
        type Actors = S::Actors;
    }
    ///State transition - sets the `count` field to Set
    pub struct SetCount<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCount<S> {}
    impl<S: State> State for SetCount<S> {
        type Reason = S::Reason;
        type MostRecentAt = S::MostRecentAt;
        type Count = Set<members::count>;
        type Subject = S::Subject;
        type Actors = S::Actors;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubject<S> {}
    impl<S: State> State for SetSubject<S> {
        type Reason = S::Reason;
        type MostRecentAt = S::MostRecentAt;
        type Count = S::Count;
        type Subject = Set<members::subject>;
        type Actors = S::Actors;
    }
    ///State transition - sets the `actors` field to Set
    pub struct SetActors<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetActors<S> {}
    impl<S: State> State for SetActors<S> {
        type Reason = S::Reason;
        type MostRecentAt = S::MostRecentAt;
        type Count = S::Count;
        type Subject = S::Subject;
        type Actors = Set<members::actors>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `reason` field
        pub struct reason(());
        ///Marker type for the `most_recent_at` field
        pub struct most_recent_at(());
        ///Marker type for the `count` field
        pub struct count(());
        ///Marker type for the `subject` field
        pub struct subject(());
        ///Marker type for the `actors` field
        pub struct actors(());
    }
}

/// Builder for constructing an instance of this type
pub struct NotificationGroupBuilder<'a, S: notification_group_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<ProfileViewBasic<'a>>>,
        Option<i64>,
        Option<bool>,
        Option<Datetime>,
        Option<notification::NotificationReason<'a>>,
        Option<NotificationGroupSubject<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: notification_group_state::State> NotificationGroupBuilder<'a, 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<'a, S> NotificationGroupBuilder<'a, S>
where
    S: notification_group_state::State,
    S::MostRecentAt: notification_group_state::IsUnset,
{
    /// Set the `mostRecentAt` field (required)
    pub fn most_recent_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> NotificationGroupBuilder<'a, notification_group_state::SetMostRecentAt<S>> {
        self._fields.3 = Option::Some(value.into());
        NotificationGroupBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

impl<'a, S> NotificationGroupBuilder<'a, S>
where
    S: notification_group_state::State,
    S::Reason: notification_group_state::IsSet,
    S::MostRecentAt: notification_group_state::IsSet,
    S::Count: notification_group_state::IsSet,
    S::Subject: notification_group_state::IsSet,
    S::Actors: notification_group_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> NotificationGroup<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> NotificationGroup<'a> {
        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 UpdatedAt;
        type Notebook;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type NewEntries = Unset;
        type UpdatedAt = Unset;
        type Notebook = Unset;
    }
    ///State transition - sets the `new_entries` field to Set
    pub struct SetNewEntries<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNewEntries<S> {}
    impl<S: State> State for SetNewEntries<S> {
        type NewEntries = Set<members::new_entries>;
        type UpdatedAt = S::UpdatedAt;
        type Notebook = S::Notebook;
    }
    ///State transition - sets the `updated_at` field to Set
    pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
    impl<S: State> State for SetUpdatedAt<S> {
        type NewEntries = S::NewEntries;
        type UpdatedAt = Set<members::updated_at>;
        type Notebook = S::Notebook;
    }
    ///State transition - sets the `notebook` field to Set
    pub struct SetNotebook<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNotebook<S> {}
    impl<S: State> State for SetNotebook<S> {
        type NewEntries = S::NewEntries;
        type UpdatedAt = S::UpdatedAt;
        type Notebook = Set<members::notebook>;
    }
    /// 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 `updated_at` field
        pub struct updated_at(());
        ///Marker type for the `notebook` field
        pub struct notebook(());
    }
}

/// Builder for constructing an instance of this type
pub struct SubscriptionUpdateViewBuilder<'a, S: subscription_update_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<EntryView<'a>>>,
        Option<NotebookView<'a>>,
        Option<Datetime>,
        Option<Vec<EntryView<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S: subscription_update_view_state::State> SubscriptionUpdateViewBuilder<'a, S> {
    /// Set the `updatedEntries` field (optional)
    pub fn updated_entries(
        mut self,
        value: impl Into<Option<Vec<EntryView<'a>>>>,
    ) -> 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<'a>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> SubscriptionUpdateViewBuilder<'a, S>
where
    S: subscription_update_view_state::State,
    S::NewEntries: subscription_update_view_state::IsSet,
    S::UpdatedAt: subscription_update_view_state::IsSet,
    S::Notebook: subscription_update_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SubscriptionUpdateView<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> SubscriptionUpdateView<'a> {
        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),
        }
    }
}