// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.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::{Datetime, 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::actor::ProfileViewBasic;
use crate::com_atproto::label::Label;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::app_bsky::embed::external;
/// RGB color definition, inspired by site.standard.theme.color#rgb

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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct External<S: BosStr = DefaultStr> {
    ///StrongRefs (uri+cid) of the Atmosphere records that backed this view.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub associated_refs: Option<Vec<StrongRef<S>>>,
    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>>>,
}

/// A representation of some externally linked content (eg, a URL and 'card'), embedded in a Bluesky record (eg, a post).

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ExternalRecord<S: BosStr = DefaultStr> {
    pub external: external::External<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: 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> {
    ///Profiles of the owners of the Atmosphere records that backed this view.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub associated_profiles: Option<Vec<ProfileViewBasic<S>>>,
    ///StrongRefs (uri+cid) of the Atmosphere records that backed this view.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub associated_refs: Option<Vec<StrongRef<S>>>,
    ///When the external content was created, if available. Example: a publication date, for an article.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    pub description: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub labels: Option<Vec<Label<S>>>,
    ///Estimated reading time in minutes, if applicable and available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reading_time: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<external::ViewExternalSource<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumb: Option<UriValue<S>>,
    pub title: S,
    ///When the external content was updated, if available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    pub uri: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// The source of an external embed, such as a standard.site publication.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ViewExternalSource<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///Fully-qualified URL where an icon representing the source can be fetched. For example, CDN location provided by the App View.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub icon: Option<UriValue<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub theme: Option<external::ViewExternalSourceTheme<S>>,
    pub title: S,
    ///URI of the source, if available. Example: the https:// URL of a site.standard.publication record.
    pub uri: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// The theme colors of an external source, such as a site.standard.publication. These colors may be used when rendering an embed from that source.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ViewExternalSourceTheme<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accent_foreground_rgb: Option<external::ColorRgb<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub accent_rgb: Option<external::ColorRgb<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub background_rgb: Option<external::ColorRgb<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub foreground_rgb: Option<external::ColorRgb<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ColorRgb<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.external"
    }
    fn def_name() -> &'static str {
        "colorRGB"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_external()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.b;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("b"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.b;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("b"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.g;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("g"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.g;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("g"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.r;
            if *value > 255i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("r"),
                    max: 255i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.r;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("r"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for External<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.external"
    }
    fn def_name() -> &'static str {
        "external"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_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 ExternalRecord<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.external"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_external()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

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

pub mod color_rgb_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 B;
        type G;
        type R;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type B = Unset;
        type G = Unset;
        type R = Unset;
    }
    ///State transition - sets the `b` field to Set
    pub struct SetB<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetB<St> {}
    impl<St: State> State for SetB<St> {
        type B = Set<members::b>;
        type G = St::G;
        type R = St::R;
    }
    ///State transition - sets the `g` field to Set
    pub struct SetG<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetG<St> {}
    impl<St: State> State for SetG<St> {
        type B = St::B;
        type G = Set<members::g>;
        type R = St::R;
    }
    ///State transition - sets the `r` field to Set
    pub struct SetR<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetR<St> {}
    impl<St: State> State for SetR<St> {
        type B = St::B;
        type G = St::G;
        type R = Set<members::r>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `b` field
        pub struct b(());
        ///Marker type for the `g` field
        pub struct g(());
        ///Marker type for the `r` field
        pub struct r(());
    }
}

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

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

impl<S: BosStr> ColorRgb<S> {
    /// Create a new builder for this type
    pub fn builder() -> ColorRgbBuilder<color_rgb_state::Empty, S> {
        ColorRgbBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ColorRgbBuilder<St, S>
where
    St: color_rgb_state::State,
    St::B: color_rgb_state::IsUnset,
{
    /// Set the `b` field (required)
    pub fn b(
        mut self,
        value: impl Into<i64>,
    ) -> ColorRgbBuilder<color_rgb_state::SetB<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ColorRgbBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ColorRgbBuilder<St, S>
where
    St: color_rgb_state::State,
    St::R: color_rgb_state::IsUnset,
{
    /// Set the `r` field (required)
    pub fn r(
        mut self,
        value: impl Into<i64>,
    ) -> ColorRgbBuilder<color_rgb_state::SetR<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ColorRgbBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ColorRgbBuilder<St, S>
where
    St: color_rgb_state::State,
    St::B: color_rgb_state::IsSet,
    St::G: color_rgb_state::IsSet,
    St::R: color_rgb_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ColorRgb<S> {
        ColorRgb {
            b: self._fields.0.unwrap(),
            g: self._fields.1.unwrap(),
            r: 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>>) -> ColorRgb<S> {
        ColorRgb {
            b: self._fields.0.unwrap(),
            g: self._fields.1.unwrap(),
            r: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_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("app.bsky.embed.external"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("colorRGB"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "RGB color definition, inspired by site.standard.theme.color#rgb",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("r"), SmolStr::new_static("g"),
                            SmolStr::new_static("b")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("b"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("g"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("r"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(255i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("external"),
                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("associatedRefs"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "StrongRefs (uri+cid) of the Atmosphere records that backed this view.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        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 {
                    description: Some(
                        CowStr::new_static(
                            "A representation of some externally linked content (eg, a URL and 'card'), embedded in a Bluesky record (eg, a post).",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("external")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("external"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#external"),
                                ..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::Ref(LexRef {
                                r#ref: CowStr::new_static("#viewExternal"),
                                ..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("associatedProfiles"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Profiles of the owners of the Atmosphere records that backed this view.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "app.bsky.actor.defs#profileViewBasic",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("associatedRefs"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "StrongRefs (uri+cid) of the Atmosphere records that backed this view.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "When the external content was created, if available. Example: a publication date, for an article.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("labels"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.label.defs#label"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("readingTime"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("source"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#viewExternalSource"),
                                ..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("updatedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "When the external content was updated, if available.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..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("viewExternalSource"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "The source of an external embed, such as a standard.site publication.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("title")],
                    ),
                    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("icon"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Fully-qualified URL where an icon representing the source can be fetched. For example, CDN location provided by the App View.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("theme"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#viewExternalSourceTheme"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "URI of the source, if available. Example: the https:// URL of a site.standard.publication record.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viewExternalSourceTheme"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "The theme colors of an external source, such as a site.standard.publication. These colors may be used when rendering an embed from that source.",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("accentForegroundRGB"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#colorRGB"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("accentRGB"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#colorRGB"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("backgroundRGB"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#colorRGB"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("foregroundRGB"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#colorRGB"),
                                ..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 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 ExternalBuilder<St: external_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<StrongRef<S>>>,
        Option<S>,
        Option<BlobRef<S>>,
        Option<S>,
        Option<UriValue<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, None, None, None, 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, None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St: external_state::State, S: BosStr> ExternalBuilder<St, S> {
    /// Set the `associatedRefs` field (optional)
    pub fn associated_refs(
        mut self,
        value: impl Into<Option<Vec<StrongRef<S>>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `associatedRefs` field to an Option value (optional)
    pub fn maybe_associated_refs(mut self, value: Option<Vec<StrongRef<S>>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: external_state::State, S: BosStr> ExternalBuilder<St, S> {
    /// Set the `thumb` field (optional)
    pub fn thumb(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.2 = 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.2 = value;
        self
    }
}

impl<St, S: BosStr> ExternalBuilder<St, S>
where
    St: external_state::State,
    St::Title: external_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> ExternalBuilder<external_state::SetTitle<St>, S> {
        self._fields.3 = 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::Uri: external_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> ExternalBuilder<external_state::SetUri<St>, S> {
        self._fields.4 = 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::Description: external_state::IsSet,
    St::Title: external_state::IsSet,
    St::Uri: external_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> External<S> {
        External {
            associated_refs: self._fields.0,
            description: self._fields.1.unwrap(),
            thumb: self._fields.2,
            title: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> External<S> {
        External {
            associated_refs: self._fields.0,
            description: self._fields.1.unwrap(),
            thumb: self._fields.2,
            title: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod external_record_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 ExternalRecordBuilder<
    St: external_record_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<external::External<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> ExternalRecord<S> {
    /// Create a new builder for this type
    pub fn builder() -> ExternalRecordBuilder<external_record_state::Empty, S> {
        ExternalRecordBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ExternalRecordBuilder<St, S>
where
    St: external_record_state::State,
    St::External: external_record_state::IsUnset,
{
    /// Set the `external` field (required)
    pub fn external(
        mut self,
        value: impl Into<external::External<S>>,
    ) -> ExternalRecordBuilder<external_record_state::SetExternal<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ExternalRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ExternalRecordBuilder<St, S>
where
    St: external_record_state::State,
    St::External: external_record_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ExternalRecord<S> {
        ExternalRecord {
            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>>,
    ) -> ExternalRecord<S> {
        ExternalRecord {
            external: 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<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<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<Vec<ProfileViewBasic<S>>>,
        Option<Vec<StrongRef<S>>>,
        Option<Datetime>,
        Option<S>,
        Option<Vec<Label<S>>>,
        Option<i64>,
        Option<external::ViewExternalSource<S>>,
        Option<UriValue<S>>,
        Option<S>,
        Option<Datetime>,
        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, None, None, None, 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, None, None, None, None, None, None, None),
            _type: PhantomData,
        }
    }
}

impl<St: view_external_state::State, S: BosStr> ViewExternalBuilder<St, S> {
    /// Set the `associatedProfiles` field (optional)
    pub fn associated_profiles(
        mut self,
        value: impl Into<Option<Vec<ProfileViewBasic<S>>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `associatedProfiles` field to an Option value (optional)
    pub fn maybe_associated_profiles(
        mut self,
        value: Option<Vec<ProfileViewBasic<S>>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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.3 = 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 `labels` field (optional)
    pub fn labels(mut self, value: impl Into<Option<Vec<Label<S>>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `labels` field to an Option value (optional)
    pub fn maybe_labels(mut self, value: Option<Vec<Label<S>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

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

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.7 = 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.7 = 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.8 = 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 `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `updatedAt` field to an Option value (optional)
    pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.9 = value;
        self
    }
}

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.10 = 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 {
            associated_profiles: self._fields.0,
            associated_refs: self._fields.1,
            created_at: self._fields.2,
            description: self._fields.3.unwrap(),
            labels: self._fields.4,
            reading_time: self._fields.5,
            source: self._fields.6,
            thumb: self._fields.7,
            title: self._fields.8.unwrap(),
            updated_at: self._fields.9,
            uri: self._fields.10.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 {
            associated_profiles: self._fields.0,
            associated_refs: self._fields.1,
            created_at: self._fields.2,
            description: self._fields.3.unwrap(),
            labels: self._fields.4,
            reading_time: self._fields.5,
            source: self._fields.6,
            thumb: self._fields.7,
            title: self._fields.8.unwrap(),
            updated_at: self._fields.9,
            uri: self._fields.10.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod view_external_source_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 Title;
        type Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Title = Unset;
        type Uri = Unset;
    }
    ///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 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 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 `title` field
        pub struct title(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> ViewExternalSource<S> {
    /// Create a new builder for this type
    pub fn builder() -> ViewExternalSourceBuilder<view_external_source_state::Empty, S> {
        ViewExternalSourceBuilder::builder()
    }
}

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

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

impl<St: view_external_source_state::State, S: BosStr> ViewExternalSourceBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: view_external_source_state::State, S: BosStr> ViewExternalSourceBuilder<St, S> {
    /// Set the `theme` field (optional)
    pub fn theme(
        mut self,
        value: impl Into<Option<external::ViewExternalSourceTheme<S>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `theme` field to an Option value (optional)
    pub fn maybe_theme(
        mut self,
        value: Option<external::ViewExternalSourceTheme<S>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

impl<St, S: BosStr> ViewExternalSourceBuilder<St, S>
where
    St: view_external_source_state::State,
    St::Title: view_external_source_state::IsSet,
    St::Uri: view_external_source_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ViewExternalSource<S> {
        ViewExternalSource {
            description: self._fields.0,
            icon: self._fields.1,
            theme: self._fields.2,
            title: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ViewExternalSource<S> {
        ViewExternalSource {
            description: self._fields.0,
            icon: self._fields.1,
            theme: self._fields.2,
            title: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}