// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: art.cllctv.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};
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::art_cllctv::embed::Tombstone;
use crate::art_cllctv::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, for accessibility.
    #[serde(borrow)]
    pub alt: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub aspect_ratio: Option<AspectRatio<'a>>,
    #[serde(borrow)]
    pub image: BlobRef<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub image_hash: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tombstone: Option<Tombstone<'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 aspect_ratio: Option<AspectRatio<'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>,
    ///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>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tombstone: Option<Tombstone<'a>>,
}

impl<'a> LexiconSchema for Image<'a> {
    fn nsid() -> &'static str {
        "art.cllctv.embed.images"
    }
    fn def_name() -> &'static str {
        "image"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_art_cllctv_embed_images()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.image;
            {
                let size = value.blob().size;
                if size > 50000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("image"),
                        max: 50000000usize,
                        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.image_hash {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("image_hash"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.image_hash {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("image_hash"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

impl<'a> LexiconSchema for ViewImage<'a> {
    fn nsid() -> &'static str {
        "art.cllctv.embed.images"
    }
    fn def_name() -> &'static str {
        "viewImage"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_art_cllctv_embed_images()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        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<AspectRatio<'a>>,
        Option<BlobRef<'a>>,
        Option<CowStr<'a>>,
        Option<Tombstone<'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 `aspectRatio` field (optional)
    pub fn aspect_ratio(mut self, value: impl Into<Option<AspectRatio<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `aspectRatio` field to an Option value (optional)
    pub fn maybe_aspect_ratio(mut self, value: Option<AspectRatio<'a>>) -> Self {
        self._fields.1 = 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.2 = Option::Some(value.into());
        ImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S: image_state::State> ImageBuilder<'a, S> {
    /// Set the `tombstone` field (optional)
    pub fn tombstone(mut self, value: impl Into<Option<Tombstone<'a>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `tombstone` field to an Option value (optional)
    pub fn maybe_tombstone(mut self, value: Option<Tombstone<'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(),
            aspect_ratio: self._fields.1,
            image: self._fields.2.unwrap(),
            image_hash: self._fields.3,
            tombstone: 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(),
            aspect_ratio: self._fields.1,
            image: self._fields.2.unwrap(),
            image_hash: self._fields.3,
            tombstone: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_art_cllctv_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("art.cllctv.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, for accessibility.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.embed.defs#aspectRatio",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("image"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("imageHash"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(640usize),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("tombstone"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "art.cllctv.embed.defs#tombstone",
                                ),
                                ..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(9usize),
                                ..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(9usize),
                                ..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("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.embed.defs#aspectRatio",
                                ),
                                ..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("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.insert(
                            SmolStr::new_static("tombstone"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "art.cllctv.embed.defs#tombstone",
                                ),
                                ..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 Fullsize;
        type Thumb;
        type Alt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Fullsize = Unset;
        type Thumb = Unset;
        type Alt = Unset;
    }
    ///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 Fullsize = Set<members::fullsize>;
        type Thumb = S::Thumb;
        type Alt = S::Alt;
    }
    ///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 Fullsize = S::Fullsize;
        type Thumb = Set<members::thumb>;
        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 Fullsize = S::Fullsize;
        type Thumb = S::Thumb;
        type Alt = Set<members::alt>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `fullsize` field
        pub struct fullsize(());
        ///Marker type for the `thumb` field
        pub struct thumb(());
        ///Marker type for the `alt` field
        pub struct alt(());
    }
}

/// 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<AspectRatio<'a>>,
        Option<UriValue<'a>>,
        Option<UriValue<'a>>,
        Option<Tombstone<'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 `aspectRatio` field (optional)
    pub fn aspect_ratio(mut self, value: impl Into<Option<AspectRatio<'a>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `aspectRatio` field to an Option value (optional)
    pub fn maybe_aspect_ratio(mut self, value: Option<AspectRatio<'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> 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.3 = Option::Some(value.into());
        ViewImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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