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

//! Generated bindings for the `com.deckbelcher.richtext` Lexicon namespace/module.
pub mod facet;


#[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::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::com_deckbelcher::richtext::facet::Facet;
use crate::com_deckbelcher::richtext;
/// An unordered (bullet) list.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct BulletListBlock<S: BosStr = DefaultStr> {
    ///The list items.
    pub items: Vec<richtext::ListItem<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A code block with optional language hint.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CodeBlock<S: BosStr = DefaultStr> {
    ///Optional language identifier for syntax highlighting.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub language: Option<S>,
    ///The code content (plain text, no facets).
    pub text: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A multi-block rich text document.
/// Used for primers and other long-form content.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Document<S: BosStr = DefaultStr> {
    ///Array of blocks (paragraphs, headings, etc).
    pub content: Vec<DocumentContentItem<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 DocumentContentItem<S: BosStr = DefaultStr> {
    #[serde(rename = "com.deckbelcher.richtext#paragraphBlock")]
    ParagraphBlock(Box<richtext::ParagraphBlock<S>>),
    #[serde(rename = "com.deckbelcher.richtext#headingBlock")]
    HeadingBlock(Box<richtext::HeadingBlock<S>>),
    #[serde(rename = "com.deckbelcher.richtext#codeBlock")]
    CodeBlock(Box<richtext::CodeBlock<S>>),
    #[serde(rename = "com.deckbelcher.richtext#bulletListBlock")]
    BulletListBlock(Box<richtext::BulletListBlock<S>>),
    #[serde(rename = "com.deckbelcher.richtext#orderedListBlock")]
    OrderedListBlock(Box<richtext::OrderedListBlock<S>>),
    #[serde(rename = "com.deckbelcher.richtext#horizontalRuleBlock")]
    HorizontalRuleBlock(Box<richtext::HorizontalRuleBlock<S>>),
}

/// A heading block with level, text, and optional facets.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct HeadingBlock<S: BosStr = DefaultStr> {
    ///Annotations of text (formatting, mentions, links, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub facets: Option<Vec<Facet<S>>>,
    ///Heading level (1-6).
    pub level: i64,
    ///The plain text content (no markdown symbols).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A horizontal rule (thematic break).

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

/// A single list item with text, optional facets, and optional sublist.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ListItem<S: BosStr = DefaultStr> {
    ///Annotations of text (formatting, mentions, links, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub facets: Option<Vec<Facet<S>>>,
    ///Optional nested sublist (bullet or ordered).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sublist: Option<ListItemSublist<S>>,
    ///The plain text content (no markdown symbols).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<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 ListItemSublist<S: BosStr = DefaultStr> {
    #[serde(rename = "com.deckbelcher.richtext#bulletListBlock")]
    BulletListBlock(Box<richtext::BulletListBlock<S>>),
    #[serde(rename = "com.deckbelcher.richtext#orderedListBlock")]
    OrderedListBlock(Box<richtext::OrderedListBlock<S>>),
}

