// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.embed.gallery
//
// 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::blob::BlobRef;
use jacquard_common::types::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::app_bsky::embed::gallery;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Image<S: BosStr = DefaultStr> {
    ///Alt text description of the image, for accessibility.
    pub alt: S,
    pub aspect_ratio: AspectRatio<S>,
    pub image: BlobRef<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 Gallery<S: BosStr = DefaultStr> {
    ///The schema-level maxLength of 20 is a future-proof ceiling. Clients should currently enforce a soft limit of 10 items in authoring UIs.
    pub items: Vec<gallery::Image<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 View<S: BosStr = DefaultStr> {
    pub items: Vec<gallery::ViewImage<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 ViewImage<S: BosStr = DefaultStr> {
    ///Alt text description of the image, for accessibility.
    pub alt: S,
    pub aspect_ratio: AspectRatio<S>,
    ///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.
    pub fullsize: UriValue<S>,
    ///Fully-qualified URL where a thumbnail of the image can be fetched. For example, CDN location provided by the App View.
    pub thumbnail: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Image<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.gallery"
    }
    fn def_name() -> &'static str {
        "image"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_gallery()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.image;
            {
                let size = value.blob().size;
                if size > 2000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("image"),
                        max: 2000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.image;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/*"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("image"),
                        accepted: vec!["image/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Gallery<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.gallery"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_gallery()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.items;
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("items"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for View<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.gallery"
    }
    fn def_name() -> &'static str {
        "view"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_gallery()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ViewImage<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.gallery"
    }
    fn def_name() -> &'static str {
        "viewImage"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_gallery()
    }
    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 Alt;
        type AspectRatio;
        type Image;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Alt = Unset;
        type AspectRatio = Unset;
        type Image = Unset;
    }
    ///State transition - sets the `alt` field to Set
    pub struct SetAlt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAlt<St> {}
    impl<St: State> State for SetAlt<St> {
        type Alt = Set<members::alt>;
        type AspectRatio = St::AspectRatio;
        type Image = St::Image;
    }
    ///State transition - sets the `aspect_ratio` field to Set
    pub struct SetAspectRatio<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAspectRatio<St> {}
    impl<St: State> State for SetAspectRatio<St> {
        type Alt = St::Alt;
        type AspectRatio = Set<members::aspect_ratio>;
        type Image = St::Image;
    }
    ///State transition - sets the `image` field to Set
    pub struct SetImage<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetImage<St> {}
    impl<St: State> State for SetImage<St> {
        type Alt = St::Alt;
        type AspectRatio = St::AspectRatio;
        type Image = Set<members::image>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `alt` field
        pub struct alt(());
        ///Marker type for the `aspect_ratio` field
        pub struct aspect_ratio(());
        ///Marker type for the `image` field
        pub struct image(());
    }
}

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

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

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

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

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

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

impl<St, S: BosStr> ImageBuilder<St, S>
where
    St: image_state::State,
    St::AspectRatio: image_state::IsUnset,
{
    /// Set the `aspectRatio` field (required)
    pub fn aspect_ratio(
        mut self,
        value: impl Into<AspectRatio<S>>,
    ) -> ImageBuilder<image_state::SetAspectRatio<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ImageBuilder<St, S>
where
    St: image_state::State,
    St::Alt: image_state::IsSet,
    St::AspectRatio: image_state::IsSet,
    St::Image: image_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Image<S> {
        Image {
            alt: self._fields.0.unwrap(),
            aspect_ratio: self._fields.1.unwrap(),
            image: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Image<S> {
        Image {
            alt: self._fields.0.unwrap(),
            aspect_ratio: self._fields.1.unwrap(),
            image: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_embed_gallery() -> 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("app.bsky.embed.gallery"),
        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"),
                            SmolStr::new_static("aspectRatio")
                        ],
                    ),
                    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
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("items")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("items"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "The schema-level maxLength of 20 is a future-proof ceiling. Clients should currently enforce a soft limit of 10 items in authoring UIs.",
                                    ),
                                ),
                                items: LexArrayItem::Union(LexRefUnion {
                                    refs: vec![CowStr::new_static("#image")],
                                    ..Default::default()
                                }),
                                max_length: Some(20usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("view"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("items")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("items"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Union(LexRefUnion {
                                    refs: vec![CowStr::new_static("#viewImage")],
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viewImage"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("thumbnail"),
                            SmolStr::new_static("fullsize"), SmolStr::new_static("alt"),
                            SmolStr::new_static("aspectRatio")
                        ],
                    ),
                    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("thumbnail"),
                            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 gallery_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 Items;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Items = Unset;
    }
    ///State transition - sets the `items` field to Set
    pub struct SetItems<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetItems<St> {}
    impl<St: State> State for SetItems<St> {
        type Items = Set<members::items>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `items` field
        pub struct items(());
    }
}

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

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

impl<S: BosStr> Gallery<S> {
    /// Create a new builder for this type
    pub fn builder() -> GalleryBuilder<gallery_state::Empty, S> {
        GalleryBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> GalleryBuilder<St, S>
where
    St: gallery_state::State,
    St::Items: gallery_state::IsUnset,
{
    /// Set the `items` field (required)
    pub fn items(
        mut self,
        value: impl Into<Vec<gallery::Image<S>>>,
    ) -> GalleryBuilder<gallery_state::SetItems<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GalleryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GalleryBuilder<St, S>
where
    St: gallery_state::State,
    St::Items: gallery_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Gallery<S> {
        Gallery {
            items: 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<SmolStr, Data<S>>) -> Gallery<S> {
        Gallery {
            items: 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 Items;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Items = Unset;
    }
    ///State transition - sets the `items` field to Set
    pub struct SetItems<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetItems<St> {}
    impl<St: State> State for SetItems<St> {
        type Items = Set<members::items>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `items` field
        pub struct items(());
    }
}

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

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

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

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

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

impl<St, S: BosStr> ViewBuilder<St, S>
where
    St: view_state::State,
    St::Items: view_state::IsUnset,
{
    /// Set the `items` field (required)
    pub fn items(
        mut self,
        value: impl Into<Vec<gallery::ViewImage<S>>>,
    ) -> ViewBuilder<view_state::SetItems<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ViewBuilder<St, S>
where
    St: view_state::State,
    St::Items: view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> View<S> {
        View {
            items: 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<SmolStr, Data<S>>) -> View<S> {
        View {
            items: 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 Alt;
        type AspectRatio;
        type Fullsize;
        type Thumbnail;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Alt = Unset;
        type AspectRatio = Unset;
        type Fullsize = Unset;
        type Thumbnail = Unset;
    }
    ///State transition - sets the `alt` field to Set
    pub struct SetAlt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAlt<St> {}
    impl<St: State> State for SetAlt<St> {
        type Alt = Set<members::alt>;
        type AspectRatio = St::AspectRatio;
        type Fullsize = St::Fullsize;
        type Thumbnail = St::Thumbnail;
    }
    ///State transition - sets the `aspect_ratio` field to Set
    pub struct SetAspectRatio<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAspectRatio<St> {}
    impl<St: State> State for SetAspectRatio<St> {
        type Alt = St::Alt;
        type AspectRatio = Set<members::aspect_ratio>;
        type Fullsize = St::Fullsize;
        type Thumbnail = St::Thumbnail;
    }
    ///State transition - sets the `fullsize` field to Set
    pub struct SetFullsize<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetFullsize<St> {}
    impl<St: State> State for SetFullsize<St> {
        type Alt = St::Alt;
        type AspectRatio = St::AspectRatio;
        type Fullsize = Set<members::fullsize>;
        type Thumbnail = St::Thumbnail;
    }
    ///State transition - sets the `thumbnail` field to Set
    pub struct SetThumbnail<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetThumbnail<St> {}
    impl<St: State> State for SetThumbnail<St> {
        type Alt = St::Alt;
        type AspectRatio = St::AspectRatio;
        type Fullsize = St::Fullsize;
        type Thumbnail = Set<members::thumbnail>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `alt` field
        pub struct alt(());
        ///Marker type for the `aspect_ratio` field
        pub struct aspect_ratio(());
        ///Marker type for the `fullsize` field
        pub struct fullsize(());
        ///Marker type for the `thumbnail` field
        pub struct thumbnail(());
    }
}

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

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

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

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

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

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

impl<St, S: BosStr> ViewImageBuilder<St, S>
where
    St: view_image_state::State,
    St::AspectRatio: view_image_state::IsUnset,
{
    /// Set the `aspectRatio` field (required)
    pub fn aspect_ratio(
        mut self,
        value: impl Into<AspectRatio<S>>,
    ) -> ViewImageBuilder<view_image_state::SetAspectRatio<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ViewImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ViewImageBuilder<St, S>
where
    St: view_image_state::State,
    St::Thumbnail: view_image_state::IsUnset,
{
    /// Set the `thumbnail` field (required)
    pub fn thumbnail(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> ViewImageBuilder<view_image_state::SetThumbnail<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ViewImageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ViewImageBuilder<St, S>
where
    St: view_image_state::State,
    St::Alt: view_image_state::IsSet,
    St::AspectRatio: view_image_state::IsSet,
    St::Fullsize: view_image_state::IsSet,
    St::Thumbnail: view_image_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ViewImage<S> {
        ViewImage {
            alt: self._fields.0.unwrap(),
            aspect_ratio: self._fields.1.unwrap(),
            fullsize: self._fields.2.unwrap(),
            thumbnail: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ViewImage<S> {
        ViewImage {
            alt: self._fields.0.unwrap(),
            aspect_ratio: self._fields.1.unwrap(),
            fullsize: self._fields.2.unwrap(),
            thumbnail: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}