// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.weaver.embed.external
//
// 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::sh_weaver::embed::external;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ExternalEmbed<S: BosStr = DefaultStr> {
    pub description: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumb: Option<BlobRef<S>>,
    pub title: S,
    pub uri: UriValue<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 External<S: BosStr = DefaultStr> {
    pub embeds: Vec<external::ExternalEmbed<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 external: Vec<external::ViewExternal<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 ViewExternal<S: BosStr = DefaultStr> {
    pub description: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumb: Option<UriValue<S>>,
    pub title: S,
    pub uri: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ExternalEmbed<S> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.external"
    }
    fn def_name() -> &'static str {
        "externalEmbed"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_external()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.thumb {
            {
                let size = value.blob().size;
                if size > 1000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("thumb"),
                        max: 1000000usize,
                        actual: size,
                    });
                }
            }
        }
        if let Some(ref value) = self.thumb {
            {
                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("thumb"),
                        accepted: vec!["image/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

impl<S: BosStr> LexiconSchema for ViewExternal<S> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.external"
    }
    fn def_name() -> &'static str {
        "viewExternal"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_external()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod external_embed_state {

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

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

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

impl<S: BosStr> ExternalEmbed<S> {
    /// Create a new builder for this type
    pub fn builder() -> ExternalEmbedBuilder<external_embed_state::Empty, S> {
        ExternalEmbedBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ExternalEmbedBuilder<St, S>
where
    St: external_embed_state::State,
    St::Description: external_embed_state::IsUnset,
{
    /// Set the `description` field (required)
    pub fn description(
        mut self,
        value: impl Into<S>,
    ) -> ExternalEmbedBuilder<external_embed_state::SetDescription<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ExternalEmbedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ExternalEmbedBuilder<St, S>
where
    St: external_embed_state::State,
    St::Title: external_embed_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> ExternalEmbedBuilder<external_embed_state::SetTitle<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ExternalEmbedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ExternalEmbedBuilder<St, S>
where
    St: external_embed_state::State,
    St::Description: external_embed_state::IsSet,
    St::Title: external_embed_state::IsSet,
    St::Uri: external_embed_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ExternalEmbed<S> {
        ExternalEmbed {
            description: self._fields.0.unwrap(),
            thumb: self._fields.1,
            title: self._fields.2.unwrap(),
            uri: 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>>,
    ) -> ExternalEmbed<S> {
        ExternalEmbed {
            description: self._fields.0.unwrap(),
            thumb: self._fields.1,
            title: self._fields.2.unwrap(),
            uri: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_embed_external() -> 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.external"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("externalEmbed"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("title"),
                            SmolStr::new_static("description")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("thumb"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("embeds")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("embeds"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#externalEmbed"),
                                    ..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("external")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("external"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#viewExternal"),
                                    ..Default::default()
                                }),
                                max_length: Some(48usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viewExternal"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("title"),
                            SmolStr::new_static("description")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("thumb"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> External<S> {
    /// Create a new builder for this type
    pub fn builder() -> ExternalBuilder<external_state::Empty, S> {
        ExternalBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ExternalBuilder<St, S>
where
    St: external_state::State,
    St::Embeds: external_state::IsUnset,
{
    /// Set the `embeds` field (required)
    pub fn embeds(
        mut self,
        value: impl Into<Vec<external::ExternalEmbed<S>>>,
    ) -> ExternalBuilder<external_state::SetEmbeds<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ExternalBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

/// 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<external::ViewExternal<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::External: view_state::IsUnset,
{
    /// Set the `external` field (required)
    pub fn external(
        mut self,
        value: impl Into<Vec<external::ViewExternal<S>>>,
    ) -> ViewBuilder<view_state::SetExternal<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::External: view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> View<S> {
        View {
            external: 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 {
            external: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod view_external_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 Description;
        type Title;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Description = Unset;
        type Title = Unset;
        type Uri = Unset;
    }
    ///State transition - sets the `description` field to Set
    pub struct SetDescription<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDescription<St> {}
    impl<St: State> State for SetDescription<St> {
        type Description = Set<members::description>;
        type Title = St::Title;
        type Uri = St::Uri;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type Description = St::Description;
        type Title = Set<members::title>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Description = St::Description;
        type Title = St::Title;
        type Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `description` field
        pub struct description(());
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> ViewExternal<S> {
    /// Create a new builder for this type
    pub fn builder() -> ViewExternalBuilder<view_external_state::Empty, S> {
        ViewExternalBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ViewExternalBuilder<St, S>
where
    St: view_external_state::State,
    St::Description: view_external_state::IsUnset,
{
    /// Set the `description` field (required)
    pub fn description(
        mut self,
        value: impl Into<S>,
    ) -> ViewExternalBuilder<view_external_state::SetDescription<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ViewExternalBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ViewExternalBuilder<St, S>
where
    St: view_external_state::State,
    St::Title: view_external_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> ViewExternalBuilder<view_external_state::SetTitle<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ViewExternalBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ViewExternalBuilder<St, S>
where
    St: view_external_state::State,
    St::Description: view_external_state::IsSet,
    St::Title: view_external_state::IsSet,
    St::Uri: view_external_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ViewExternal<S> {
        ViewExternal {
            description: self._fields.0.unwrap(),
            thumb: self._fields.1,
            title: self._fields.2.unwrap(),
            uri: 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>>,
    ) -> ViewExternal<S> {
        ViewExternal {
            description: self._fields.0.unwrap(),
            thumb: self._fields.1,
            title: self._fields.2.unwrap(),
            uri: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}