// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: pub.leaflet.pages.canvas
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, 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::pub_leaflet::blocks::blockquote::Blockquote;
use crate::pub_leaflet::blocks::bsky_post::BskyPost;
use crate::pub_leaflet::blocks::button::Button;
use crate::pub_leaflet::blocks::code::Code;
use crate::pub_leaflet::blocks::header::Header;
use crate::pub_leaflet::blocks::horizontal_rule::HorizontalRule;
use crate::pub_leaflet::blocks::iframe::Iframe;
use crate::pub_leaflet::blocks::image::Image;
use crate::pub_leaflet::blocks::math::Math;
use crate::pub_leaflet::blocks::ordered_list::OrderedList;
use crate::pub_leaflet::blocks::page::Page;
use crate::pub_leaflet::blocks::poll::Poll;
use crate::pub_leaflet::blocks::posts_list::PostsList;
use crate::pub_leaflet::blocks::signup::Signup;
use crate::pub_leaflet::blocks::standard_site_post::StandardSitePost;
use crate::pub_leaflet::blocks::text::Text;
use crate::pub_leaflet::blocks::unordered_list::UnorderedList;
use crate::pub_leaflet::blocks::website::Website;
use crate::pub_leaflet::pages::canvas;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Block<S: BosStr = DefaultStr> {
    pub block: BlockBlock<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub height: Option<i64>,
    ///The rotation of the block in degrees
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rotation: Option<i64>,
    pub width: i64,
    pub x: i64,
    pub y: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum BlockBlock<S: BosStr = DefaultStr> {
    #[serde(rename = "pub.leaflet.blocks.iframe")]
    Iframe(Box<Iframe<S>>),
    #[serde(rename = "pub.leaflet.blocks.text")]
    Text(Box<Text<S>>),
    #[serde(rename = "pub.leaflet.blocks.blockquote")]
    Blockquote(Box<Blockquote<S>>),
    #[serde(rename = "pub.leaflet.blocks.header")]
    Header(Box<Header<S>>),
    #[serde(rename = "pub.leaflet.blocks.image")]
    Image(Box<Image<S>>),
    #[serde(rename = "pub.leaflet.blocks.unorderedList")]
    UnorderedList(Box<UnorderedList<S>>),
    #[serde(rename = "pub.leaflet.blocks.orderedList")]
    OrderedList(Box<OrderedList<S>>),
    #[serde(rename = "pub.leaflet.blocks.website")]
    Website(Box<Website<S>>),
    #[serde(rename = "pub.leaflet.blocks.math")]
    Math(Box<Math<S>>),
    #[serde(rename = "pub.leaflet.blocks.code")]
    Code(Box<Code<S>>),
    #[serde(rename = "pub.leaflet.blocks.horizontalRule")]
    HorizontalRule(Box<HorizontalRule<S>>),
    #[serde(rename = "pub.leaflet.blocks.bskyPost")]
    BskyPost(Box<BskyPost<S>>),
    #[serde(rename = "pub.leaflet.blocks.standardSitePost")]
    StandardSitePost(Box<StandardSitePost<S>>),
    #[serde(rename = "pub.leaflet.blocks.page")]
    Page(Box<Page<S>>),
    #[serde(rename = "pub.leaflet.blocks.poll")]
    Poll(Box<Poll<S>>),
    #[serde(rename = "pub.leaflet.blocks.button")]
    Button(Box<Button<S>>),
    #[serde(rename = "pub.leaflet.blocks.postsList")]
    PostsList(Box<PostsList<S>>),
    #[serde(rename = "pub.leaflet.blocks.signup")]
    Signup(Box<Signup<S>>),
}


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


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


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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct TextAlignCenter;
impl core::fmt::Display for TextAlignCenter {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "textAlignCenter")
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct TextAlignLeft;
impl core::fmt::Display for TextAlignLeft {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "textAlignLeft")
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct TextAlignRight;
impl core::fmt::Display for TextAlignRight {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "textAlignRight")
    }
}

