// @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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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.

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

/// Facet feature for a block quotation.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Blockquote<'a> {}
/// Facet feature for bold text.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Bold<'a> {}
/// Specifies the sub-string range a facet feature applies to. Start index is inclusive, end index is exclusive. Indices are zero-indexed, counting bytes of the UTF-8 encoded text.

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

/// Facet feature for a code block. The text contains the code content.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct CodeBlock<'a> {
    ///Programming language for syntax highlighting.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub lang: Option<CowStr<'a>>,
}

/// Facet feature for inline code.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct CodeInline<'a> {}
/// External link card.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ExternalEmbed<'a> {
    ///Description or summary.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    ///Thumbnail image for the link card.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub thumb: Option<BlobRef<'a>>,
    ///Title of the external content.
    #[serde(borrow)]
    pub title: CowStr<'a>,
    ///URL of the external content.
    #[serde(borrow)]
    pub uri: UriValue<'a>,
}

/// Embedded images.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ImageEmbed<'a> {
    #[serde(borrow)]
    pub images: Vec<message::ImageItem<'a>>,
}

/// A single embedded image.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ImageItem<'a> {
    ///Alt text for accessibility.
    #[serde(borrow)]
    pub alt: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub aspect_ratio: Option<message::AspectRatio<'a>>,
    ///Image blob reference.
    #[serde(borrow)]
    pub image: BlobRef<'a>,
}