/// A single paragraph of rich text with optional facet annotations.
/// Used for descriptions and other short formatted text.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Richtext<S: BosStr = DefaultStr> {
    ///Annotations of text (mentions, URLs, hashtags, formatting, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub facets: Option<Vec<Facet<S>>>,
    ///The plain text content (no markdown symbols).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// An ordered (numbered) list.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct OrderedListBlock<S: BosStr = DefaultStr> {
    ///The list items.
    pub items: Vec<richtext::ListItem<S>>,
    ///Starting number (default 1).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub start: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A paragraph block with text and optional facets.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ParagraphBlock<S: BosStr = DefaultStr> {
    ///Annotations of text (formatting, mentions, links, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub facets: Option<Vec<Facet<S>>>,
    ///The plain text content (no markdown symbols).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub text: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for BulletListBlock<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "bulletListBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for CodeBlock<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "codeBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.language {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("language"),
                    max: 50usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 100000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Document<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "document"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for HeadingBlock<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "headingBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.level;
            if *value > 6i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("level"),
                    max: 6i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.level;
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("level"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.text {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.text {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("text"),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for HorizontalRuleBlock<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "horizontalRuleBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ListItem<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "listItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.text {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 100000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.text {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 10000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("text"),
                        max: 10000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Richtext<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.text {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 500000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.text {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 50000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("text"),
                        max: 50000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for OrderedListBlock<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "orderedListBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ParagraphBlock<S> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext"
    }
    fn def_name() -> &'static str {
        "paragraphBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.text {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 500000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.text {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 50000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("text"),
                        max: 50000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> BulletListBlock<S> {
    /// Create a new builder for this type
    pub fn builder() -> BulletListBlockBuilder<bullet_list_block_state::Empty, S> {
        BulletListBlockBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> BulletListBlockBuilder<St, S>
where
    St: bullet_list_block_state::State,
    St::Items: bullet_list_block_state::IsUnset,
{
    /// Set the `items` field (required)
    pub fn items(
        mut self,
        value: impl Into<Vec<richtext::ListItem<S>>>,
    ) -> BulletListBlockBuilder<bullet_list_block_state::SetItems<St>, S> {
        self._fields.0 = Option::Some(value.into());
        BulletListBlockBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BulletListBlockBuilder<St, S>
where
    St: bullet_list_block_state::State,
    St::Items: bullet_list_block_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> BulletListBlock<S> {
        BulletListBlock {
            items: 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>>,
    ) -> BulletListBlock<S> {
        BulletListBlock {
            items: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_deckbelcher_richtext() -> 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("com.deckbelcher.richtext"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("bulletListBlock"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("An unordered (bullet) list.")),
                    required: Some(vec![SmolStr::new_static("items")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("items"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(CowStr::new_static("The list items.")),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#listItem"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("codeBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A code block with optional language hint."),
                    ),
                    required: Some(vec![SmolStr::new_static("text")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("language"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional language identifier for syntax highlighting.",
                                    ),
                                ),
                                max_length: Some(50usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The code content (plain text, no facets).",
                                    ),
                                ),
                                max_length: Some(100000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("document"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A multi-block rich text document.\nUsed for primers and other long-form content.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("content")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("content"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Array of blocks (paragraphs, headings, etc).",
                                    ),
                                ),
                                items: LexArrayItem::Union(LexRefUnion {
                                    refs: vec![
                                        CowStr::new_static("#paragraphBlock"),
                                        CowStr::new_static("#headingBlock"),
                                        CowStr::new_static("#codeBlock"),
                                        CowStr::new_static("#bulletListBlock"),
                                        CowStr::new_static("#orderedListBlock"),
                                        CowStr::new_static("#horizontalRuleBlock")
                                    ],
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("headingBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A heading block with level, text, and optional facets.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("level")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("facets"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Annotations of text (formatting, mentions, links, etc).",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.deckbelcher.richtext.facet"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("level"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                maximum: Some(6i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The plain text content (no markdown symbols).",
                                    ),
                                ),
                                max_length: Some(10000usize),
                                max_graphemes: Some(1000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("horizontalRuleBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A horizontal rule (thematic break)."),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("listItem"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A single list item with text, optional facets, and optional sublist.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("facets"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Annotations of text (formatting, mentions, links, etc).",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.deckbelcher.richtext.facet"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("sublist"),
                            LexObjectProperty::Union(LexRefUnion {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional nested sublist (bullet or ordered).",
                                    ),
                                ),
                                refs: vec![
                                    CowStr::new_static("#bulletListBlock"),
                                    CowStr::new_static("#orderedListBlock")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The plain text content (no markdown symbols).",
                                    ),
                                ),
                                max_length: Some(100000usize),
                                max_graphemes: Some(10000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A single paragraph of rich text with optional facet annotations.\nUsed for descriptions and other short formatted text.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("facets"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Annotations of text (mentions, URLs, hashtags, formatting, etc).",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.deckbelcher.richtext.facet"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The plain text content (no markdown symbols).",
                                    ),
                                ),
                                max_length: Some(500000usize),
                                max_graphemes: Some(50000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("orderedListBlock"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("An ordered (numbered) list.")),
                    required: Some(vec![SmolStr::new_static("items")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("items"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(CowStr::new_static("The list items.")),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#listItem"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("start"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("paragraphBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A paragraph block with text and optional facets.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("facets"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Annotations of text (formatting, mentions, links, etc).",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.deckbelcher.richtext.facet"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The plain text content (no markdown symbols).",
                                    ),
                                ),
                                max_length: Some(500000usize),
                                max_graphemes: Some(50000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> Document<S> {
    /// Create a new builder for this type
    pub fn builder() -> DocumentBuilder<document_state::Empty, S> {
        DocumentBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> DocumentBuilder<St, S>
where
    St: document_state::State,
    St::Content: document_state::IsUnset,
{
    /// Set the `content` field (required)
    pub fn content(
        mut self,
        value: impl Into<Vec<DocumentContentItem<S>>>,
    ) -> DocumentBuilder<document_state::SetContent<St>, S> {
        self._fields.0 = Option::Some(value.into());
        DocumentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DocumentBuilder<St, S>
where
    St: document_state::State,
    St::Content: document_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Document<S> {
        Document {
            content: 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>>) -> Document<S> {
        Document {
            content: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> HeadingBlock<S> {
    /// Create a new builder for this type
    pub fn builder() -> HeadingBlockBuilder<heading_block_state::Empty, S> {
        HeadingBlockBuilder::builder()
    }
}

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

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

impl<St: heading_block_state::State, S: BosStr> HeadingBlockBuilder<St, S> {
    /// Set the `facets` field (optional)
    pub fn facets(mut self, value: impl Into<Option<Vec<Facet<S>>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `facets` field to an Option value (optional)
    pub fn maybe_facets(mut self, value: Option<Vec<Facet<S>>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: heading_block_state::State, S: BosStr> HeadingBlockBuilder<St, S> {
    /// Set the `text` field (optional)
    pub fn text(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `text` field to an Option value (optional)
    pub fn maybe_text(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> HeadingBlockBuilder<St, S>
where
    St: heading_block_state::State,
    St::Level: heading_block_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> HeadingBlock<S> {
        HeadingBlock {
            facets: self._fields.0,
            level: self._fields.1.unwrap(),
            text: 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>>,
    ) -> HeadingBlock<S> {
        HeadingBlock {
            facets: self._fields.0,
            level: self._fields.1.unwrap(),
            text: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

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

/// Builder for constructing an instance of this type.
pub struct OrderedListBlockBuilder<
    St: ordered_list_block_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Vec<richtext::ListItem<S>>>, Option<i64>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> OrderedListBlock<S> {
    /// Create a new builder for this type
    pub fn builder() -> OrderedListBlockBuilder<ordered_list_block_state::Empty, S> {
        OrderedListBlockBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> OrderedListBlockBuilder<St, S>
where
    St: ordered_list_block_state::State,
    St::Items: ordered_list_block_state::IsUnset,
{
    /// Set the `items` field (required)
    pub fn items(
        mut self,
        value: impl Into<Vec<richtext::ListItem<S>>>,
    ) -> OrderedListBlockBuilder<ordered_list_block_state::SetItems<St>, S> {
        self._fields.0 = Option::Some(value.into());
        OrderedListBlockBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: ordered_list_block_state::State, S: BosStr> OrderedListBlockBuilder<St, S> {
    /// Set the `start` field (optional)
    pub fn start(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `start` field to an Option value (optional)
    pub fn maybe_start(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> OrderedListBlockBuilder<St, S>
where
    St: ordered_list_block_state::State,
    St::Items: ordered_list_block_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> OrderedListBlock<S> {
        OrderedListBlock {
            items: self._fields.0.unwrap(),
            start: self._fields.1,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> OrderedListBlock<S> {
        OrderedListBlock {
            items: self._fields.0.unwrap(),
            start: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}