// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: blue.backyard.feed.post
//
// 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::{AtUri, Cid, Datetime, Language, 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::blue_backyard::richtext::facet::Facet;
use crate::blue_backyard::feed::post;
/// Width and height of the media, used for layout before the blob is loaded.

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

/// An inline URL embed (link preview).

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct EmbedBlock<'a> {
    ///The URL to embed as a link preview.
    #[serde(borrow)]
    pub url: UriValue<'a>,
}

/// An inline image or video.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ImageBlock<'a> {
    ///Alt text description 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<post::AspectRatio<'a>>,
    #[serde(borrow)]
    pub blob: BlobRef<'a>,
    ///MIME type of the media (e.g. image/jpeg, video/mp4). Duplicated from the blob ref for convenience.
    #[serde(borrow)]
    pub mime_type: CowStr<'a>,
}

/// An original post in a user's Backyard feed.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Post<'a> {
    ///Ordered array of content blocks. Each block is a text block, image block, or embed block.
    #[serde(borrow)]
    pub content: Vec<PostContentItem<'a>>,
    pub created_at: Datetime,
    ///BCP-47 language tags of the post text.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub langs: Option<Vec<Language>>,
    ///Additional non-inline tags for categorization.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tags: Option<Vec<CowStr<'a>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum PostContentItem<'a> {
    #[serde(rename = "blue.backyard.feed.post#textBlock")]
    TextBlock(Box<post::TextBlock<'a>>),
    #[serde(rename = "blue.backyard.feed.post#imageBlock")]
    ImageBlock(Box<post::ImageBlock<'a>>),
    #[serde(rename = "blue.backyard.feed.post#embedBlock")]
    EmbedBlock(Box<post::EmbedBlock<'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 PostGetRecordOutput<'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: Post<'a>,
}

/// A block of rich text content.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct TextBlock<'a> {
    ///Annotations of text (mentions, URLs, hashtags, formatting).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub facets: Option<Vec<Facet<'a>>>,
    ///The text content of this block.
    #[serde(borrow)]
    pub text: CowStr<'a>,
}

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

impl<'a> LexiconSchema for AspectRatio<'a> {
    fn nsid() -> &'static str {
        "blue.backyard.feed.post"
    }
    fn def_name() -> &'static str {
        "aspectRatio"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blue_backyard_feed_post()
    }
    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 EmbedBlock<'a> {
    fn nsid() -> &'static str {
        "blue.backyard.feed.post"
    }
    fn def_name() -> &'static str {
        "embedBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blue_backyard_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for ImageBlock<'a> {
    fn nsid() -> &'static str {
        "blue.backyard.feed.post"
    }
    fn def_name() -> &'static str {
        "imageBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blue_backyard_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.alt {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.alt {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("alt"),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.blob;
            {
                let size = value.blob().size;
                if size > 50000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("blob"),
                        max: 50000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.blob;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &[
                    "image/png",
                    "image/jpeg",
                    "image/gif",
                    "image/webp",
                    "image/avif",
                    "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("blob"),
                        accepted: vec![
                            "image/png".to_string(), "image/jpeg".to_string(),
                            "image/gif".to_string(), "image/webp".to_string(),
                            "image/avif".to_string(), "video/mp4".to_string(),
                            "video/webm".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        {
            let value = &self.mime_type;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 255usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("mime_type"),
                    max: 255usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct PostRecord;
impl XrpcResp for PostRecord {
    const NSID: &'static str = "blue.backyard.feed.post";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = PostGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Post<'_> {
    const NSID: &'static str = "blue.backyard.feed.post";
    type Record = PostRecord;
}

impl Collection for PostRecord {
    const NSID: &'static str = "blue.backyard.feed.post";
    type Record = PostRecord;
}

impl<'a> LexiconSchema for Post<'a> {
    fn nsid() -> &'static str {
        "blue.backyard.feed.post"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blue_backyard_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.content;
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("content"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.content;
            #[allow(unused_comparisons)]
            if value.len() < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("content"),
                    min: 1usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.langs {
            #[allow(unused_comparisons)]
            if value.len() > 3usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("langs"),
                    max: 3usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.tags {
            #[allow(unused_comparisons)]
            if value.len() > 8usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tags"),
                    max: 8usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for TextBlock<'a> {
    fn nsid() -> &'static str {
        "blue.backyard.feed.post"
    }
    fn def_name() -> &'static str {
        "textBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blue_backyard_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 30000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 30000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.text;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 3000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("text"),
                        max: 3000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod aspect_ratio_state {

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

/// Builder for constructing an instance of this type
pub struct AspectRatioBuilder<'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::Height: aspect_ratio_state::IsSet,
    S::Width: 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_blue_backyard_feed_post() -> 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("blue.backyard.feed.post"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("aspectRatio"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Width and height of the media, used for layout before the blob is loaded.",
                        ),
                    ),
                    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("embedBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("An inline URL embed (link preview)."),
                    ),
                    required: Some(vec![SmolStr::new_static("url")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The URL to embed as a link preview."),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("imageBlock"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("An inline image or video.")),
                    required: Some(
                        vec![
                            SmolStr::new_static("blob"), SmolStr::new_static("mimeType")
                        ],
                    ),
                    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 description for accessibility.",
                                    ),
                                ),
                                max_length: Some(10000usize),
                                max_graphemes: Some(1000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#aspectRatio"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("blob"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("mimeType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "MIME type of the media (e.g. image/jpeg, video/mp4). Duplicated from the blob ref for convenience.",
                                    ),
                                ),
                                max_length: Some(255usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("An original post in a user's Backyard feed."),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("content"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("content"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Ordered array of content blocks. Each block is a text block, image block, or embed block.",
                                        ),
                                    ),
                                    items: LexArrayItem::Union(LexRefUnion {
                                        refs: vec![
                                            CowStr::new_static("#textBlock"),
                                            CowStr::new_static("#imageBlock"),
                                            CowStr::new_static("#embedBlock")
                                        ],
                                        ..Default::default()
                                    }),
                                    min_length: Some(1usize),
                                    max_length: Some(20usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("langs"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("BCP-47 language tags of the post text."),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::Language),
                                        ..Default::default()
                                    }),
                                    max_length: Some(3usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tags"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Additional non-inline tags for categorization.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        max_length: Some(640usize),
                                        max_graphemes: Some(64usize),
                                        ..Default::default()
                                    }),
                                    max_length: Some(8usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("textBlock"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A block of rich text content."),
                    ),
                    required: Some(vec![SmolStr::new_static("text")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("facets"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Annotations of text (mentions, URLs, hashtags, formatting).",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("blue.backyard.richtext.facet"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The text content of this block."),
                                ),
                                max_length: Some(30000usize),
                                max_graphemes: Some(3000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod embed_block_state {

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

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

impl<'a> EmbedBlock<'a> {
    /// Create a new builder for this type
    pub fn new() -> EmbedBlockBuilder<'a, embed_block_state::Empty> {
        EmbedBlockBuilder::new()
    }
}

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

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

impl<'a, S> EmbedBlockBuilder<'a, S>
where
    S: embed_block_state::State,
    S::Url: embed_block_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> EmbedBlock<'a> {
        EmbedBlock {
            url: 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>,
        >,
    ) -> EmbedBlock<'a> {
        EmbedBlock {
            url: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod image_block_state {

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

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

impl<'a> ImageBlock<'a> {
    /// Create a new builder for this type
    pub fn new() -> ImageBlockBuilder<'a, image_block_state::Empty> {
        ImageBlockBuilder::new()
    }
}

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

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

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

impl<'a, S> ImageBlockBuilder<'a, S>
where
    S: image_block_state::State,
    S::MimeType: image_block_state::IsUnset,
{
    /// Set the `mimeType` field (required)
    pub fn mime_type(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> ImageBlockBuilder<'a, image_block_state::SetMimeType<S>> {
        self._fields.3 = Option::Some(value.into());
        ImageBlockBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ImageBlockBuilder<'a, S>
where
    S: image_block_state::State,
    S::MimeType: image_block_state::IsSet,
    S::Blob: image_block_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ImageBlock<'a> {
        ImageBlock {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            blob: self._fields.2.unwrap(),
            mime_type: 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>,
        >,
    ) -> ImageBlock<'a> {
        ImageBlock {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            blob: self._fields.2.unwrap(),
            mime_type: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

/// Builder for constructing an instance of this type
pub struct PostBuilder<'a, S: post_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<PostContentItem<'a>>>,
        Option<Datetime>,
        Option<Vec<Language>>,
        Option<Vec<CowStr<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Post<'a> {
    /// Create a new builder for this type
    pub fn new() -> PostBuilder<'a, post_state::Empty> {
        PostBuilder::new()
    }
}

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

impl<'a, S> PostBuilder<'a, S>
where
    S: post_state::State,
    S::Content: post_state::IsUnset,
{
    /// Set the `content` field (required)
    pub fn content(
        mut self,
        value: impl Into<Vec<PostContentItem<'a>>>,
    ) -> PostBuilder<'a, post_state::SetContent<S>> {
        self._fields.0 = Option::Some(value.into());
        PostBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S: post_state::State> PostBuilder<'a, S> {
    /// Set the `langs` field (optional)
    pub fn langs(mut self, value: impl Into<Option<Vec<Language>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `langs` field to an Option value (optional)
    pub fn maybe_langs(mut self, value: Option<Vec<Language>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: post_state::State> PostBuilder<'a, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `tags` field to an Option value (optional)
    pub fn maybe_tags(mut self, value: Option<Vec<CowStr<'a>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> PostBuilder<'a, S>
where
    S: post_state::State,
    S::CreatedAt: post_state::IsSet,
    S::Content: post_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Post<'a> {
        Post {
            content: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            langs: self._fields.2,
            tags: self._fields.3,
            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>,
        >,
    ) -> Post<'a> {
        Post {
            content: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            langs: self._fields.2,
            tags: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}