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

#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::sh_weaver::edit::cursor;

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


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ContainerIdValue<'a> {
    #[serde(rename = "sh.weaver.edit.cursor#normalContainerId")]
    NormalContainerId(Box<cursor::NormalContainerId<'a>>),
    #[serde(rename = "sh.weaver.edit.cursor#rootContainerId")]
    RootContainerId(Box<cursor::RootContainerId<'a>>),
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CursorSide<'a> {
    ///The side of an item the cursor is on (left = -1, right = 1, middle = 0)
    pub value: i64,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Id<'a> {
    pub counter: i64,
    pub peer: i64,
}

/// An edit record for a notebook.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Cursor<'a> {
    #[serde(borrow)]
    pub container: cursor::ContainerId<'a>,
    #[serde(borrow)]
    pub id: cursor::Id<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub side: Option<cursor::CursorSide<'a>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CursorGetRecordOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Cursor<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct NormalContainerId<'a> {
    #[serde(borrow)]
    pub container_type: CowStr<'a>,
    pub counter: i64,
    pub peer: i64,
}


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

impl<'a> Cursor<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, CursorRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

impl<'a> LexiconSchema for ContainerId<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.edit.cursor"
    }
    fn def_name() -> &'static str {
        "containerId"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_edit_cursor()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for CursorSide<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.edit.cursor"
    }
    fn def_name() -> &'static str {
        "cursorSide"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_edit_cursor()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Id<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.edit.cursor"
    }
    fn def_name() -> &'static str {
        "id"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_edit_cursor()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct CursorRecord;
impl XrpcResp for CursorRecord {
    const NSID: &'static str = "sh.weaver.edit.cursor";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = CursorGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<CursorGetRecordOutput<'_>> for Cursor<'_> {
    fn from(output: CursorGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Cursor<'_> {
    const NSID: &'static str = "sh.weaver.edit.cursor";
    type Record = CursorRecord;
}

impl Collection for CursorRecord {
    const NSID: &'static str = "sh.weaver.edit.cursor";
    type Record = CursorRecord;
}

impl<'a> LexiconSchema for Cursor<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.edit.cursor"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_edit_cursor()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for NormalContainerId<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.edit.cursor"
    }
    fn def_name() -> &'static str {
        "normalContainerId"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_edit_cursor()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for RootContainerId<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.edit.cursor"
    }
    fn def_name() -> &'static str {
        "rootContainerId"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_edit_cursor()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod container_id_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 ContainerIdBuilder<'a, S: container_id_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<ContainerIdValue<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> ContainerId<'a> {
    /// Create a new builder for this type
    pub fn new() -> ContainerIdBuilder<'a, container_id_state::Empty> {
        ContainerIdBuilder::new()
    }
}

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

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

