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

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;

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

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::sh_weaver::actor::ProfileViewBasic;
use crate::sh_weaver::edit;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DocRef<'a> {
    #[serde(borrow)]
    pub value: DocRefValue<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum DocRefValue<'a> {
    #[serde(rename = "sh.weaver.edit.defs#notebookRef")]
    NotebookRef(Box<edit::NotebookRef<'a>>),
    #[serde(rename = "sh.weaver.edit.defs#entryRef")]
    EntryRef(Box<edit::EntryRef<'a>>),
    #[serde(rename = "sh.weaver.edit.defs#draftRef")]
    DraftRef(Box<edit::DraftRef<'a>>),
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct DraftRef<'a> {
    #[serde(borrow)]
    pub draft_key: CowStr<'a>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EditBranchView<'a> {
    #[serde(borrow)]
    pub author: ProfileViewBasic<'a>,
    ///Common ancestor if this is a fork
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub diverges_from: Option<StrongRef<'a>>,
    #[serde(borrow)]
    pub head: StrongRef<'a>,
    #[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")]
    #[serde(borrow)]
    pub root: Option<StrongRef<'a>>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EditHistoryEntry<'a> {
    #[serde(borrow)]
    pub author: ProfileViewBasic<'a>,
    #[serde(borrow)]
    pub cid: Cid<'a>,
    pub created_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_inline_diff: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub prev_ref: Option<StrongRef<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub root_ref: Option<StrongRef<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub snapshot_cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub r#type: EditHistoryEntryType<'a>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EditHistoryEntryType<'a> {
    Root,
    Diff,
    Other(CowStr<'a>),
}

impl<'a> EditHistoryEntryType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Root => "root",
            Self::Diff => "diff",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for EditHistoryEntryType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "root" => Self::Root,
            "diff" => Self::Diff,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for EditHistoryEntryType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "root" => Self::Root,
            "diff" => Self::Diff,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for EditHistoryEntryType<'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 EditHistoryEntryType<'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<'a> Default for EditHistoryEntryType<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EditTreeView<'a> {
    #[serde(borrow)]
    pub branches: Vec<edit::EditBranchView<'a>>,
    ///Diffs where branches diverge
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub conflict_points: Option<Vec<StrongRef<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub has_conflicts: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub main_branch: Option<edit::EditBranchView<'a>>,
    #[serde(borrow)]
    pub resource: StrongRef<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EntryRef<'a> {
    #[serde(borrow)]
    pub entry: StrongRef<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct NotebookRef<'a> {
    #[serde(borrow)]
    pub notebook: StrongRef<'a>,
}

impl<'a> LexiconSchema for DocRef<'a> {
    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<'a> LexiconSchema for DraftRef<'a> {
    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<'a> LexiconSchema for EditBranchView<'a> {
    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<'a> LexiconSchema for EditHistoryEntry<'a> {
    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<'a> LexiconSchema for EditTreeView<'a> {
    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<'a> LexiconSchema for EntryRef<'a> {
    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<'a> LexiconSchema for NotebookRef<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetValue<S> {}
    impl<S: State> State for SetValue<S> {
        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<'a, S: doc_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<DocRefValue<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> DocRefBuilder<'a, S>
where
    S: doc_ref_state::State,
    S::Value: doc_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> DocRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> DocRef<'a> {
        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 Length;
        type Author;
        type LastUpdated;
        type Head;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Length = Unset;
        type Author = Unset;
        type LastUpdated = Unset;
        type Head = Unset;
    }
    ///State transition - sets the `length` field to Set
    pub struct SetLength<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLength<S> {}
    impl<S: State> State for SetLength<S> {
        type Length = Set<members::length>;
        type Author = S::Author;
        type LastUpdated = S::LastUpdated;
        type Head = S::Head;
    }
    ///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 Length = S::Length;
        type Author = Set<members::author>;
        type LastUpdated = S::LastUpdated;
        type Head = S::Head;
    }
    ///State transition - sets the `last_updated` field to Set
    pub struct SetLastUpdated<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLastUpdated<S> {}
    impl<S: State> State for SetLastUpdated<S> {
        type Length = S::Length;
        type Author = S::Author;
        type LastUpdated = Set<members::last_updated>;
        type Head = S::Head;
    }
    ///State transition - sets the `head` field to Set
    pub struct SetHead<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetHead<S> {}
    impl<S: State> State for SetHead<S> {
        type Length = S::Length;
        type Author = S::Author;
        type LastUpdated = S::LastUpdated;
        type Head = Set<members::head>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `length` field
        pub struct length(());
        ///Marker type for the `author` field
        pub struct author(());
        ///Marker type for the `last_updated` field
        pub struct last_updated(());
        ///Marker type for the `head` field
        pub struct head(());
    }
}

/// Builder for constructing an instance of this type
pub struct EditBranchViewBuilder<'a, S: edit_branch_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<ProfileViewBasic<'a>>,
        Option<StrongRef<'a>>,
        Option<StrongRef<'a>>,
        Option<bool>,
        Option<Datetime>,
        Option<i64>,
        Option<StrongRef<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: edit_branch_view_state::State> EditBranchViewBuilder<'a, S> {
    /// Set the `divergesFrom` field (optional)
    pub fn diverges_from(mut self, value: impl Into<Option<StrongRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<'a, S: edit_branch_view_state::State> EditBranchViewBuilder<'a, 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<'a, S> EditBranchViewBuilder<'a, S>
where
    S: edit_branch_view_state::State,
    S::LastUpdated: edit_branch_view_state::IsUnset,
{
    /// Set the `lastUpdated` field (required)
    pub fn last_updated(
        mut self,
        value: impl Into<Datetime>,
    ) -> EditBranchViewBuilder<'a, edit_branch_view_state::SetLastUpdated<S>> {
        self._fields.4 = Option::Some(value.into());
        EditBranchViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

impl<'a, S> EditBranchViewBuilder<'a, S>
where
    S: edit_branch_view_state::State,
    S::Length: edit_branch_view_state::IsSet,
    S::Author: edit_branch_view_state::IsSet,
    S::LastUpdated: edit_branch_view_state::IsSet,
    S::Head: edit_branch_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> EditBranchView<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> EditBranchView<'a> {
        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 Cid;
        type Uri;
        type CreatedAt;
        type Type;
        type Author;
    }
    /// 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 CreatedAt = Unset;
        type Type = Unset;
        type Author = 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 CreatedAt = S::CreatedAt;
        type Type = S::Type;
        type Author = S::Author;
    }
    ///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 CreatedAt = S::CreatedAt;
        type Type = S::Type;
        type Author = S::Author;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type CreatedAt = Set<members::created_at>;
        type Type = S::Type;
        type Author = S::Author;
    }
    ///State transition - sets the `type` field to Set
    pub struct SetType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetType<S> {}
    impl<S: State> State for SetType<S> {
        type Cid = S::Cid;
        type Uri = S::Uri;
        type CreatedAt = S::CreatedAt;
        type Type = Set<members::r#type>;
        type Author = S::Author;
    }
    ///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 CreatedAt = S::CreatedAt;
        type Type = S::Type;
        type Author = Set<members::author>;
    }
    /// 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 `created_at` field
        pub struct created_at(());
        ///Marker type for the `type` field
        pub struct r#type(());
        ///Marker type for the `author` field
        pub struct author(());
    }
}

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

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

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

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

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

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

impl<'a, S: edit_history_entry_state::State> EditHistoryEntryBuilder<'a, 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<'a, S: edit_history_entry_state::State> EditHistoryEntryBuilder<'a, S> {
    /// Set the `prevRef` field (optional)
    pub fn prev_ref(mut self, value: impl Into<Option<StrongRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: edit_history_entry_state::State> EditHistoryEntryBuilder<'a, S> {
    /// Set the `rootRef` field (optional)
    pub fn root_ref(mut self, value: impl Into<Option<StrongRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

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

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

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

impl<'a, S> EditHistoryEntryBuilder<'a, S>
where
    S: edit_history_entry_state::State,
    S::Cid: edit_history_entry_state::IsSet,
    S::Uri: edit_history_entry_state::IsSet,
    S::CreatedAt: edit_history_entry_state::IsSet,
    S::Type: edit_history_entry_state::IsSet,
    S::Author: edit_history_entry_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> EditHistoryEntry<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> EditHistoryEntry<'a> {
        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 Resource;
        type Branches;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Resource = Unset;
        type Branches = Unset;
    }
    ///State transition - sets the `resource` field to Set
    pub struct SetResource<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetResource<S> {}
    impl<S: State> State for SetResource<S> {
        type Resource = Set<members::resource>;
        type Branches = S::Branches;
    }
    ///State transition - sets the `branches` field to Set
    pub struct SetBranches<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBranches<S> {}
    impl<S: State> State for SetBranches<S> {
        type Resource = S::Resource;
        type Branches = Set<members::branches>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `resource` field
        pub struct resource(());
        ///Marker type for the `branches` field
        pub struct branches(());
    }
}

/// Builder for constructing an instance of this type
pub struct EditTreeViewBuilder<'a, S: edit_tree_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<edit::EditBranchView<'a>>>,
        Option<Vec<StrongRef<'a>>>,
        Option<bool>,
        Option<edit::EditBranchView<'a>>,
        Option<StrongRef<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: edit_tree_view_state::State> EditTreeViewBuilder<'a, S> {
    /// Set the `conflictPoints` field (optional)
    pub fn conflict_points(
        mut self,
        value: impl Into<Option<Vec<StrongRef<'a>>>>,
    ) -> 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<'a>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: edit_tree_view_state::State> EditTreeViewBuilder<'a, 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<'a, S: edit_tree_view_state::State> EditTreeViewBuilder<'a, S> {
    /// Set the `mainBranch` field (optional)
    pub fn main_branch(
        mut self,
        value: impl Into<Option<edit::EditBranchView<'a>>>,
    ) -> 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<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<'a, S> EditTreeViewBuilder<'a, S>
where
    S: edit_tree_view_state::State,
    S::Resource: edit_tree_view_state::IsSet,
    S::Branches: edit_tree_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> EditTreeView<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> EditTreeView<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEntry<S> {}
    impl<S: State> State for SetEntry<S> {
        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<'a, S: entry_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<StrongRef<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> EntryRefBuilder<'a, S>
where
    S: entry_ref_state::State,
    S::Entry: entry_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> EntryRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> EntryRef<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNotebook<S> {}
    impl<S: State> State for SetNotebook<S> {
        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<'a, S: notebook_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<StrongRef<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> NotebookRefBuilder<'a, S>
where
    S: notebook_ref_state::State,
    S::Notebook: notebook_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> NotebookRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> NotebookRef<'a> {
        NotebookRef {
            notebook: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}