// @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, 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
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;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ContainerId<S: BosStr = DefaultStr> {
    pub value: ContainerIdValue<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 ContainerIdValue<S: BosStr = DefaultStr> {
    #[serde(rename = "sh.weaver.edit.cursor#normalContainerId")]
    NormalContainerId(Box<cursor::NormalContainerId<S>>),
    #[serde(rename = "sh.weaver.edit.cursor#rootContainerId")]
    RootContainerId(Box<cursor::RootContainerId<S>>),
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CursorSide<S: BosStr = DefaultStr> {
    ///The side of an item the cursor is on (left = -1, right = 1, middle = 0)
    pub value: i64,
    #[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 Id<S: BosStr = DefaultStr> {
    pub counter: i64,
    pub peer: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// An edit record for a notebook.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "sh.weaver.edit.cursor",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Cursor<S: BosStr = DefaultStr> {
    pub container: cursor::ContainerId<S>,
    pub id: cursor::Id<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub side: Option<cursor::CursorSide<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// 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<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Cursor<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct NormalContainerId<S: BosStr = DefaultStr> {
    pub container_type: S,
    pub counter: i64,
    pub peer: i64,
    #[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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RootContainerId<S: BosStr = DefaultStr> {
    pub container_type: S,
    pub name: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> Cursor<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, CursorRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

impl<S: BosStr> LexiconSchema for ContainerId<S> {
    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<S: BosStr> LexiconSchema for CursorSide<S> {
    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<S: BosStr> LexiconSchema for Id<S> {
    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<S: BosStr> = CursorGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<CursorGetRecordOutput<S>> for Cursor<S> {
    fn from(output: CursorGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Cursor<S> {
    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<S: BosStr> LexiconSchema for Cursor<S> {
    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<S: BosStr> LexiconSchema for NormalContainerId<S> {
    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<S: BosStr> LexiconSchema for RootContainerId<S> {
    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<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 ContainerIdBuilder<St: container_id_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<ContainerIdValue<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> ContainerIdBuilder<St, S>
where
    St: container_id_state::State,
    St::Value: container_id_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ContainerId<S> {
        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<SmolStr, Data<S>>,
    ) -> ContainerId<S> {
        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<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 CursorSideBuilder<St: cursor_side_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<i64>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> CursorSideBuilder<St, S>
where
    St: cursor_side_state::State,
    St::Value: cursor_side_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CursorSide<S> {
        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<SmolStr, Data<S>>,
    ) -> CursorSide<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCounter<St> {}
    impl<St: State> State for SetCounter<St> {
        type Counter = Set<members::counter>;
        type Peer = St::Peer;
    }
    ///State transition - sets the `peer` field to Set
    pub struct SetPeer<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPeer<St> {}
    impl<St: State> State for SetPeer<St> {
        type Counter = St::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<St: id_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<i64>, Option<i64>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

impl<St, S: BosStr> IdBuilder<St, S>
where
    St: id_state::State,
    St::Counter: id_state::IsSet,
    St::Peer: id_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Id<S> {
        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<SmolStr, Data<S>>) -> Id<S> {
        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 Container;
        type Id;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Container = Unset;
        type Id = Unset;
    }
    ///State transition - sets the `container` field to Set
    pub struct SetContainer<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetContainer<St> {}
    impl<St: State> State for SetContainer<St> {
        type Container = Set<members::container>;
        type Id = St::Id;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetId<St> {}
    impl<St: State> State for SetId<St> {
        type Container = St::Container;
        type Id = Set<members::id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `container` field
        pub struct container(());
        ///Marker type for the `id` field
        pub struct id(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CursorBuilder<St: cursor_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<cursor::ContainerId<S>>,
        Option<cursor::Id<S>>,
        Option<cursor::CursorSide<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

impl<St: cursor_state::State, S: BosStr> CursorBuilder<St, S> {
    /// Set the `side` field (optional)
    pub fn side(mut self, value: impl Into<Option<cursor::CursorSide<S>>>) -> 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<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> CursorBuilder<St, S>
where
    St: cursor_state::State,
    St::Container: cursor_state::IsSet,
    St::Id: cursor_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Cursor<S> {
        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<SmolStr, Data<S>>) -> Cursor<S> {
        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 ContainerType;
        type Counter;
        type Peer;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type ContainerType = Unset;
        type Counter = Unset;
        type Peer = Unset;
    }
    ///State transition - sets the `container_type` field to Set
    pub struct SetContainerType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetContainerType<St> {}
    impl<St: State> State for SetContainerType<St> {
        type ContainerType = Set<members::container_type>;
        type Counter = St::Counter;
        type Peer = St::Peer;
    }
    ///State transition - sets the `counter` field to Set
    pub struct SetCounter<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCounter<St> {}
    impl<St: State> State for SetCounter<St> {
        type ContainerType = St::ContainerType;
        type Counter = Set<members::counter>;
        type Peer = St::Peer;
    }
    ///State transition - sets the `peer` field to Set
    pub struct SetPeer<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPeer<St> {}
    impl<St: State> State for SetPeer<St> {
        type ContainerType = St::ContainerType;
        type Counter = St::Counter;
        type Peer = Set<members::peer>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `container_type` field
        pub struct container_type(());
        ///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 NormalContainerIdBuilder<
    St: normal_container_id_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<i64>, Option<i64>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

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

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