/// Facet feature for italic text.

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

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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Message<'a> {
    ///AT-URI of the channel record this message belongs to.
    #[serde(borrow)]
    pub channel: AtUri<'a>,
    ///Timestamp of message creation.
    pub created_at: Datetime,
    ///Embedded media or link card.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub embed: Option<MessageEmbed<'a>>,
    ///Rich text annotations (mentions, links, tags, formatting). Extends the Bluesky facet convention with additional formatting features.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub facets: Option<Vec<message::RichTextFacet<'a>>>,
    ///Structured reply reference for threading.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub reply: Option<message::ReplyRef<'a>>,
    ///Message text content.
    #[serde(borrow)]
    pub text: CowStr<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum MessageEmbed<'a> {
    #[serde(rename = "app.protoimsg.chat.message#imageEmbed")]
    ImageEmbed(Box<message::ImageEmbed<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#videoEmbed")]
    VideoEmbed(Box<message::VideoEmbed<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#externalEmbed")]
    ExternalEmbed(Box<message::ExternalEmbed<'a>>),
}

/// 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<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Message<'a>,
}

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

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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ReplyRef<'a> {
    ///AT-URI of the direct parent message being replied to.
    #[serde(borrow)]
    pub parent: AtUri<'a>,
    ///AT-URI of the root message in the thread.
    #[serde(borrow)]
    pub root: AtUri<'a>,
}

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

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


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum RichTextFacetFeaturesItem<'a> {
    #[serde(rename = "app.protoimsg.chat.message#mention")]
    Mention(Box<message::Mention<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#link")]
    Link(Box<message::Link<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#tag")]
    Tag(Box<message::Tag<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#bold")]
    Bold(Box<message::Bold<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#italic")]
    Italic(Box<message::Italic<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#strikethrough")]
    Strikethrough(Box<message::Strikethrough<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#codeInline")]
    CodeInline(Box<message::CodeInline<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#codeBlock")]
    CodeBlock(Box<message::CodeBlock<'a>>),
    #[serde(rename = "app.protoimsg.chat.message#blockquote")]
    Blockquote(Box<message::Blockquote<'a>>),
}

/// Facet feature for strikethrough text.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Strikethrough<'a> {}
/// Facet feature for a hashtag. The text usually includes a '#' prefix, but the facet reference should not.

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

/// Embedded video.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct VideoEmbed<'a> {
    ///Alt text for accessibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub alt: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub aspect_ratio: Option<message::AspectRatio<'a>>,
    ///Video thumbnail image.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub thumbnail: Option<BlobRef<'a>>,
    ///Video blob reference.
    #[serde(borrow)]
    pub video: BlobRef<'a>,
}

impl<'a> Message<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, MessageRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

impl<'a> LexiconSchema for AspectRatio<'a> {
    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<'a> LexiconSchema for Blockquote<'a> {
    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<'a> LexiconSchema for Bold<'a> {
    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<'a> LexiconSchema for ByteSlice<'a> {
    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<'a> LexiconSchema for CodeBlock<'a> {
    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<'a> LexiconSchema for CodeInline<'a> {
    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<'a> LexiconSchema for ExternalEmbed<'a> {
    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<'a> LexiconSchema for ImageEmbed<'a> {
    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<'a> LexiconSchema for ImageItem<'a> {
    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<'a> LexiconSchema for Italic<'a> {
    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<'a> LexiconSchema for Link<'a> {
    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<'de> = MessageGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<MessageGetRecordOutput<'_>> for Message<'_> {
    fn from(output: MessageGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Message<'_> {
    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<'a> LexiconSchema for Message<'a> {
    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<'a> LexiconSchema for Mention<'a> {
    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<'a> LexiconSchema for ReplyRef<'a> {
    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<'a> LexiconSchema for RichTextFacet<'a> {
    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<'a> LexiconSchema for Strikethrough<'a> {
    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<'a> LexiconSchema for Tag<'a> {
    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<'a> LexiconSchema for VideoEmbed<'a> {
    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 Width;
        type Height;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Width = Unset;
        type Height = Unset;
    }
    ///State transition - sets the `width` field to Set
    pub struct SetWidth<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetWidth<S> {}
    impl<S: State> State for SetWidth<S> {
        type Width = Set<members::width>;
        type Height = S::Height;
    }
    ///State transition - sets the `height` field to Set
    pub struct SetHeight<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetHeight<S> {}
    impl<S: State> State for SetHeight<S> {
        type Width = S::Width;
        type Height = Set<members::height>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `width` field
        pub struct width(());
        ///Marker type for the `height` field
        pub struct height(());
    }
}

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

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

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

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

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

impl<'a, S> AspectRatioBuilder<'a, S>
where
    S: aspect_ratio_state::State,
    S::Width: aspect_ratio_state::IsSet,
    S::Height: aspect_ratio_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> AspectRatio<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> AspectRatio<'a> {
        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 ByteStart;
        type ByteEnd;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type ByteStart = Unset;
        type ByteEnd = Unset;
    }
    ///State transition - sets the `byte_start` field to Set
    pub struct SetByteStart<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetByteStart<S> {}
    impl<S: State> State for SetByteStart<S> {
        type ByteStart = Set<members::byte_start>;
        type ByteEnd = S::ByteEnd;
    }
    ///State transition - sets the `byte_end` field to Set
    pub struct SetByteEnd<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetByteEnd<S> {}
    impl<S: State> State for SetByteEnd<S> {
        type ByteStart = S::ByteStart;
        type ByteEnd = Set<members::byte_end>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `byte_start` field
        pub struct byte_start(());
        ///Marker type for the `byte_end` field
        pub struct byte_end(());
    }
}

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

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

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

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

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

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

pub mod 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTitle<S> {}
    impl<S: State> State for SetTitle<S> {
        type Title = Set<members::title>;
        type Uri = S::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Title = S::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<'a, S: external_embed_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<BlobRef<'a>>,
        Option<CowStr<'a>>,
        Option<UriValue<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: external_embed_state::State> ExternalEmbedBuilder<'a, S> {
    /// Set the `thumb` field (optional)
    pub fn thumb(mut self, value: impl Into<Option<BlobRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<'a, S> ExternalEmbedBuilder<'a, S>
where
    S: external_embed_state::State,
    S::Title: external_embed_state::IsSet,
    S::Uri: external_embed_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ExternalEmbed<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ExternalEmbed<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetImages<S> {}
    impl<S: State> State for SetImages<S> {
        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<'a, S: image_embed_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<message::ImageItem<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> ImageEmbedBuilder<'a, S>
where
    S: image_embed_state::State,
    S::Images: image_embed_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ImageEmbed<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ImageEmbed<'a> {
        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 Image;
        type Alt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Image = Unset;
        type Alt = Unset;
    }
    ///State transition - sets the `image` field to Set
    pub struct SetImage<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetImage<S> {}
    impl<S: State> State for SetImage<S> {
        type Image = Set<members::image>;
        type Alt = S::Alt;
    }
    ///State transition - sets the `alt` field to Set
    pub struct SetAlt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAlt<S> {}
    impl<S: State> State for SetAlt<S> {
        type Image = S::Image;
        type Alt = Set<members::alt>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `image` field
        pub struct image(());
        ///Marker type for the `alt` field
        pub struct alt(());
    }
}

/// Builder for constructing an instance of this type
pub struct ImageItemBuilder<'a, S: image_item_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<message::AspectRatio<'a>>, Option<BlobRef<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: image_item_state::State> ImageItemBuilder<'a, S> {
    /// Set the `aspectRatio` field (optional)
    pub fn aspect_ratio(
        mut self,
        value: impl Into<Option<message::AspectRatio<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<'a, S> ImageItemBuilder<'a, S>
where
    S: image_item_state::State,
    S::Image: image_item_state::IsSet,
    S::Alt: image_item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ImageItem<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ImageItem<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

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

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

impl<'a, S> LinkBuilder<'a, S>
where
    S: link_state::State,
    S::Uri: link_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Link<'a> {
        Link {
            uri: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Link<'a> {
        Link {
            uri: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

/// Builder for constructing an instance of this type
pub struct MessageBuilder<'a, S: message_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<AtUri<'a>>,
        Option<Datetime>,
        Option<MessageEmbed<'a>>,
        Option<Vec<message::RichTextFacet<'a>>>,
        Option<message::ReplyRef<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: message_state::State> MessageBuilder<'a, S> {
    /// Set the `embed` field (optional)
    pub fn embed(mut self, value: impl Into<Option<MessageEmbed<'a>>>) -> 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<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: message_state::State> MessageBuilder<'a, S> {
    /// Set the `facets` field (optional)
    pub fn facets(
        mut self,
        value: impl Into<Option<Vec<message::RichTextFacet<'a>>>>,
    ) -> 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<'a>>>,
    ) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: message_state::State> MessageBuilder<'a, S> {
    /// Set the `reply` field (optional)
    pub fn reply(mut self, value: impl Into<Option<message::ReplyRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<'a, S> MessageBuilder<'a, S>
where
    S: message_state::State,
    S::Channel: message_state::IsSet,
    S::Text: message_state::IsSet,
    S::CreatedAt: message_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Message<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Message<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDid<S> {}
    impl<S: State> State for SetDid<S> {
        type Did = Set<members::did>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `did` field
        pub struct did(());
    }
}

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

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

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

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

impl<'a, S> MentionBuilder<'a, S>
where
    S: mention_state::State,
    S::Did: mention_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Mention<'a> {
        Mention {
            did: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Mention<'a> {
        Mention {
            did: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetParent<S> {}
    impl<S: State> State for SetParent<S> {
        type Parent = Set<members::parent>;
        type Root = S::Root;
    }
    ///State transition - sets the `root` field to Set
    pub struct SetRoot<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRoot<S> {}
    impl<S: State> State for SetRoot<S> {
        type Parent = S::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<'a, S: reply_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AtUri<'a>>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> ReplyRefBuilder<'a, S>
where
    S: reply_ref_state::State,
    S::Parent: reply_ref_state::IsSet,
    S::Root: reply_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ReplyRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ReplyRef<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetFeatures<S> {}
    impl<S: State> State for SetFeatures<S> {
        type Features = Set<members::features>;
        type Index = S::Index;
    }
    ///State transition - sets the `index` field to Set
    pub struct SetIndex<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIndex<S> {}
    impl<S: State> State for SetIndex<S> {
        type Features = S::Features;
        type Index = Set<members::index>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `features` field
        pub struct features(());
        ///Marker type for the `index` field
        pub struct index(());
    }
}

/// Builder for constructing an instance of this type
pub struct RichTextFacetBuilder<'a, S: rich_text_facet_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<RichTextFacetFeaturesItem<'a>>>,
        Option<message::ByteSlice<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> RichTextFacetBuilder<'a, S>
where
    S: rich_text_facet_state::State,
    S::Features: rich_text_facet_state::IsSet,
    S::Index: rich_text_facet_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RichTextFacet<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> RichTextFacet<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetVideo<S> {}
    impl<S: State> State for SetVideo<S> {
        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<'a, S: video_embed_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<message::AspectRatio<'a>>,
        Option<BlobRef<'a>>,
        Option<BlobRef<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: video_embed_state::State> VideoEmbedBuilder<'a, S> {
    /// Set the `aspectRatio` field (optional)
    pub fn aspect_ratio(
        mut self,
        value: impl Into<Option<message::AspectRatio<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: video_embed_state::State> VideoEmbedBuilder<'a, S> {
    /// Set the `thumbnail` field (optional)
    pub fn thumbnail(mut self, value: impl Into<Option<BlobRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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