// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.protoimsg.chat.message
//
// 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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::app_protoimsg::chat::message;
/// Width and height for layout before media loads.

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

/// Facet feature for a block quotation.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Blockquote<S: BosStr = DefaultStr> {
    #[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.

#[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 a code block. The text contains the code content.

#[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> {
    ///Programming language for syntax highlighting.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lang: Option<S>,
    #[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 CodeInline<S: BosStr = DefaultStr> {
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// External link card.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ExternalEmbed<S: BosStr = DefaultStr> {
    ///Description or summary.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///Thumbnail image for the link card.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumb: Option<BlobRef<S>>,
    ///Title of the external content.
    pub title: S,
    ///URL of the external content.
    pub uri: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Embedded images.

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

/// A single embedded image.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ImageItem<S: BosStr = DefaultStr> {
    ///Alt text for accessibility.
    pub alt: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub aspect_ratio: Option<message::AspectRatio<S>>,
    ///Image blob reference.
    pub image: BlobRef<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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Link<S: BosStr = DefaultStr> {
    pub uri: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A chat message. Lives in the sender's repo, points to a channel.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "app.protoimsg.chat.message",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Message<S: BosStr = DefaultStr> {
    ///AT-URI of the channel record this message belongs to.
    pub channel: AtUri<S>,
    ///Timestamp of message creation.
    pub created_at: Datetime,
    ///Embedded media or link card.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub embed: Option<MessageEmbed<S>>,
    ///Rich text annotations (mentions, links, tags, formatting). Extends the Bluesky facet convention with additional formatting features.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub facets: Option<Vec<message::RichTextFacet<S>>>,
    ///Structured reply reference for threading.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reply: Option<message::ReplyRef<S>>,
    ///Message text content.
    pub text: 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 MessageEmbed<S: BosStr = DefaultStr> {
    #[serde(rename = "app.protoimsg.chat.message#imageEmbed")]
    ImageEmbed(Box<message::ImageEmbed<S>>),
    #[serde(rename = "app.protoimsg.chat.message#videoEmbed")]
    VideoEmbed(Box<message::VideoEmbed<S>>),
    #[serde(rename = "app.protoimsg.chat.message#externalEmbed")]
    ExternalEmbed(Box<message::ExternalEmbed<S>>),
}

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MessageGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Message<S>,
}

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

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