impl<'a, S> ContainerIdBuilder<'a, S>
where
    S: container_id_state::State,
    S::Value: container_id_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ContainerId<'a> {
        ContainerId {
            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>,
        >,
    ) -> ContainerId<'a> {
        ContainerId {
            value: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_edit_cursor() -> 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.cursor"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("containerId"),
                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("#normalContainerId"),
                                    CowStr::new_static("#rootContainerId")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("cursorSide"),
                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::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("id"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("peer"), SmolStr::new_static("counter")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("counter"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("peer"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("An edit record for a notebook."),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("container"), SmolStr::new_static("id")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("container"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#containerId"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("id"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#id"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("side"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#cursorSide"),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("normalContainerId"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("peer"), SmolStr::new_static("counter"),
                            SmolStr::new_static("container_type")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("container_type"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("counter"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("peer"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("rootContainerId"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("name"),
                            SmolStr::new_static("container_type")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("container_type"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod cursor_side_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 CursorSideBuilder<'a, S: cursor_side_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> CursorSide<'a> {
    /// Create a new builder for this type
    pub fn new() -> CursorSideBuilder<'a, cursor_side_state::Empty> {
        CursorSideBuilder::new()
    }
}

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

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

impl<'a, S> CursorSideBuilder<'a, S>
where
    S: cursor_side_state::State,
    S::Value: cursor_side_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CursorSide<'a> {
        CursorSide {
            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>,
        >,
    ) -> CursorSide<'a> {
        CursorSide {
            value: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod id_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 Counter;
        type Peer;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Counter = Unset;
        type Peer = Unset;
    }
    ///State transition - sets the `counter` field to Set
    pub struct SetCounter<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCounter<S> {}
    impl<S: State> State for SetCounter<S> {
        type Counter = Set<members::counter>;
        type Peer = S::Peer;
    }
    ///State transition - sets the `peer` field to Set
    pub struct SetPeer<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPeer<S> {}
    impl<S: State> State for SetPeer<S> {
        type Counter = S::Counter;
        type Peer = Set<members::peer>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `counter` field
        pub struct counter(());
        ///Marker type for the `peer` field
        pub struct peer(());
    }
}

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

impl<'a> Id<'a> {
    /// Create a new builder for this type
    pub fn new() -> IdBuilder<'a, id_state::Empty> {
        IdBuilder::new()
    }
}

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

impl<'a, S> IdBuilder<'a, S>
where
    S: id_state::State,
    S::Counter: id_state::IsUnset,
{
    /// Set the `counter` field (required)
    pub fn counter(
        mut self,
        value: impl Into<i64>,
    ) -> IdBuilder<'a, id_state::SetCounter<S>> {
        self._fields.0 = Option::Some(value.into());
        IdBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> IdBuilder<'a, S>
where
    S: id_state::State,
    S::Counter: id_state::IsSet,
    S::Peer: id_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Id<'a> {
        Id {
            counter: self._fields.0.unwrap(),
            peer: self._fields.1.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>,
        >,
    ) -> Id<'a> {
        Id {
            counter: self._fields.0.unwrap(),
            peer: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod cursor_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 Id;
        type Container;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Id = Unset;
        type Container = Unset;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetId<S> {}
    impl<S: State> State for SetId<S> {
        type Id = Set<members::id>;
        type Container = S::Container;
    }
    ///State transition - sets the `container` field to Set
    pub struct SetContainer<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContainer<S> {}
    impl<S: State> State for SetContainer<S> {
        type Id = S::Id;
        type Container = Set<members::container>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `container` field
        pub struct container(());
    }
}

/// Builder for constructing an instance of this type
pub struct CursorBuilder<'a, S: cursor_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<cursor::ContainerId<'a>>,
        Option<cursor::Id<'a>>,
        Option<cursor::CursorSide<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Cursor<'a> {
    /// Create a new builder for this type
    pub fn new() -> CursorBuilder<'a, cursor_state::Empty> {
        CursorBuilder::new()
    }
}

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

impl<'a, S> CursorBuilder<'a, S>
where
    S: cursor_state::State,
    S::Container: cursor_state::IsUnset,
{
    /// Set the `container` field (required)
    pub fn container(
        mut self,
        value: impl Into<cursor::ContainerId<'a>>,
    ) -> CursorBuilder<'a, cursor_state::SetContainer<S>> {
        self._fields.0 = Option::Some(value.into());
        CursorBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CursorBuilder<'a, S>
where
    S: cursor_state::State,
    S::Id: cursor_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<cursor::Id<'a>>,
    ) -> CursorBuilder<'a, cursor_state::SetId<S>> {
        self._fields.1 = Option::Some(value.into());
        CursorBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: cursor_state::State> CursorBuilder<'a, S> {
    /// Set the `side` field (optional)
    pub fn side(mut self, value: impl Into<Option<cursor::CursorSide<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `side` field to an Option value (optional)
    pub fn maybe_side(mut self, value: Option<cursor::CursorSide<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> CursorBuilder<'a, S>
where
    S: cursor_state::State,
    S::Id: cursor_state::IsSet,
    S::Container: cursor_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Cursor<'a> {
        Cursor {
            container: self._fields.0.unwrap(),
            id: self._fields.1.unwrap(),
            side: self._fields.2,
            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>,
        >,
    ) -> Cursor<'a> {
        Cursor {
            container: self._fields.0.unwrap(),
            id: self._fields.1.unwrap(),
            side: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

pub mod normal_container_id_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 Counter;
        type ContainerType;
        type Peer;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Counter = Unset;
        type ContainerType = Unset;
        type Peer = Unset;
    }
    ///State transition - sets the `counter` field to Set
    pub struct SetCounter<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCounter<S> {}
    impl<S: State> State for SetCounter<S> {
        type Counter = Set<members::counter>;
        type ContainerType = S::ContainerType;
        type Peer = S::Peer;
    }
    ///State transition - sets the `container_type` field to Set
    pub struct SetContainerType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContainerType<S> {}
    impl<S: State> State for SetContainerType<S> {
        type Counter = S::Counter;
        type ContainerType = Set<members::container_type>;
        type Peer = S::Peer;
    }
    ///State transition - sets the `peer` field to Set
    pub struct SetPeer<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPeer<S> {}
    impl<S: State> State for SetPeer<S> {
        type Counter = S::Counter;
        type ContainerType = S::ContainerType;
        type Peer = Set<members::peer>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `counter` field
        pub struct counter(());
        ///Marker type for the `container_type` field
        pub struct container_type(());
        ///Marker type for the `peer` field
        pub struct peer(());
    }
}

/// Builder for constructing an instance of this type
pub struct NormalContainerIdBuilder<'a, S: normal_container_id_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<i64>, Option<i64>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> NormalContainerId<'a> {
    /// Create a new builder for this type
    pub fn new() -> NormalContainerIdBuilder<'a, normal_container_id_state::Empty> {
        NormalContainerIdBuilder::new()
    }
}

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

impl<'a, S> NormalContainerIdBuilder<'a, S>
where
    S: normal_container_id_state::State,
    S::ContainerType: normal_container_id_state::IsUnset,
{
    /// Set the `container_type` field (required)
    pub fn container_type(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> NormalContainerIdBuilder<'a, normal_container_id_state::SetContainerType<S>> {
        self._fields.0 = Option::Some(value.into());
        NormalContainerIdBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> NormalContainerIdBuilder<'a, S>
where
    S: normal_container_id_state::State,
    S::Peer: normal_container_id_state::IsUnset,
{
    /// Set the `peer` field (required)
    pub fn peer(
        mut self,
        value: impl Into<i64>,
    ) -> NormalContainerIdBuilder<'a, normal_container_id_state::SetPeer<S>> {
        self._fields.2 = Option::Some(value.into());
        NormalContainerIdBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> NormalContainerIdBuilder<'a, S>
where
    S: normal_container_id_state::State,
    S::Counter: normal_container_id_state::IsSet,
    S::ContainerType: normal_container_id_state::IsSet,
    S::Peer: normal_container_id_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> NormalContainerId<'a> {
        NormalContainerId {
            container_type: self._fields.0.unwrap(),
            counter: self._fields.1.unwrap(),
            peer: self._fields.2.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>,
        >,
    ) -> NormalContainerId<'a> {
        NormalContainerId {
            container_type: self._fields.0.unwrap(),
            counter: self._fields.1.unwrap(),
            peer: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}