// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: pub.leaflet.richtext.facet
//
// 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::string::{Did, UriValue};
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::pub_leaflet::theme::color::Rgb;
use crate::pub_leaflet::theme::color::Rgba;
use crate::pub_leaflet::richtext::facet;
/// Facet feature for mentioning an AT URI.

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

/// Facet feature for bold text

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

/// Specifies the sub-string range a facet feature applies to. Start index is inclusive, end index is exclusive. Indices are zero-indexed, counting bytes of the UTF-8 encoded text. NOTE: some languages, like Javascript, use UTF-16 or Unicode codepoints for string slice indexing; in these languages, convert to byte arrays before working with facets.

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

/// Facet feature for inline code.

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

/// Facet feature for mentioning a did.

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

/// Facet feature for a footnote reference

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

/// Facet feature for highlighted text.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Highlight<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub color: Option<HighlightColor<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 HighlightColor<S: BosStr = DefaultStr> {
    #[serde(rename = "pub.leaflet.theme.color#rgba")]
    ColorRgba(Box<Rgba<S>>),
    #[serde(rename = "pub.leaflet.theme.color#rgb")]
    ColorRgb(Box<Rgb<S>>),
}

/// Facet feature for an identifier. Used for linking to a segment

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

/// Facet feature for italic text

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

/// Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL.

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

