// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.embed.images
//
// 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::string::UriValue;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::app_bsky::embed::AspectRatio;
use crate::sh_weaver::embed::PercentSize;
use crate::sh_weaver::embed::PixelSize;
use crate::sh_weaver::embed::images;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Image<'a> {
    ///alt text description of the image
    #[serde(borrow)]
    pub alt: CowStr<'a>,
    ///Blurhash string for the image, used for low-resolution placeholders. This must be a valid Blurhash string.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub blurhash: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub dimensions: Option<ImageDimensions<'a>>,
    #[serde(borrow)]
    pub image: BlobRef<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ImageDimensions<'a> {
    #[serde(rename = "app.bsky.embed.defs#aspectRatio")]
    AspectRatio(Box<AspectRatio<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#percentSize")]
    PercentSize(Box<PercentSize<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#pixelSize")]
    PixelSize(Box<PixelSize<'a>>),
}


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


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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ViewImage<'a> {
    ///Alt text description of the image, for accessibility.
    #[serde(borrow)]
    pub alt: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub dimensions: Option<ViewImageDimensions<'a>>,
    ///Fully-qualified URL where a large version of the image can be fetched. May or may not be the exact original blob. For example, CDN location provided by the App View.
    #[serde(borrow)]
    pub fullsize: UriValue<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    ///Fully-qualified URL where a thumbnail of the image can be fetched. For example, CDN location provided by the App View.
    #[serde(borrow)]
    pub thumb: UriValue<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ViewImageDimensions<'a> {
    #[serde(rename = "app.bsky.embed.defs#aspectRatio")]
    AspectRatio(Box<AspectRatio<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#percentSize")]
    PercentSize(Box<PercentSize<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#pixelSize")]
    PixelSize(Box<PixelSize<'a>>),
}

impl<'a> LexiconSchema for Image<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.images"
    }
    fn def_name() -> &'static str {
        "image"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_images()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.blurhash {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("blurhash"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.image;
            {
                let size = value.blob().size;
                if size > 3000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("image"),
                        max: 3000000usize,
                        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(),
                    });
                }
            }
        }
        if let Some(ref value) = self.name {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Images<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.images"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_images()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.images;
            #[allow(unused_comparisons)]
            if value.len() > 48usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("images"),
                    max: 48usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for View<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.images"
    }
    fn def_name() -> &'static str {
        "view"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_images()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.images;
            #[allow(unused_comparisons)]
            if value.len() > 48usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("images"),
                    max: 48usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for ViewImage<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.images"
    }
    fn def_name() -> &'static str {
        "viewImage"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_images()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.name {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod image_state {

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

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

impl<'a> Image<'a> {
    /// Create a new builder for this type
    pub fn new() -> ImageBuilder<'a, image_state::Empty> {
        ImageBuilder::new()
    }
}

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

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

impl<'a, S: image_state::State> ImageBuilder<'a, S> {
    /// Set the `blurhash` field (optional)
    pub fn blurhash(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `blurhash` field to an Option value (optional)
    pub fn maybe_blurhash(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S: image_state::State> ImageBuilder<'a, S> {
    /// Set the `dimensions` field (optional)
    pub fn dimensions(mut self, value: impl Into<Option<ImageDimensions<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `dimensions` field to an Option value (optional)
    pub fn maybe_dimensions(mut self, value: Option<ImageDimensions<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<'a, S: image_state::State> ImageBuilder<'a, S> {
    /// Set the `name` field (optional)
    pub fn name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `name` field to an Option value (optional)
    pub fn maybe_name(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> ImageBuilder<'a, S>
where
    S: image_state::State,
    S::Image: image_state::IsSet,
    S::Alt: image_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Image<'a> {
        Image {
            alt: self._fields.0.unwrap(),
            blurhash: self._fields.1,
            dimensions: self._fields.2,
            image: self._fields.3.unwrap(),
            name: 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>,
        >,
    ) -> Image<'a> {
        Image {
            alt: self._fields.0.unwrap(),
            blurhash: self._fields.1,
            dimensions: self._fields.2,
            image: self._fields.3.unwrap(),
            name: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_embed_images() -> 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("sh.weaver.embed.images"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("image"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("image"), SmolStr::new_static("alt")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("alt text description of the image"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("blurhash"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Blurhash string for the image, used for low-resolution placeholders. This must be a valid Blurhash string.",
                                    ),
                                ),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("dimensions"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("app.bsky.embed.defs#aspectRatio"),
                                    CowStr::new_static("sh.weaver.embed.defs#percentSize"),
                                    CowStr::new_static("sh.weaver.embed.defs#pixelSize")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("image"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("images")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("images"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#image"),
                                    ..Default::default()
                                }),
                                max_length: Some(48usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("view"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("images")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("images"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#viewImage"),
                                    ..Default::default()
                                }),
                                max_length: Some(48usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viewImage"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("thumb"),
                            SmolStr::new_static("fullsize"), SmolStr::new_static("alt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Alt text description of the image, for accessibility.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("dimensions"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("app.bsky.embed.defs#aspectRatio"),
                                    CowStr::new_static("sh.weaver.embed.defs#percentSize"),
                                    CowStr::new_static("sh.weaver.embed.defs#pixelSize")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("fullsize"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Fully-qualified URL where a large version of the image can be fetched. May or may not be the exact original blob. For example, CDN location provided by the App View.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("thumb"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Fully-qualified URL where a thumbnail of the image can be fetched. For example, CDN location provided by the App View.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod images_state {

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

/// Builder for constructing an instance of this type
pub struct ImagesBuilder<'a, S: images_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<images::Image<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Images<'a> {
    /// Create a new builder for this type
    pub fn new() -> ImagesBuilder<'a, images_state::Empty> {
        ImagesBuilder::new()
    }
}

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

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

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

pub mod view_state {

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

/// Builder for constructing an instance of this type
pub struct ViewBuilder<'a, S: view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<images::ViewImage<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> View<'a> {
    /// Create a new builder for this type
    pub fn new() -> ViewBuilder<'a, view_state::Empty> {
        ViewBuilder::new()
    }
}

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

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

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

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

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

impl<'a> ViewImage<'a> {
    /// Create a new builder for this type
    pub fn new() -> ViewImageBuilder<'a, view_image_state::Empty> {
        ViewImageBuilder::new()
    }
}

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

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

impl<'a, S: view_image_state::State> ViewImageBuilder<'a, S> {
    /// Set the `dimensions` field (optional)
    pub fn dimensions(
        mut self,
        value: impl Into<Option<ViewImageDimensions<'a>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `dimensions` field to an Option value (optional)
    pub fn maybe_dimensions(mut self, value: Option<ViewImageDimensions<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> ViewImageBuilder<'a, S>
where
    S: view_image_state::State,
    S::Fullsize: view_image_state::IsUnset,
{
    /// Set the `fullsize` field (required)
    pub fn fullsize(
        mut self,
        value: impl Into<UriValue<'a>>,
    ) -> ViewImageBuilder<'a, view_image_state::SetFullsize<S>> {
        self._fields.2 = Option::Some(value.into());
        ViewImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> ViewImageBuilder<'a, S>
where
    S: view_image_state::State,
    S::Thumb: view_image_state::IsUnset,
{
    /// Set the `thumb` field (required)
    pub fn thumb(
        mut self,
        value: impl Into<UriValue<'a>>,
    ) -> ViewImageBuilder<'a, view_image_state::SetThumb<S>> {
        self._fields.4 = Option::Some(value.into());
        ViewImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ViewImageBuilder<'a, S>
where
    S: view_image_state::State,
    S::Thumb: view_image_state::IsSet,
    S::Alt: view_image_state::IsSet,
    S::Fullsize: view_image_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ViewImage<'a> {
        ViewImage {
            alt: self._fields.0.unwrap(),
            dimensions: self._fields.1,
            fullsize: self._fields.2.unwrap(),
            name: self._fields.3,
            thumb: self._fields.4.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>,
        >,
    ) -> ViewImage<'a> {
        ViewImage {
            alt: self._fields.0.unwrap(),
            dimensions: self._fields.1,
            fullsize: self._fields.2.unwrap(),
            name: self._fields.3,
            thumb: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}