// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: network.slices.tools.document
//
// 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};
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::network_slices::tools::richtext::facet::Facet;
use crate::network_slices::tools::document;
/// A fenced code block

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

/// A heading block (h1-h3) with optional inline formatting

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Heading<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub facets: Option<Vec<Facet<'a>>>,
    pub level: i64,
    #[serde(borrow)]
    pub text: CowStr<'a>,
}

/// An embedded image with alt text

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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Document<'a> {
    ///Document content as array of blocks
    #[serde(borrow)]
    pub blocks: Vec<DocumentBlocksItem<'a>>,
    pub created_at: Datetime,
    ///URL-friendly identifier, unique per author
    #[serde(borrow)]
    pub slug: CowStr<'a>,
    ///Document title
    #[serde(borrow)]
    pub title: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum DocumentBlocksItem<'a> {
    #[serde(rename = "network.slices.tools.document#paragraph")]
    Paragraph(Box<document::Paragraph<'a>>),
    #[serde(rename = "network.slices.tools.document#heading")]
    Heading(Box<document::Heading<'a>>),
    #[serde(rename = "network.slices.tools.document#codeBlock")]
    CodeBlock(Box<document::CodeBlock<'a>>),
    #[serde(rename = "network.slices.tools.document#quote")]
    Quote(Box<document::Quote<'a>>),
    #[serde(rename = "network.slices.tools.document#tangledEmbed")]
    TangledEmbed(Box<document::TangledEmbed<'a>>),
    #[serde(rename = "network.slices.tools.document#imageEmbed")]
    ImageEmbed(Box<document::ImageEmbed<'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 DocumentGetRecordOutput<'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: Document<'a>,
}

/// A paragraph block with optional inline formatting

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Paragraph<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub facets: Option<Vec<Facet<'a>>>,
    #[serde(borrow)]
    pub text: CowStr<'a>,
}

/// A blockquote with optional inline formatting

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Quote<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub facets: Option<Vec<Facet<'a>>>,
    #[serde(borrow)]
    pub text: CowStr<'a>,
}

/// An embedded Tangled repo card

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct TangledEmbed<'a> {
    ///The repo owner's handle
    #[serde(borrow)]
    pub handle: CowStr<'a>,
    ///The repository name
    #[serde(borrow)]
    pub repo: CowStr<'a>,
}

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

impl<'a> LexiconSchema for CodeBlock<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.document"
    }
    fn def_name() -> &'static str {
        "codeBlock"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_document()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.code;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 20000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("code"),
                    max: 20000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        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 Heading<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.document"
    }
    fn def_name() -> &'static str {
        "heading"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_document()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.level;
            if *value > 3i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("level"),
                    max: 3i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.level;
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("level"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 300usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 300usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for ImageEmbed<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.document"
    }
    fn def_name() -> &'static str {
        "imageEmbed"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_document()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.alt {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 1000usize,
                    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/*"];
                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/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct DocumentRecord;
impl XrpcResp for DocumentRecord {
    const NSID: &'static str = "network.slices.tools.document";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = DocumentGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Document<'_> {
    const NSID: &'static str = "network.slices.tools.document";
    type Record = DocumentRecord;
}

impl Collection for DocumentRecord {
    const NSID: &'static str = "network.slices.tools.document";
    type Record = DocumentRecord;
}

impl<'a> LexiconSchema for Document<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.document"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_document()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.slug;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("slug"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            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 Paragraph<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.document"
    }
    fn def_name() -> &'static str {
        "paragraph"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_document()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Quote<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.document"
    }
    fn def_name() -> &'static str {
        "quote"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_document()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 5000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 5000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for TangledEmbed<'a> {
    fn nsid() -> &'static str {
        "network.slices.tools.document"
    }
    fn def_name() -> &'static str {
        "tangledEmbed"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_network_slices_tools_document()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.handle;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 300usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("handle"),
                    max: 300usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.repo;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 300usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("repo"),
                    max: 300usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_network_slices_tools_document() -> 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("network.slices.tools.document"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("codeBlock"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A fenced code block")),
                    required: Some(vec![SmolStr::new_static("code")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("code"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(20000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("lang"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(50usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("heading"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A heading block (h1-h3) with optional inline formatting",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("level"), SmolStr::new_static("text")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("facets"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "network.slices.tools.richtext.facet",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("level"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                maximum: Some(3i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(300usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("imageEmbed"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("An embedded image with alt text"),
                    ),
                    required: Some(vec![SmolStr::new_static("image")]),
                    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(1000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("image"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("title"), SmolStr::new_static("slug"),
                                SmolStr::new_static("blocks"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("blocks"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("Document content as array of blocks"),
                                    ),
                                    items: LexArrayItem::Union(LexRefUnion {
                                        refs: vec![
                                            CowStr::new_static("#paragraph"),
                                            CowStr::new_static("#heading"),
                                            CowStr::new_static("#codeBlock"),
                                            CowStr::new_static("#quote"),
                                            CowStr::new_static("#tangledEmbed"),
                                            CowStr::new_static("#imageEmbed")
                                        ],
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("slug"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "URL-friendly identifier, unique per author",
                                        ),
                                    ),
                                    max_length: Some(100usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("Document title")),
                                    max_length: Some(300usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("paragraph"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A paragraph block with optional inline formatting",
                        ),
                    ),
                    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 {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "network.slices.tools.richtext.facet",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(10000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("quote"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A blockquote with optional inline formatting",
                        ),
                    ),
                    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 {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "network.slices.tools.richtext.facet",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("text"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(5000usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("tangledEmbed"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("An embedded Tangled repo card"),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("handle"), SmolStr::new_static("repo")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The repo owner's handle"),
                                ),
                                max_length: Some(300usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("repo"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The repository name"),
                                ),
                                max_length: Some(300usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

impl<'a> Heading<'a> {
    /// Create a new builder for this type
    pub fn new() -> HeadingBuilder<'a, heading_state::Empty> {
        HeadingBuilder::new()
    }
}

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

impl<'a, S: heading_state::State> HeadingBuilder<'a, S> {
    /// Set the `facets` field (optional)
    pub fn facets(mut self, value: impl Into<Option<Vec<Facet<'a>>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `facets` field to an Option value (optional)
    pub fn maybe_facets(mut self, value: Option<Vec<Facet<'a>>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

impl<'a, S> HeadingBuilder<'a, S>
where
    S: heading_state::State,
    S::Text: heading_state::IsSet,
    S::Level: heading_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Heading<'a> {
        Heading {
            facets: self._fields.0,
            level: self._fields.1.unwrap(),
            text: 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>,
        >,
    ) -> Heading<'a> {
        Heading {
            facets: self._fields.0,
            level: self._fields.1.unwrap(),
            text: self._fields.2.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 Image;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Image = 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>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `image` field
        pub struct image(());
    }
}

/// Builder for constructing an instance of this type
pub struct ImageEmbedBuilder<'a, S: image_embed_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<BlobRef<'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, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: image_embed_state::State> ImageEmbedBuilder<'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> ImageEmbedBuilder<'a, S>
where
    S: image_embed_state::State,
    S::Image: image_embed_state::IsUnset,
{
    /// Set the `image` field (required)
    pub fn image(
        mut self,
        value: impl Into<BlobRef<'a>>,
    ) -> ImageEmbedBuilder<'a, image_embed_state::SetImage<S>> {
        self._fields.1 = 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::Image: image_embed_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ImageEmbed<'a> {
        ImageEmbed {
            alt: self._fields.0,
            image: 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>,
        >,
    ) -> ImageEmbed<'a> {
        ImageEmbed {
            alt: self._fields.0,
            image: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

impl<'a> Document<'a> {
    /// Create a new builder for this type
    pub fn new() -> DocumentBuilder<'a, document_state::Empty> {
        DocumentBuilder::new()
    }
}

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

impl<'a, S> DocumentBuilder<'a, S>
where
    S: document_state::State,
    S::Blocks: document_state::IsUnset,
{
    /// Set the `blocks` field (required)
    pub fn blocks(
        mut self,
        value: impl Into<Vec<DocumentBlocksItem<'a>>>,
    ) -> DocumentBuilder<'a, document_state::SetBlocks<S>> {
        self._fields.0 = Option::Some(value.into());
        DocumentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

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

impl<'a, S: document_state::State> DocumentBuilder<'a, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `updatedAt` field to an Option value (optional)
    pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> DocumentBuilder<'a, S>
where
    S: document_state::State,
    S::Slug: document_state::IsSet,
    S::Blocks: document_state::IsSet,
    S::CreatedAt: document_state::IsSet,
    S::Title: document_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Document<'a> {
        Document {
            blocks: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            slug: self._fields.2.unwrap(),
            title: self._fields.3.unwrap(),
            updated_at: self._fields.4,
            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>,
        >,
    ) -> Document<'a> {
        Document {
            blocks: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            slug: self._fields.2.unwrap(),
            title: self._fields.3.unwrap(),
            updated_at: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}