// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.edit.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.edit` Lexicon namespace/module.
pub mod cursor;
pub mod diff;
pub mod draft;
pub mod get_branch;
pub mod get_contributors;
pub mod get_edit_history;
pub mod get_edit_tree;
pub mod list_drafts;
pub mod root;


#[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::com_atproto::repo::strong_ref::StrongRef;
use crate::sh_weaver::actor::ProfileViewBasic;
use crate::sh_weaver::edit;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DocRef<S: BosStr = DefaultStr> {
    pub value: DocRefValue<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 DocRefValue<S: BosStr = DefaultStr> {
    #[serde(rename = "sh.weaver.edit.defs#notebookRef")]
    NotebookRef(Box<edit::NotebookRef<S>>),
    #[serde(rename = "sh.weaver.edit.defs#entryRef")]
    EntryRef(Box<edit::EntryRef<S>>),
    #[serde(rename = "sh.weaver.edit.defs#draftRef")]
    DraftRef(Box<edit::DraftRef<S>>),
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DraftRef<S: BosStr = DefaultStr> {
    pub draft_key: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A branch/fork in edit history (for when collaborators diverge).

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct EditBranchView<S: BosStr = DefaultStr> {
    pub author: ProfileViewBasic<S>,
    ///Common ancestor if this is a fork
    #[serde(skip_serializing_if = "Option::is_none")]
    pub diverges_from: Option<StrongRef<S>>,
    pub head: StrongRef<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub is_merged: Option<bool>,
    pub last_updated: Datetime,
    ///Number of diffs in this branch
    pub length: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub root: Option<StrongRef<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Summary of an edit (root or diff) for history queries.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct EditHistoryEntry<S: BosStr = DefaultStr> {
    pub author: ProfileViewBasic<S>,
    pub cid: Cid<S>,
    pub created_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_inline_diff: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prev_ref: Option<StrongRef<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub root_ref: Option<StrongRef<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub snapshot_cid: Option<Cid<S>>,
    pub r#type: EditHistoryEntryType<S>,
    pub uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EditHistoryEntryType<S: BosStr = DefaultStr> {
    Root,
    Diff,
    Other(S),
}

impl<S: BosStr> EditHistoryEntryType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Root => "root",
            Self::Diff => "diff",
            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() {
            "root" => Self::Root,
            "diff" => Self::Diff,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for EditHistoryEntryType<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 EditHistoryEntryType<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for EditHistoryEntryType<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

/// Full tree structure showing all branches for a resource.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct EditTreeView<S: BosStr = DefaultStr> {
    pub branches: Vec<edit::EditBranchView<S>>,
    ///Diffs where branches diverge
    #[serde(skip_serializing_if = "Option::is_none")]
    pub conflict_points: Option<Vec<StrongRef<S>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_conflicts: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub main_branch: Option<edit::EditBranchView<S>>,
    pub resource: StrongRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct EntryRef<S: BosStr = DefaultStr> {
    pub entry: StrongRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct NotebookRef<S: BosStr = DefaultStr> {
    pub notebook: StrongRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

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

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

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

pub mod doc_ref_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 Value;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Value = Unset;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetValue<St> {}
    impl<St: State> State for SetValue<St> {
        type Value = Set<members::value>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `value` field
        pub struct value(());
    }
}

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

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

impl<S: BosStr> DocRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> DocRefBuilder<doc_ref_state::Empty, S> {
        DocRefBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> DocRefBuilder<St, S>
where
    St: doc_ref_state::State,
    St::Value: doc_ref_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<DocRefValue<S>>,
    ) -> DocRefBuilder<doc_ref_state::SetValue<St>, S> {
        self._fields.0 = Option::Some(value.into());
        DocRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DocRefBuilder<St, S>
where
    St: doc_ref_state::State,
    St::Value: doc_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> DocRef<S> {
        DocRef {
            value: self._fields.0.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>>) -> DocRef<S> {
        DocRef {
            value: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_edit_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.edit.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("docRef"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("value")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("#notebookRef"),
                                    CowStr::new_static("#entryRef"),
                                    CowStr::new_static("#draftRef")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("draftRef"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("draftKey")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("draftKey"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(200usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("editBranchView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A branch/fork in edit history (for when collaborators diverge).",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("head"), SmolStr::new_static("author"),
                            SmolStr::new_static("length"),
                            SmolStr::new_static("lastUpdated")
                        ],
                    ),
                    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("divergesFrom"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("head"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isMerged"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("lastUpdated"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("length"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("root"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("editHistoryEntry"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Summary of an edit (root or diff) for history queries.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("author"),
                            SmolStr::new_static("createdAt"), SmolStr::new_static("type")
                        ],
                    ),
                    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("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("hasInlineDiff"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("prevRef"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rootRef"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("snapshotCid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString { ..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("editTreeView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Full tree structure showing all branches for a resource.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("resource"),
                            SmolStr::new_static("branches")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("branches"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#editBranchView"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("conflictPoints"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static("Diffs where branches diverge"),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("hasConflicts"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("mainBranch"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#editBranchView"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("resource"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("entryRef"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("entry")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("entry"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("notebookRef"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("notebook")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("notebook"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod edit_branch_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 Author;
        type Head;
        type LastUpdated;
        type Length;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Author = Unset;
        type Head = Unset;
        type LastUpdated = Unset;
        type Length = 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 Head = St::Head;
        type LastUpdated = St::LastUpdated;
        type Length = St::Length;
    }
    ///State transition - sets the `head` field to Set
    pub struct SetHead<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHead<St> {}
    impl<St: State> State for SetHead<St> {
        type Author = St::Author;
        type Head = Set<members::head>;
        type LastUpdated = St::LastUpdated;
        type Length = St::Length;
    }
    ///State transition - sets the `last_updated` field to Set
    pub struct SetLastUpdated<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLastUpdated<St> {}
    impl<St: State> State for SetLastUpdated<St> {
        type Author = St::Author;
        type Head = St::Head;
        type LastUpdated = Set<members::last_updated>;
        type Length = St::Length;
    }
    ///State transition - sets the `length` field to Set
    pub struct SetLength<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLength<St> {}
    impl<St: State> State for SetLength<St> {
        type Author = St::Author;
        type Head = St::Head;
        type LastUpdated = St::LastUpdated;
        type Length = Set<members::length>;
    }
    /// 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 `head` field
        pub struct head(());
        ///Marker type for the `last_updated` field
        pub struct last_updated(());
        ///Marker type for the `length` field
        pub struct length(());
    }
}

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

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

impl<S: BosStr> EditBranchView<S> {
    /// Create a new builder for this type
    pub fn builder() -> EditBranchViewBuilder<edit_branch_view_state::Empty, S> {
        EditBranchViewBuilder::builder()
    }
}

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

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

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

impl<St: edit_branch_view_state::State, S: BosStr> EditBranchViewBuilder<St, S> {
    /// Set the `divergesFrom` field (optional)
    pub fn diverges_from(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `divergesFrom` field to an Option value (optional)
    pub fn maybe_diverges_from(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> EditBranchViewBuilder<St, S>
where
    St: edit_branch_view_state::State,
    St::Head: edit_branch_view_state::IsUnset,
{
    /// Set the `head` field (required)
    pub fn head(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> EditBranchViewBuilder<edit_branch_view_state::SetHead<St>, S> {
        self._fields.2 = Option::Some(value.into());
        EditBranchViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: edit_branch_view_state::State, S: BosStr> EditBranchViewBuilder<St, S> {
    /// Set the `isMerged` field (optional)
    pub fn is_merged(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `isMerged` field to an Option value (optional)
    pub fn maybe_is_merged(mut self, value: Option<bool>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> EditBranchViewBuilder<St, S>
where
    St: edit_branch_view_state::State,
    St::LastUpdated: edit_branch_view_state::IsUnset,
{
    /// Set the `lastUpdated` field (required)
    pub fn last_updated(
        mut self,
        value: impl Into<Datetime>,
    ) -> EditBranchViewBuilder<edit_branch_view_state::SetLastUpdated<St>, S> {
        self._fields.4 = Option::Some(value.into());
        EditBranchViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EditBranchViewBuilder<St, S>
where
    St: edit_branch_view_state::State,
    St::Length: edit_branch_view_state::IsUnset,
{
    /// Set the `length` field (required)
    pub fn length(
        mut self,
        value: impl Into<i64>,
    ) -> EditBranchViewBuilder<edit_branch_view_state::SetLength<St>, S> {
        self._fields.5 = Option::Some(value.into());
        EditBranchViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: edit_branch_view_state::State, S: BosStr> EditBranchViewBuilder<St, S> {
    /// Set the `root` field (optional)
    pub fn root(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `root` field to an Option value (optional)
    pub fn maybe_root(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> EditBranchViewBuilder<St, S>
where
    St: edit_branch_view_state::State,
    St::Author: edit_branch_view_state::IsSet,
    St::Head: edit_branch_view_state::IsSet,
    St::LastUpdated: edit_branch_view_state::IsSet,
    St::Length: edit_branch_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> EditBranchView<S> {
        EditBranchView {
            author: self._fields.0.unwrap(),
            diverges_from: self._fields.1,
            head: self._fields.2.unwrap(),
            is_merged: self._fields.3,
            last_updated: self._fields.4.unwrap(),
            length: self._fields.5.unwrap(),
            root: self._fields.6,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> EditBranchView<S> {
        EditBranchView {
            author: self._fields.0.unwrap(),
            diverges_from: self._fields.1,
            head: self._fields.2.unwrap(),
            is_merged: self._fields.3,
            last_updated: self._fields.4.unwrap(),
            length: self._fields.5.unwrap(),
            root: self._fields.6,
            extra_data: Some(extra_data),
        }
    }
}

pub mod edit_history_entry_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 CreatedAt;
        type Type;
        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 CreatedAt = Unset;
        type Type = 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 CreatedAt = St::CreatedAt;
        type Type = St::Type;
        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 CreatedAt = St::CreatedAt;
        type Type = St::Type;
        type Uri = St::Uri;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type CreatedAt = Set<members::created_at>;
        type Type = St::Type;
        type Uri = St::Uri;
    }
    ///State transition - sets the `type` field to Set
    pub struct SetType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetType<St> {}
    impl<St: State> State for SetType<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type CreatedAt = St::CreatedAt;
        type Type = Set<members::r#type>;
        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 CreatedAt = St::CreatedAt;
        type Type = St::Type;
        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 `created_at` field
        pub struct created_at(());
        ///Marker type for the `type` field
        pub struct r#type(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> EditHistoryEntry<S> {
    /// Create a new builder for this type
    pub fn builder() -> EditHistoryEntryBuilder<edit_history_entry_state::Empty, S> {
        EditHistoryEntryBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> EditHistoryEntryBuilder<St, S>
where
    St: edit_history_entry_state::State,
    St::CreatedAt: edit_history_entry_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> EditHistoryEntryBuilder<edit_history_entry_state::SetCreatedAt<St>, S> {
        self._fields.2 = Option::Some(value.into());
        EditHistoryEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: edit_history_entry_state::State, S: BosStr> EditHistoryEntryBuilder<St, S> {
    /// Set the `hasInlineDiff` field (optional)
    pub fn has_inline_diff(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `hasInlineDiff` field to an Option value (optional)
    pub fn maybe_has_inline_diff(mut self, value: Option<bool>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: edit_history_entry_state::State, S: BosStr> EditHistoryEntryBuilder<St, S> {
    /// Set the `prevRef` field (optional)
    pub fn prev_ref(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `prevRef` field to an Option value (optional)
    pub fn maybe_prev_ref(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: edit_history_entry_state::State, S: BosStr> EditHistoryEntryBuilder<St, S> {
    /// Set the `rootRef` field (optional)
    pub fn root_ref(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `rootRef` field to an Option value (optional)
    pub fn maybe_root_ref(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: edit_history_entry_state::State, S: BosStr> EditHistoryEntryBuilder<St, S> {
    /// Set the `snapshotCid` field (optional)
    pub fn snapshot_cid(mut self, value: impl Into<Option<Cid<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `snapshotCid` field to an Option value (optional)
    pub fn maybe_snapshot_cid(mut self, value: Option<Cid<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> EditHistoryEntryBuilder<St, S>
where
    St: edit_history_entry_state::State,
    St::Type: edit_history_entry_state::IsUnset,
{
    /// Set the `type` field (required)
    pub fn r#type(
        mut self,
        value: impl Into<EditHistoryEntryType<S>>,
    ) -> EditHistoryEntryBuilder<edit_history_entry_state::SetType<St>, S> {
        self._fields.7 = Option::Some(value.into());
        EditHistoryEntryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> EditHistoryEntryBuilder<St, S>
where
    St: edit_history_entry_state::State,
    St::Author: edit_history_entry_state::IsSet,
    St::Cid: edit_history_entry_state::IsSet,
    St::CreatedAt: edit_history_entry_state::IsSet,
    St::Type: edit_history_entry_state::IsSet,
    St::Uri: edit_history_entry_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> EditHistoryEntry<S> {
        EditHistoryEntry {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            has_inline_diff: self._fields.3,
            prev_ref: self._fields.4,
            root_ref: self._fields.5,
            snapshot_cid: self._fields.6,
            r#type: self._fields.7.unwrap(),
            uri: self._fields.8.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> EditHistoryEntry<S> {
        EditHistoryEntry {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            has_inline_diff: self._fields.3,
            prev_ref: self._fields.4,
            root_ref: self._fields.5,
            snapshot_cid: self._fields.6,
            r#type: self._fields.7.unwrap(),
            uri: self._fields.8.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod edit_tree_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 Branches;
        type Resource;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Branches = Unset;
        type Resource = Unset;
    }
    ///State transition - sets the `branches` field to Set
    pub struct SetBranches<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBranches<St> {}
    impl<St: State> State for SetBranches<St> {
        type Branches = Set<members::branches>;
        type Resource = St::Resource;
    }
    ///State transition - sets the `resource` field to Set
    pub struct SetResource<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetResource<St> {}
    impl<St: State> State for SetResource<St> {
        type Branches = St::Branches;
        type Resource = Set<members::resource>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `branches` field
        pub struct branches(());
        ///Marker type for the `resource` field
        pub struct resource(());
    }
}

/// Builder for constructing an instance of this type.
pub struct EditTreeViewBuilder<St: edit_tree_view_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<edit::EditBranchView<S>>>,
        Option<Vec<StrongRef<S>>>,
        Option<bool>,
        Option<edit::EditBranchView<S>>,
        Option<StrongRef<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> EditTreeView<S> {
    /// Create a new builder for this type
    pub fn builder() -> EditTreeViewBuilder<edit_tree_view_state::Empty, S> {
        EditTreeViewBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> EditTreeViewBuilder<St, S>
where
    St: edit_tree_view_state::State,
    St::Branches: edit_tree_view_state::IsUnset,
{
    /// Set the `branches` field (required)
    pub fn branches(
        mut self,
        value: impl Into<Vec<edit::EditBranchView<S>>>,
    ) -> EditTreeViewBuilder<edit_tree_view_state::SetBranches<St>, S> {
        self._fields.0 = Option::Some(value.into());
        EditTreeViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: edit_tree_view_state::State, S: BosStr> EditTreeViewBuilder<St, S> {
    /// Set the `conflictPoints` field (optional)
    pub fn conflict_points(
        mut self,
        value: impl Into<Option<Vec<StrongRef<S>>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `conflictPoints` field to an Option value (optional)
    pub fn maybe_conflict_points(mut self, value: Option<Vec<StrongRef<S>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: edit_tree_view_state::State, S: BosStr> EditTreeViewBuilder<St, S> {
    /// Set the `hasConflicts` field (optional)
    pub fn has_conflicts(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `hasConflicts` field to an Option value (optional)
    pub fn maybe_has_conflicts(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: edit_tree_view_state::State, S: BosStr> EditTreeViewBuilder<St, S> {
    /// Set the `mainBranch` field (optional)
    pub fn main_branch(
        mut self,
        value: impl Into<Option<edit::EditBranchView<S>>>,
    ) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `mainBranch` field to an Option value (optional)
    pub fn maybe_main_branch(mut self, value: Option<edit::EditBranchView<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> EditTreeViewBuilder<St, S>
where
    St: edit_tree_view_state::State,
    St::Resource: edit_tree_view_state::IsUnset,
{
    /// Set the `resource` field (required)
    pub fn resource(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> EditTreeViewBuilder<edit_tree_view_state::SetResource<St>, S> {
        self._fields.4 = Option::Some(value.into());
        EditTreeViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EditTreeViewBuilder<St, S>
where
    St: edit_tree_view_state::State,
    St::Branches: edit_tree_view_state::IsSet,
    St::Resource: edit_tree_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> EditTreeView<S> {
        EditTreeView {
            branches: self._fields.0.unwrap(),
            conflict_points: self._fields.1,
            has_conflicts: self._fields.2,
            main_branch: self._fields.3,
            resource: self._fields.4.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> EditTreeView<S> {
        EditTreeView {
            branches: self._fields.0.unwrap(),
            conflict_points: self._fields.1,
            has_conflicts: self._fields.2,
            main_branch: self._fields.3,
            resource: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod entry_ref_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 Entry;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Entry = Unset;
    }
    ///State transition - sets the `entry` field to Set
    pub struct SetEntry<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEntry<St> {}
    impl<St: State> State for SetEntry<St> {
        type Entry = Set<members::entry>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `entry` field
        pub struct entry(());
    }
}

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

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

impl<S: BosStr> EntryRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> EntryRefBuilder<entry_ref_state::Empty, S> {
        EntryRefBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> EntryRefBuilder<St, S>
where
    St: entry_ref_state::State,
    St::Entry: entry_ref_state::IsUnset,
{
    /// Set the `entry` field (required)
    pub fn entry(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> EntryRefBuilder<entry_ref_state::SetEntry<St>, S> {
        self._fields.0 = Option::Some(value.into());
        EntryRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EntryRefBuilder<St, S>
where
    St: entry_ref_state::State,
    St::Entry: entry_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> EntryRef<S> {
        EntryRef {
            entry: self._fields.0.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>>) -> EntryRef<S> {
        EntryRef {
            entry: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod notebook_ref_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 Notebook;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Notebook = Unset;
    }
    ///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 Notebook = Set<members::notebook>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `notebook` field
        pub struct notebook(());
    }
}

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

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

impl<S: BosStr> NotebookRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> NotebookRefBuilder<notebook_ref_state::Empty, S> {
        NotebookRefBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> NotebookRefBuilder<St, S>
where
    St: notebook_ref_state::State,
    St::Notebook: notebook_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> NotebookRef<S> {
        NotebookRef {
            notebook: self._fields.0.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>>,
    ) -> NotebookRef<S> {
        NotebookRef {
            notebook: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}