/// Thread reply reference with root and parent for efficient deep thread traversal.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ReplyRef<S: BosStr = DefaultStr> {
    ///AT-URI of the direct parent message being replied to.
    pub parent: AtUri<S>,
    ///AT-URI of the root message in the thread.
    pub root: AtUri<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 RichTextFacet<S: BosStr = DefaultStr> {
    pub features: Vec<RichTextFacetFeaturesItem<S>>,
    pub index: message::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 RichTextFacetFeaturesItem<S: BosStr = DefaultStr> {
    #[serde(rename = "app.protoimsg.chat.message#mention")]
    Mention(Box<message::Mention<S>>),
    #[serde(rename = "app.protoimsg.chat.message#link")]
    Link(Box<message::Link<S>>),
    #[serde(rename = "app.protoimsg.chat.message#tag")]
    Tag(Box<message::Tag<S>>),
    #[serde(rename = "app.protoimsg.chat.message#bold")]
    Bold(Box<message::Bold<S>>),
    #[serde(rename = "app.protoimsg.chat.message#italic")]
    Italic(Box<message::Italic<S>>),
    #[serde(rename = "app.protoimsg.chat.message#strikethrough")]
    Strikethrough(Box<message::Strikethrough<S>>),
    #[serde(rename = "app.protoimsg.chat.message#codeInline")]
    CodeInline(Box<message::CodeInline<S>>),
    #[serde(rename = "app.protoimsg.chat.message#codeBlock")]
    CodeBlock(Box<message::CodeBlock<S>>),
    #[serde(rename = "app.protoimsg.chat.message#blockquote")]
    Blockquote(Box<message::Blockquote<S>>),
}

/// Facet feature for strikethrough text.

#[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 a hashtag. The text usually includes a '#' prefix, but the facet reference should not.

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

/// Embedded video.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct VideoEmbed<S: BosStr = DefaultStr> {
    ///Alt text for accessibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alt: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub aspect_ratio: Option<message::AspectRatio<S>>,
    ///Video thumbnail image.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumbnail: Option<BlobRef<S>>,
    ///Video blob reference.
    pub video: BlobRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

impl<S: BosStr> LexiconSchema for AspectRatio<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "aspectRatio"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.height;
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("height"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.width;
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("width"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Blockquote<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "blockquote"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Bold<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "bold"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ByteSlice<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "byteSlice"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    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 CodeBlock<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "codeBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.lang {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("lang"),
                    max: 50usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for CodeInline<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "codeInline"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ExternalEmbed<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "externalEmbed"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.thumb {
            {
                let size = value.blob().size;
                if size > 1000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("thumb"),
                        max: 1000000usize,
                        actual: size,
                    });
                }
            }
        }
        if let Some(ref value) = self.thumb {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/png", "image/jpeg"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("thumb"),
                        accepted: vec![
                            "image/png".to_string(), "image/jpeg".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        {
            let value = &self.title;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 300usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 300usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ImageEmbed<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "imageEmbed"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.images;
            #[allow(unused_comparisons)]
            if value.len() > 4usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("images"),
                    max: 4usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ImageItem<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "imageItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.alt;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.image;
            {
                let size = value.blob().size;
                if size > 1000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("image"),
                        max: 1000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.image;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &[
                    "image/png",
                    "image/jpeg",
                    "image/gif",
                    "image/webp",
                ];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("image"),
                        accepted: vec![
                            "image/png".to_string(), "image/jpeg".to_string(),
                            "image/gif".to_string(), "image/webp".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Italic<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "italic"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Link<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "link"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct MessageRecord;
impl XrpcResp for MessageRecord {
    const NSID: &'static str = "app.protoimsg.chat.message";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = MessageGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Message<S> {
    const NSID: &'static str = "app.protoimsg.chat.message";
    type Record = MessageRecord;
}

impl Collection for MessageRecord {
    const NSID: &'static str = "app.protoimsg.chat.message";
    type Record = MessageRecord;
}

impl<S: BosStr> LexiconSchema for Message<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 3000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 3000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let 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 Mention<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "mention"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ReplyRef<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "replyRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for RichTextFacet<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "richTextFacet"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Strikethrough<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "strikethrough"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Tag<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "tag"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    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(())
    }
}

impl<S: BosStr> LexiconSchema for VideoEmbed<S> {
    fn nsid() -> &'static str {
        "app.protoimsg.chat.message"
    }
    fn def_name() -> &'static str {
        "videoEmbed"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_protoimsg_chat_message()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.alt {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 2000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.thumbnail {
            {
                let size = value.blob().size;
                if size > 1000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("thumbnail"),
                        max: 1000000usize,
                        actual: size,
                    });
                }
            }
        }
        if let Some(ref value) = self.thumbnail {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/png", "image/jpeg"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("thumbnail"),
                        accepted: vec![
                            "image/png".to_string(), "image/jpeg".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        {
            let value = &self.video;
            {
                let size = value.blob().size;
                if size > 50000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("video"),
                        max: 50000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.video;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["video/mp4", "video/webm"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("video"),
                        accepted: vec![
                            "video/mp4".to_string(), "video/webm".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> AspectRatio<S> {
    /// Create a new builder for this type
    pub fn builder() -> AspectRatioBuilder<aspect_ratio_state::Empty, S> {
        AspectRatioBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> AspectRatioBuilder<St, S>
where
    St: aspect_ratio_state::State,
    St::Height: aspect_ratio_state::IsSet,
    St::Width: aspect_ratio_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> AspectRatio<S> {
        AspectRatio {
            height: self._fields.0.unwrap(),
            width: 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>>,
    ) -> AspectRatio<S> {
        AspectRatio {
            height: self._fields.0.unwrap(),
            width: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_protoimsg_chat_message() -> 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("app.protoimsg.chat.message"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("aspectRatio"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Width and height for layout before media loads.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("width"), SmolStr::new_static("height")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("height"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("width"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("blockquote"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for a block quotation."),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("bold"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for bold text."),
                    ),
                    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.",
                        ),
                    ),
                    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("codeBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for a code block. The text contains the code content.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("lang"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Programming language for syntax highlighting.",
                                    ),
                                ),
                                max_length: Some(50usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("codeInline"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for inline code."),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("externalEmbed"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("External link card.")),
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("title")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Description or summary."),
                                ),
                                max_length: Some(1000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("thumb"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Title of the external content."),
                                ),
                                max_length: Some(300usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URL of the external content."),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("imageEmbed"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Embedded images.")),
                    required: Some(vec![SmolStr::new_static("images")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("images"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#imageItem"),
                                    ..Default::default()
                                }),
                                max_length: Some(4usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("imageItem"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A single embedded image.")),
                    required: Some(
                        vec![SmolStr::new_static("image"), SmolStr::new_static("alt")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Alt text for accessibility."),
                                ),
                                max_length: Some(2000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#aspectRatio"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("image"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("italic"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Facet feature for italic text."),
                    ),
                    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 {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A chat message. Lives in the sender's repo, points to a channel.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("channel"), SmolStr::new_static("text"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("channel"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "AT-URI of the channel record this message belongs to.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Timestamp of message creation."),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("embed"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static("Embedded media or link card."),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("#imageEmbed"),
                                        CowStr::new_static("#videoEmbed"),
                                        CowStr::new_static("#externalEmbed")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("facets"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Rich text annotations (mentions, links, tags, formatting). Extends the Bluesky facet convention with additional formatting features.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#richTextFacet"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("reply"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#replyRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("text"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Message text content."),
                                    ),
                                    max_length: Some(3000usize),
                                    max_graphemes: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("mention"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for mention of another account. The text is usually a handle, including a '@' 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("replyRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Thread reply reference with root and parent for efficient deep thread traversal.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("root"), SmolStr::new_static("parent")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("parent"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "AT-URI of the direct parent message being replied to.",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("root"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "AT-URI of the root message in the thread.",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("richTextFacet"),
                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("#mention"), CowStr::new_static("#link"),
                                        CowStr::new_static("#tag"), CowStr::new_static("#bold"),
                                        CowStr::new_static("#italic"),
                                        CowStr::new_static("#strikethrough"),
                                        CowStr::new_static("#codeInline"),
                                        CowStr::new_static("#codeBlock"),
                                        CowStr::new_static("#blockquote")
                                    ],
                                    ..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 text."),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("tag"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Facet feature for a hashtag. The 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.insert(
                SmolStr::new_static("videoEmbed"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Embedded video.")),
                    required: Some(vec![SmolStr::new_static("video")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Alt text for accessibility."),
                                ),
                                max_length: Some(2000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#aspectRatio"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("thumbnail"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("video"),
                            LexObjectProperty::Blob(LexBlob { ..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<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 external_embed_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 Title;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Title = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type Title = Set<members::title>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Title = St::Title;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> ExternalEmbed<S> {
    /// Create a new builder for this type
    pub fn builder() -> ExternalEmbedBuilder<external_embed_state::Empty, S> {
        ExternalEmbedBuilder::builder()
    }
}

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

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

impl<St: external_embed_state::State, S: BosStr> ExternalEmbedBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: external_embed_state::State, S: BosStr> ExternalEmbedBuilder<St, S> {
    /// Set the `thumb` field (optional)
    pub fn thumb(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `thumb` field to an Option value (optional)
    pub fn maybe_thumb(mut self, value: Option<BlobRef<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> ExternalEmbedBuilder<St, S>
where
    St: external_embed_state::State,
    St::Title: external_embed_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> ExternalEmbedBuilder<external_embed_state::SetTitle<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ExternalEmbedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ExternalEmbedBuilder<St, S>
where
    St: external_embed_state::State,
    St::Uri: external_embed_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> ExternalEmbedBuilder<external_embed_state::SetUri<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ExternalEmbedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ExternalEmbedBuilder<St, S>
where
    St: external_embed_state::State,
    St::Title: external_embed_state::IsSet,
    St::Uri: external_embed_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ExternalEmbed<S> {
        ExternalEmbed {
            description: self._fields.0,
            thumb: self._fields.1,
            title: self._fields.2.unwrap(),
            uri: self._fields.3.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>>,
    ) -> ExternalEmbed<S> {
        ExternalEmbed {
            description: self._fields.0,
            thumb: self._fields.1,
            title: self._fields.2.unwrap(),
            uri: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> ImageEmbed<S> {
    /// Create a new builder for this type
    pub fn builder() -> ImageEmbedBuilder<image_embed_state::Empty, S> {
        ImageEmbedBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ImageEmbedBuilder<St, S>
where
    St: image_embed_state::State,
    St::Images: image_embed_state::IsUnset,
{
    /// Set the `images` field (required)
    pub fn images(
        mut self,
        value: impl Into<Vec<message::ImageItem<S>>>,
    ) -> ImageEmbedBuilder<image_embed_state::SetImages<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ImageEmbedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ImageEmbedBuilder<St, S>
where
    St: image_embed_state::State,
    St::Images: image_embed_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ImageEmbed<S> {
        ImageEmbed {
            images: 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>>,
    ) -> ImageEmbed<S> {
        ImageEmbed {
            images: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> ImageItem<S> {
    /// Create a new builder for this type
    pub fn builder() -> ImageItemBuilder<image_item_state::Empty, S> {
        ImageItemBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ImageItemBuilder<St, S>
where
    St: image_item_state::State,
    St::Alt: image_item_state::IsUnset,
{
    /// Set the `alt` field (required)
    pub fn alt(
        mut self,
        value: impl Into<S>,
    ) -> ImageItemBuilder<image_item_state::SetAlt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ImageItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: image_item_state::State, S: BosStr> ImageItemBuilder<St, S> {
    /// Set the `aspectRatio` field (optional)
    pub fn aspect_ratio(
        mut self,
        value: impl Into<Option<message::AspectRatio<S>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `aspectRatio` field to an Option value (optional)
    pub fn maybe_aspect_ratio(mut self, value: Option<message::AspectRatio<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> ImageItemBuilder<St, S>
where
    St: image_item_state::State,
    St::Image: image_item_state::IsUnset,
{
    /// Set the `image` field (required)
    pub fn image(
        mut self,
        value: impl Into<BlobRef<S>>,
    ) -> ImageItemBuilder<image_item_state::SetImage<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ImageItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ImageItemBuilder<St, S>
where
    St: image_item_state::State,
    St::Alt: image_item_state::IsSet,
    St::Image: image_item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ImageItem<S> {
        ImageItem {
            alt: self._fields.0.unwrap(),
            aspect_ratio: self._fields.1,
            image: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ImageItem<S> {
        ImageItem {
            alt: self._fields.0.unwrap(),
            aspect_ratio: self._fields.1,
            image: self._fields.2.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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        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<St: link_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<UriValue<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> LinkBuilder<St, S>
where
    St: link_state::State,
    St::Uri: link_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Link<S> {
        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<SmolStr, Data<S>>) -> Link<S> {
        Link {
            uri: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod message_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 Channel;
        type CreatedAt;
        type Text;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Channel = Unset;
        type CreatedAt = Unset;
        type Text = Unset;
    }
    ///State transition - sets the `channel` field to Set
    pub struct SetChannel<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetChannel<St> {}
    impl<St: State> State for SetChannel<St> {
        type Channel = Set<members::channel>;
        type CreatedAt = St::CreatedAt;
        type Text = St::Text;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type Channel = St::Channel;
        type CreatedAt = Set<members::created_at>;
        type Text = St::Text;
    }
    ///State transition - sets the `text` field to Set
    pub struct SetText<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetText<St> {}
    impl<St: State> State for SetText<St> {
        type Channel = St::Channel;
        type CreatedAt = St::CreatedAt;
        type Text = Set<members::text>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `channel` field
        pub struct channel(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `text` field
        pub struct text(());
    }
}

/// Builder for constructing an instance of this type.
pub struct MessageBuilder<St: message_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<AtUri<S>>,
        Option<Datetime>,
        Option<MessageEmbed<S>>,
        Option<Vec<message::RichTextFacet<S>>>,
        Option<message::ReplyRef<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Message<S> {
    /// Create a new builder for this type
    pub fn builder() -> MessageBuilder<message_state::Empty, S> {
        MessageBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> MessageBuilder<St, S>
where
    St: message_state::State,
    St::Channel: message_state::IsUnset,
{
    /// Set the `channel` field (required)
    pub fn channel(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> MessageBuilder<message_state::SetChannel<St>, S> {
        self._fields.0 = Option::Some(value.into());
        MessageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MessageBuilder<St, S>
where
    St: message_state::State,
    St::CreatedAt: message_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> MessageBuilder<message_state::SetCreatedAt<St>, S> {
        self._fields.1 = Option::Some(value.into());
        MessageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St: message_state::State, S: BosStr> MessageBuilder<St, S> {
    /// Set the `reply` field (optional)
    pub fn reply(mut self, value: impl Into<Option<message::ReplyRef<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `reply` field to an Option value (optional)
    pub fn maybe_reply(mut self, value: Option<message::ReplyRef<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> MessageBuilder<St, S>
where
    St: message_state::State,
    St::Text: message_state::IsUnset,
{
    /// Set the `text` field (required)
    pub fn text(
        mut self,
        value: impl Into<S>,
    ) -> MessageBuilder<message_state::SetText<St>, S> {
        self._fields.5 = Option::Some(value.into());
        MessageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> MessageBuilder<St, S>
where
    St: message_state::State,
    St::Channel: message_state::IsSet,
    St::CreatedAt: message_state::IsSet,
    St::Text: message_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Message<S> {
        Message {
            channel: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            embed: self._fields.2,
            facets: self._fields.3,
            reply: self._fields.4,
            text: self._fields.5.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>>) -> Message<S> {
        Message {
            channel: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            embed: self._fields.2,
            facets: self._fields.3,
            reply: self._fields.4,
            text: self._fields.5.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<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 MentionBuilder<St: mention_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Did<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

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

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

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

impl<S: BosStr> ReplyRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> ReplyRefBuilder<reply_ref_state::Empty, S> {
        ReplyRefBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ReplyRefBuilder<St, S>
where
    St: reply_ref_state::State,
    St::Parent: reply_ref_state::IsUnset,
{
    /// Set the `parent` field (required)
    pub fn parent(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ReplyRefBuilder<reply_ref_state::SetParent<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ReplyRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReplyRefBuilder<St, S>
where
    St: reply_ref_state::State,
    St::Root: reply_ref_state::IsUnset,
{
    /// Set the `root` field (required)
    pub fn root(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ReplyRefBuilder<reply_ref_state::SetRoot<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ReplyRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReplyRefBuilder<St, S>
where
    St: reply_ref_state::State,
    St::Parent: reply_ref_state::IsSet,
    St::Root: reply_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ReplyRef<S> {
        ReplyRef {
            parent: self._fields.0.unwrap(),
            root: 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>>) -> ReplyRef<S> {
        ReplyRef {
            parent: self._fields.0.unwrap(),
            root: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod rich_text_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 RichTextFacetBuilder<
    St: rich_text_facet_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Vec<RichTextFacetFeaturesItem<S>>>, Option<message::ByteSlice<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> RichTextFacet<S> {
    /// Create a new builder for this type
    pub fn builder() -> RichTextFacetBuilder<rich_text_facet_state::Empty, S> {
        RichTextFacetBuilder::builder()
    }
}

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

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

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

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

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

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

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

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

impl<S: BosStr> VideoEmbed<S> {
    /// Create a new builder for this type
    pub fn builder() -> VideoEmbedBuilder<video_embed_state::Empty, S> {
        VideoEmbedBuilder::builder()
    }
}

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

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

impl<St: video_embed_state::State, S: BosStr> VideoEmbedBuilder<St, S> {
    /// Set the `alt` field (optional)
    pub fn alt(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `alt` field to an Option value (optional)
    pub fn maybe_alt(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: video_embed_state::State, S: BosStr> VideoEmbedBuilder<St, S> {
    /// Set the `aspectRatio` field (optional)
    pub fn aspect_ratio(
        mut self,
        value: impl Into<Option<message::AspectRatio<S>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `aspectRatio` field to an Option value (optional)
    pub fn maybe_aspect_ratio(mut self, value: Option<message::AspectRatio<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<St, S: BosStr> VideoEmbedBuilder<St, S>
where
    St: video_embed_state::State,
    St::Video: video_embed_state::IsUnset,
{
    /// Set the `video` field (required)
    pub fn video(
        mut self,
        value: impl Into<BlobRef<S>>,
    ) -> VideoEmbedBuilder<video_embed_state::SetVideo<St>, S> {
        self._fields.3 = Option::Some(value.into());
        VideoEmbedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoEmbedBuilder<St, S>
where
    St: video_embed_state::State,
    St::Video: video_embed_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> VideoEmbed<S> {
        VideoEmbed {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            thumbnail: self._fields.2,
            video: self._fields.3.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>>,
    ) -> VideoEmbed<S> {
        VideoEmbed {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            thumbnail: self._fields.2,
            video: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}