impl<S: BosStr> LexiconSchema for Block<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.pages.canvas"
    }
    fn def_name() -> &'static str {
        "block"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_pages_canvas()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Canvas<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.pages.canvas"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_pages_canvas()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Position<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.pages.canvas"
    }
    fn def_name() -> &'static str {
        "position"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_pages_canvas()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Quote<S> {
    fn nsid() -> &'static str {
        "pub.leaflet.pages.canvas"
    }
    fn def_name() -> &'static str {
        "quote"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_leaflet_pages_canvas()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Block<S> {
    /// Create a new builder for this type
    pub fn builder() -> BlockBuilder<block_state::Empty, S> {
        BlockBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> BlockBuilder<St, S>
where
    St: block_state::State,
    St::Block: block_state::IsUnset,
{
    /// Set the `block` field (required)
    pub fn block(
        mut self,
        value: impl Into<BlockBlock<S>>,
    ) -> BlockBuilder<block_state::SetBlock<St>, S> {
        self._fields.0 = Option::Some(value.into());
        BlockBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: block_state::State, S: BosStr> BlockBuilder<St, S> {
    /// Set the `height` field (optional)
    pub fn height(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `height` field to an Option value (optional)
    pub fn maybe_height(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: block_state::State, S: BosStr> BlockBuilder<St, S> {
    /// Set the `rotation` field (optional)
    pub fn rotation(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `rotation` field to an Option value (optional)
    pub fn maybe_rotation(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<St, S: BosStr> BlockBuilder<St, S>
where
    St: block_state::State,
    St::X: block_state::IsUnset,
{
    /// Set the `x` field (required)
    pub fn x(mut self, value: impl Into<i64>) -> BlockBuilder<block_state::SetX<St>, S> {
        self._fields.4 = Option::Some(value.into());
        BlockBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BlockBuilder<St, S>
where
    St: block_state::State,
    St::Y: block_state::IsUnset,
{
    /// Set the `y` field (required)
    pub fn y(mut self, value: impl Into<i64>) -> BlockBuilder<block_state::SetY<St>, S> {
        self._fields.5 = Option::Some(value.into());
        BlockBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> BlockBuilder<St, S>
where
    St: block_state::State,
    St::Block: block_state::IsSet,
    St::Width: block_state::IsSet,
    St::X: block_state::IsSet,
    St::Y: block_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Block<S> {
        Block {
            block: self._fields.0.unwrap(),
            height: self._fields.1,
            rotation: self._fields.2,
            width: self._fields.3.unwrap(),
            x: self._fields.4.unwrap(),
            y: self._fields.5.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Block<S> {
        Block {
            block: self._fields.0.unwrap(),
            height: self._fields.1,
            rotation: self._fields.2,
            width: self._fields.3.unwrap(),
            x: self._fields.4.unwrap(),
            y: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_pub_leaflet_pages_canvas() -> 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("pub.leaflet.pages.canvas"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("block"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("block"), SmolStr::new_static("x"),
                            SmolStr::new_static("y"), SmolStr::new_static("width")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("block"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("pub.leaflet.blocks.iframe"),
                                    CowStr::new_static("pub.leaflet.blocks.text"),
                                    CowStr::new_static("pub.leaflet.blocks.blockquote"),
                                    CowStr::new_static("pub.leaflet.blocks.header"),
                                    CowStr::new_static("pub.leaflet.blocks.image"),
                                    CowStr::new_static("pub.leaflet.blocks.unorderedList"),
                                    CowStr::new_static("pub.leaflet.blocks.orderedList"),
                                    CowStr::new_static("pub.leaflet.blocks.website"),
                                    CowStr::new_static("pub.leaflet.blocks.math"),
                                    CowStr::new_static("pub.leaflet.blocks.code"),
                                    CowStr::new_static("pub.leaflet.blocks.horizontalRule"),
                                    CowStr::new_static("pub.leaflet.blocks.bskyPost"),
                                    CowStr::new_static("pub.leaflet.blocks.standardSitePost"),
                                    CowStr::new_static("pub.leaflet.blocks.page"),
                                    CowStr::new_static("pub.leaflet.blocks.poll"),
                                    CowStr::new_static("pub.leaflet.blocks.button"),
                                    CowStr::new_static("pub.leaflet.blocks.postsList"),
                                    CowStr::new_static("pub.leaflet.blocks.signup")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("height"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rotation"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("width"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("x"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("y"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("blocks")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("blocks"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#block"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("position"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("block"), SmolStr::new_static("offset")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("block"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Integer(LexInteger {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("offset"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("quote"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("start"), SmolStr::new_static("end")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("end"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#position"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("start"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#position"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("textAlignCenter"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("textAlignLeft"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("textAlignRight"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> Canvas<S> {
    /// Create a new builder for this type
    pub fn builder() -> CanvasBuilder<canvas_state::Empty, S> {
        CanvasBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> CanvasBuilder<St, S>
where
    St: canvas_state::State,
    St::Blocks: canvas_state::IsUnset,
{
    /// Set the `blocks` field (required)
    pub fn blocks(
        mut self,
        value: impl Into<Vec<canvas::Block<S>>>,
    ) -> CanvasBuilder<canvas_state::SetBlocks<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CanvasBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> CanvasBuilder<St, S>
where
    St: canvas_state::State,
    St::Blocks: canvas_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Canvas<S> {
        Canvas {
            blocks: self._fields.0.unwrap(),
            id: self._fields.1,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Canvas<S> {
        Canvas {
            blocks: self._fields.0.unwrap(),
            id: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> Position<S> {
    /// Create a new builder for this type
    pub fn builder() -> PositionBuilder<position_state::Empty, S> {
        PositionBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> PositionBuilder<St, S>
where
    St: position_state::State,
    St::Block: position_state::IsUnset,
{
    /// Set the `block` field (required)
    pub fn block(
        mut self,
        value: impl Into<Vec<i64>>,
    ) -> PositionBuilder<position_state::SetBlock<St>, S> {
        self._fields.0 = Option::Some(value.into());
        PositionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> PositionBuilder<St, S>
where
    St: position_state::State,
    St::Block: position_state::IsSet,
    St::Offset: position_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Position<S> {
        Position {
            block: self._fields.0.unwrap(),
            offset: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Position<S> {
        Position {
            block: self._fields.0.unwrap(),
            offset: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> Quote<S> {
    /// Create a new builder for this type
    pub fn builder() -> QuoteBuilder<quote_state::Empty, S> {
        QuoteBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> QuoteBuilder<St, S>
where
    St: quote_state::State,
    St::End: quote_state::IsUnset,
{
    /// Set the `end` field (required)
    pub fn end(
        mut self,
        value: impl Into<canvas::Position<S>>,
    ) -> QuoteBuilder<quote_state::SetEnd<St>, S> {
        self._fields.0 = Option::Some(value.into());
        QuoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> QuoteBuilder<St, S>
where
    St: quote_state::State,
    St::Start: quote_state::IsUnset,
{
    /// Set the `start` field (required)
    pub fn start(
        mut self,
        value: impl Into<canvas::Position<S>>,
    ) -> QuoteBuilder<quote_state::SetStart<St>, S> {
        self._fields.1 = Option::Some(value.into());
        QuoteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> QuoteBuilder<St, S>
where
    St: quote_state::State,
    St::End: quote_state::IsSet,
    St::Start: quote_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Quote<S> {
        Quote {
            end: self._fields.0.unwrap(),
            start: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Quote<S> {
        Quote {
            end: self._fields.0.unwrap(),
            start: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}