/// Annotation of a sub-string within rich text.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Facet<S: BosStr = DefaultStr> {
    pub features: Vec<FacetFeaturesItem<S>>,
    pub index: facet::ByteSlice<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 FacetFeaturesItem<S: BosStr = DefaultStr> {
    #[serde(rename = "pub.leaflet.richtext.facet#link")]
    Link(Box<facet::Link<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#didMention")]
    DidMention(Box<facet::DidMention<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#atMention")]
    AtMention(Box<facet::AtMention<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#code")]
    Code(Box<facet::Code<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#highlight")]
    Highlight(Box<facet::Highlight<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#underline")]
    Underline(Box<facet::Underline<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#strikethrough")]
    Strikethrough(Box<facet::Strikethrough<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#id")]
    Id(Box<facet::Id<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#bold")]
    Bold(Box<facet::Bold<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#italic")]
    Italic(Box<facet::Italic<S>>),
    #[serde(rename = "pub.leaflet.richtext.facet#footnote")]
    Footnote(Box<facet::Footnote<S>>),
}

/// Facet feature for strikethrough markup

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

/// Facet feature for underline markup

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

impl<S: BosStr> LexiconSchema for AtMention<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "atMention"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Bold<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "bold"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ByteSlice<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "byteSlice"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.byte_end;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("byte_end"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.byte_start;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("byte_start"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Code<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "code"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for DidMention<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "didMention"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Footnote<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "footnote"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Highlight<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "highlight"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Id<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "id"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Italic<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "italic"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Link<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "link"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Facet<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Strikethrough<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "strikethrough"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Underline<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.richtext.facet"
    }
    fn def_name() -> &'static str {
        "underline"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> AtMention<S> {
    /// Create a new builder for this type
    pub fn builder() -> AtMentionBuilder<at_mention_state::Empty, S> {
        AtMentionBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> AtMentionBuilder<St, S>
where
    St: at_mention_state::State,
    St::AtUri: at_mention_state::IsUnset,
{
    /// Set the `atURI` field (required)
    pub fn at_uri(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> AtMentionBuilder<at_mention_state::SetAtUri<St>, S> {
        self._fields.0 = Option::Some(value.into());
        AtMentionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: at_mention_state::State, S: BosStr> AtMentionBuilder<St, S> {
    /// Set the `href` field (optional)
    pub fn href(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `href` field to an Option value (optional)
    pub fn maybe_href(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> AtMentionBuilder<St, S>
where
    St: at_mention_state::State,
    St::AtUri: at_mention_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> AtMention<S> {
        AtMention {
            at_uri: self._fields.0.unwrap(),
            href: 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>>,
    ) -> AtMention<S> {
        AtMention {
            at_uri: self._fields.0.unwrap(),
            href: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_pub_leaflet_richtext_facet() -> 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("pub.leaflet.richtext.facet"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("atMention"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for mentioning an AT URI."),
                    ),
                    required: Some(vec![SmolStr::new_static("atURI")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("atURI"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("href"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("bold"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Facet feature for bold text")),
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("byteSlice"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Specifies the sub-string range a facet feature applies to. Start index is inclusive, end index is exclusive. Indices are zero-indexed, counting bytes of the UTF-8 encoded text. NOTE: some languages, like Javascript, use UTF-16 or Unicode codepoints for string slice indexing; in these languages, convert to byte arrays before working with facets.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("byteStart"),
                            SmolStr::new_static("byteEnd")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("byteEnd"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("byteStart"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("code"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for inline code."),
                    ),
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("didMention"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for mentioning a did."),
                    ),
                    required: Some(vec![SmolStr::new_static("did")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("footnote"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for a footnote reference"),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("footnoteId"),
                            SmolStr::new_static("contentPlaintext")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("contentFacets"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#main"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("contentPlaintext"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("footnoteId"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("highlight"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for highlighted text."),
                    ),
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("color"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("pub.leaflet.theme.color#rgba"),
                                    CowStr::new_static("pub.leaflet.theme.color#rgb")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("id"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for an identifier. Used for linking to a segment",
                        ),
                    ),
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("italic"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for italic text"),
                    ),
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("link"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for a URL. The text URL may have been simplified or truncated, but the facet reference should be a complete URL.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("uri")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Annotation of a sub-string within rich text.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("index"), SmolStr::new_static("features")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("features"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Union(LexRefUnion {
                                    refs: vec![
                                        CowStr::new_static("#link"),
                                        CowStr::new_static("#didMention"),
                                        CowStr::new_static("#atMention"),
                                        CowStr::new_static("#code"),
                                        CowStr::new_static("#highlight"),
                                        CowStr::new_static("#underline"),
                                        CowStr::new_static("#strikethrough"),
                                        CowStr::new_static("#id"), CowStr::new_static("#bold"),
                                        CowStr::new_static("#italic"),
                                        CowStr::new_static("#footnote")
                                    ],
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("index"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#byteSlice"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("strikethrough"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for strikethrough markup"),
                    ),
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("underline"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for underline markup"),
                    ),
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> ByteSlice<S> {
    /// Create a new builder for this type
    pub fn builder() -> ByteSliceBuilder<byte_slice_state::Empty, S> {
        ByteSliceBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> ByteSliceBuilder<St, S>
where
    St: byte_slice_state::State,
    St::ByteStart: byte_slice_state::IsUnset,
{
    /// Set the `byteStart` field (required)
    pub fn byte_start(
        mut self,
        value: impl Into<i64>,
    ) -> ByteSliceBuilder<byte_slice_state::SetByteStart<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ByteSliceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ByteSliceBuilder<St, S>
where
    St: byte_slice_state::State,
    St::ByteEnd: byte_slice_state::IsSet,
    St::ByteStart: byte_slice_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ByteSlice<S> {
        ByteSlice {
            byte_end: self._fields.0.unwrap(),
            byte_start: 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>>,
    ) -> ByteSlice<S> {
        ByteSlice {
            byte_end: self._fields.0.unwrap(),
            byte_start: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> DidMention<S> {
    /// Create a new builder for this type
    pub fn builder() -> DidMentionBuilder<did_mention_state::Empty, S> {
        DidMentionBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> DidMentionBuilder<St, S>
where
    St: did_mention_state::State,
    St::Did: did_mention_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> DidMentionBuilder<did_mention_state::SetDid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        DidMentionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DidMentionBuilder<St, S>
where
    St: did_mention_state::State,
    St::Did: did_mention_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> DidMention<S> {
        DidMention {
            did: 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>>,
    ) -> DidMention<S> {
        DidMention {
            did: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> Facet<S> {
    /// Create a new builder for this type
    pub fn builder() -> FacetBuilder<facet_state::Empty, S> {
        FacetBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> FacetBuilder<St, S>
where
    St: facet_state::State,
    St::Features: facet_state::IsUnset,
{
    /// Set the `features` field (required)
    pub fn features(
        mut self,
        value: impl Into<Vec<FacetFeaturesItem<S>>>,
    ) -> FacetBuilder<facet_state::SetFeatures<St>, S> {
        self._fields.0 = Option::Some(value.into());
        FacetBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FacetBuilder<St, S>
where
    St: facet_state::State,
    St::Index: facet_state::IsUnset,
{
    /// Set the `index` field (required)
    pub fn index(
        mut self,
        value: impl Into<facet::ByteSlice<S>>,
    ) -> FacetBuilder<facet_state::SetIndex<St>, S> {
        self._fields.1 = Option::Some(value.into());
        FacetBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> FacetBuilder<St, S>
where
    St: facet_state::State,
    St::Features: facet_state::IsSet,
    St::Index: facet_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Facet<S> {
        Facet {
            features: self._fields.0.unwrap(),
            index: 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>>) -> Facet<S> {
        Facet {
            features: self._fields.0.unwrap(),
            index: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}