// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.deckbelcher.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;

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

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::com_deckbelcher;
use crate::com_deckbelcher::richtext::facet;
/** Facet feature for bold text formatting.
Typically rendered as `<strong>` in HTML.*/

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Bold<'a> {}
/** 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.*/

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

/** Facet feature for a card reference.
Links to a Magic: The Gathering card.
The text is usually the card name.*/

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CardRef<'a> {
    ///Reference to the card (scryfall printing + oracle card).
    #[serde(borrow)]
    pub r#ref: com_deckbelcher::CardRef<'a>,
}

/** Facet feature for inline code.
Typically rendered as `<code>` in HTML.*/

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Code<'a> {}
/** Facet feature for code blocks.
Typically rendered as `<pre><code>` in HTML.*/

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct CodeBlock<'a> {}
/** Facet feature for italic text formatting.
Typically rendered as `<em>` in HTML.*/

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Italic<'a> {}
/** Facet feature for a URL.
The text URL may have been simplified or truncated, but the facet reference should be a complete URL.*/

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

/** Annotation of a sub-string within rich text.
Extends Bluesky's facet system to support DeckBelcher-specific features.*/

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Facet<'a> {
    #[serde(borrow)]
    pub features: Vec<FacetFeaturesItem<'a>>,
    #[serde(borrow)]
    pub index: facet::ByteSlice<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum FacetFeaturesItem<'a> {
    #[serde(rename = "com.deckbelcher.richtext.facet#mention")]
    Mention(Box<facet::Mention<'a>>),
    #[serde(rename = "com.deckbelcher.richtext.facet#link")]
    Link(Box<facet::Link<'a>>),
    #[serde(rename = "com.deckbelcher.richtext.facet#tag")]
    Tag(Box<facet::Tag<'a>>),
    #[serde(rename = "com.deckbelcher.richtext.facet#bold")]
    Bold(Box<facet::Bold<'a>>),
    #[serde(rename = "com.deckbelcher.richtext.facet#italic")]
    Italic(Box<facet::Italic<'a>>),
    #[serde(rename = "com.deckbelcher.richtext.facet#code")]
    Code(Box<facet::Code<'a>>),
    #[serde(rename = "com.deckbelcher.richtext.facet#codeBlock")]
    CodeBlock(Box<facet::CodeBlock<'a>>),
    #[serde(rename = "com.deckbelcher.richtext.facet#cardRef")]
    CardRef(Box<facet::CardRef<'a>>),
}

/** Facet feature for mention of another account.
The text is usually a handle, including an `@` prefix, but the facet reference is a DID.*/

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

/** Facet feature for a hashtag.
The text usually includes a '#' prefix, but the facet reference should not.*/

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

impl<'a> LexiconSchema for Bold<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "bold"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ByteSlice<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "byteSlice"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_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<'a> LexiconSchema for CardRef<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "cardRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Code<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "code"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for CodeBlock<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "codeBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Italic<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "italic"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Link<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "link"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Facet<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Mention<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "mention"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Tag<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.richtext.facet"
    }
    fn def_name() -> &'static str {
        "tag"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_richtext_facet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.tag;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tag"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.tag;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("tag"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

fn lexicon_doc_com_deckbelcher_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("com.deckbelcher.richtext.facet"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("bold"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for bold text formatting.\nTypically rendered as `<strong>` in HTML.",
                        ),
                    ),
                    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.\nStart index is inclusive, end index is exclusive.\nIndices are zero-indexed, counting bytes of the UTF-8 encoded text.",
                        ),
                    ),
                    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("cardRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for a card reference.\nLinks to a Magic: The Gathering card.\nThe text is usually the card name.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("ref")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.deckbelcher.defs#cardRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("code"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for inline code.\nTypically rendered as `<code>` in HTML.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("codeBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for code blocks.\nTypically rendered as `<pre><code>` in HTML.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("italic"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for italic text formatting.\nTypically rendered as `<em>` in HTML.",
                        ),
                    ),
                    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.\nThe 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 {
                                format: Some(LexStringFormat::Uri),
                                ..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.\nExtends Bluesky's facet system to support DeckBelcher-specific features.",
                        ),
                    ),
                    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("#mention"), CowStr::new_static("#link"),
                                        CowStr::new_static("#tag"), CowStr::new_static("#bold"),
                                        CowStr::new_static("#italic"), CowStr::new_static("#code"),
                                        CowStr::new_static("#codeBlock"),
                                        CowStr::new_static("#cardRef")
                                    ],
                                    ..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("mention"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for mention of another account.\nThe text is usually a handle, including an `@` prefix, but the facet reference is 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("tag"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for a hashtag.\nThe text usually includes a '#' prefix, but the facet reference should not.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("tag")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("tag"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(640usize),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetByteEnd<S> {}
    impl<S: State> State for SetByteEnd<S> {
        type ByteEnd = Set<members::byte_end>;
        type ByteStart = S::ByteStart;
    }
    ///State transition - sets the `byte_start` field to Set
    pub struct SetByteStart<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetByteStart<S> {}
    impl<S: State> State for SetByteStart<S> {
        type ByteEnd = S::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<'a, S: byte_slice_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>, Option<i64>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> ByteSliceBuilder<'a, S>
where
    S: byte_slice_state::State,
    S::ByteEnd: byte_slice_state::IsSet,
    S::ByteStart: byte_slice_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ByteSlice<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ByteSlice<'a> {
        ByteSlice {
            byte_end: self._fields.0.unwrap(),
            byte_start: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod card_ref_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Ref;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Ref = Unset;
    }
    ///State transition - sets the `ref` field to Set
    pub struct SetRef<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRef<S> {}
    impl<S: State> State for SetRef<S> {
        type Ref = Set<members::r#ref>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `ref` field
        pub struct r#ref(());
    }
}

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

impl<'a> CardRef<'a> {
    /// Create a new builder for this type
    pub fn new() -> CardRefBuilder<'a, card_ref_state::Empty> {
        CardRefBuilder::new()
    }
}

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

impl<'a, S> CardRefBuilder<'a, S>
where
    S: card_ref_state::State,
    S::Ref: card_ref_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<com_deckbelcher::CardRef<'a>>,
    ) -> CardRefBuilder<'a, card_ref_state::SetRef<S>> {
        self._fields.0 = Option::Some(value.into());
        CardRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CardRefBuilder<'a, S>
where
    S: card_ref_state::State,
    S::Ref: card_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CardRef<'a> {
        CardRef {
            r#ref: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> CardRef<'a> {
        CardRef {
            r#ref: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

impl<'a> Link<'a> {
    /// Create a new builder for this type
    pub fn new() -> LinkBuilder<'a, link_state::Empty> {
        LinkBuilder::new()
    }
}

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

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

impl<'a, S> LinkBuilder<'a, S>
where
    S: link_state::State,
    S::Uri: link_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Link<'a> {
        Link {
            uri: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Link<'a> {
        Link {
            uri: 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetFeatures<S> {}
    impl<S: State> State for SetFeatures<S> {
        type Features = Set<members::features>;
        type Index = S::Index;
    }
    ///State transition - sets the `index` field to Set
    pub struct SetIndex<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIndex<S> {}
    impl<S: State> State for SetIndex<S> {
        type Features = S::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<'a, S: facet_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<FacetFeaturesItem<'a>>>, Option<facet::ByteSlice<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> FacetBuilder<'a, S>
where
    S: facet_state::State,
    S::Features: facet_state::IsSet,
    S::Index: facet_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Facet<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Facet<'a> {
        Facet {
            features: self._fields.0.unwrap(),
            index: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDid<S> {}
    impl<S: State> State for SetDid<S> {
        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 MentionBuilder<'a, S: mention_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Did<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Mention<'a> {
    /// Create a new builder for this type
    pub fn new() -> MentionBuilder<'a, mention_state::Empty> {
        MentionBuilder::new()
    }
}

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

impl<'a, S> MentionBuilder<'a, S>
where
    S: mention_state::State,
    S::Did: mention_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> MentionBuilder<'a, mention_state::SetDid<S>> {
        self._fields.0 = Option::Some(value.into());
        MentionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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