// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.embed.video
//
// 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::{Cid, Language, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Caption<S: BosStr = DefaultStr> {
    pub file: BlobRef<S>,
    pub lang: Language,
    #[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 Video<S: BosStr = DefaultStr> {
    ///Alt text description of the video, for accessibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alt: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub aspect_ratio: Option<AspectRatio<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub captions: Option<Vec<video::Caption<S>>>,
    ///A hint to the client about how to present the video.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub presentation: Option<VideoPresentation<S>>,
    ///The mp4 video file. May be up to 100mb, formerly limited to 50mb.
    pub video: BlobRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A hint to the client about how to present the video.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum VideoPresentation<S: BosStr = DefaultStr> {
    Default,
    Gif,
    Other(S),
}

impl<S: BosStr> VideoPresentation<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Default => "default",
            Self::Gif => "gif",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "default" => Self::Default,
            "gif" => Self::Gif,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for VideoPresentation<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for VideoPresentation<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for VideoPresentation<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for VideoPresentation<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for VideoPresentation<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for VideoPresentation<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = VideoPresentation<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            VideoPresentation::Default => VideoPresentation::Default,
            VideoPresentation::Gif => VideoPresentation::Gif,
            VideoPresentation::Other(v) => VideoPresentation::Other(v.into_static()),
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct View<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alt: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub aspect_ratio: Option<AspectRatio<S>>,
    pub cid: Cid<S>,
    pub playlist: UriValue<S>,
    ///A hint to the client about how to present the video.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub presentation: Option<ViewPresentation<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumbnail: Option<UriValue<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A hint to the client about how to present the video.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ViewPresentation<S: BosStr = DefaultStr> {
    Default,
    Gif,
    Other(S),
}

impl<S: BosStr> ViewPresentation<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Default => "default",
            Self::Gif => "gif",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "default" => Self::Default,
            "gif" => Self::Gif,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for ViewPresentation<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for ViewPresentation<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for ViewPresentation<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for ViewPresentation<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for ViewPresentation<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for ViewPresentation<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ViewPresentation<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ViewPresentation::Default => ViewPresentation::Default,
            ViewPresentation::Gif => ViewPresentation::Gif,
            ViewPresentation::Other(v) => ViewPresentation::Other(v.into_static()),
        }
    }
}

impl<S: BosStr> LexiconSchema for Caption<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.video"
    }
    fn def_name() -> &'static str {
        "caption"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_video()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.file;
            {
                let size = value.blob().size;
                if size > 20000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("file"),
                        max: 20000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.file;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["text/vtt"];
                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("file"),
                        accepted: vec!["text/vtt".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Video<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.video"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_video()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.alt {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.alt {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("alt"),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.captions {
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("captions"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.video;
            {
                let size = value.blob().size;
                if size > 100000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("video"),
                        max: 100000000usize,
                        actual: size,
                    });
                }
            }
        }
        {
            let value = &self.video;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["video/mp4"];
                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("video"),
                        accepted: vec!["video/mp4".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for View<S> {
    fn nsid() -> &'static str {
        "app.bsky.embed.video"
    }
    fn def_name() -> &'static str {
        "view"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_embed_video()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.alt {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("alt"),
                    max: 10000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.alt {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("alt"),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Caption<S> {
    /// Create a new builder for this type
    pub fn builder() -> CaptionBuilder<caption_state::Empty, S> {
        CaptionBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> CaptionBuilder<St, S>
where
    St: caption_state::State,
    St::File: caption_state::IsUnset,
{
    /// Set the `file` field (required)
    pub fn file(
        mut self,
        value: impl Into<BlobRef<S>>,
    ) -> CaptionBuilder<caption_state::SetFile<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CaptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CaptionBuilder<St, S>
where
    St: caption_state::State,
    St::Lang: caption_state::IsUnset,
{
    /// Set the `lang` field (required)
    pub fn lang(
        mut self,
        value: impl Into<Language>,
    ) -> CaptionBuilder<caption_state::SetLang<St>, S> {
        self._fields.1 = Option::Some(value.into());
        CaptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CaptionBuilder<St, S>
where
    St: caption_state::State,
    St::File: caption_state::IsSet,
    St::Lang: caption_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Caption<S> {
        Caption {
            file: self._fields.0.unwrap(),
            lang: self._fields.1.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>>) -> Caption<S> {
        Caption {
            file: self._fields.0.unwrap(),
            lang: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_embed_video() -> 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.video"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("caption"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("lang"), SmolStr::new_static("file")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("file"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("lang"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Language),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("video")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Alt text description of the video, for accessibility.",
                                    ),
                                ),
                                max_length: Some(10000usize),
                                max_graphemes: Some(1000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.embed.defs#aspectRatio",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("captions"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#caption"),
                                    ..Default::default()
                                }),
                                max_length: Some(20usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("presentation"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "A hint to the client about how to present the video.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("video"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("view"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("cid"), SmolStr::new_static("playlist")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("alt"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(10000usize),
                                max_graphemes: Some(1000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("aspectRatio"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.embed.defs#aspectRatio",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("playlist"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("presentation"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "A hint to the client about how to present the video.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("thumbnail"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> Video<S> {
    /// Create a new builder for this type
    pub fn builder() -> VideoBuilder<video_state::Empty, S> {
        VideoBuilder::builder()
    }
}

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

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

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

impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
    /// Set the `aspectRatio` field (optional)
    pub fn aspect_ratio(mut self, value: impl Into<Option<AspectRatio<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `aspectRatio` field to an Option value (optional)
    pub fn maybe_aspect_ratio(mut self, value: Option<AspectRatio<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
    /// Set the `captions` field (optional)
    pub fn captions(mut self, value: impl Into<Option<Vec<video::Caption<S>>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `captions` field to an Option value (optional)
    pub fn maybe_captions(mut self, value: Option<Vec<video::Caption<S>>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: video_state::State, S: BosStr> VideoBuilder<St, S> {
    /// Set the `presentation` field (optional)
    pub fn presentation(
        mut self,
        value: impl Into<Option<VideoPresentation<S>>>,
    ) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `presentation` field to an Option value (optional)
    pub fn maybe_presentation(mut self, value: Option<VideoPresentation<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> VideoBuilder<St, S>
where
    St: video_state::State,
    St::Video: video_state::IsUnset,
{
    /// Set the `video` field (required)
    pub fn video(
        mut self,
        value: impl Into<BlobRef<S>>,
    ) -> VideoBuilder<video_state::SetVideo<St>, S> {
        self._fields.4 = Option::Some(value.into());
        VideoBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoBuilder<St, S>
where
    St: video_state::State,
    St::Video: video_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Video<S> {
        Video {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            captions: self._fields.2,
            presentation: self._fields.3,
            video: 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>>) -> Video<S> {
        Video {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            captions: self._fields.2,
            presentation: self._fields.3,
            video: self._fields.4.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 Cid;
        type Playlist;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Cid = Unset;
        type Playlist = Unset;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCid<St> {}
    impl<St: State> State for SetCid<St> {
        type Cid = Set<members::cid>;
        type Playlist = St::Playlist;
    }
    ///State transition - sets the `playlist` field to Set
    pub struct SetPlaylist<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPlaylist<St> {}
    impl<St: State> State for SetPlaylist<St> {
        type Cid = St::Cid;
        type Playlist = Set<members::playlist>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `playlist` field
        pub struct playlist(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ViewBuilder<St: view_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<AspectRatio<S>>,
        Option<Cid<S>>,
        Option<UriValue<S>>,
        Option<ViewPresentation<S>>,
        Option<UriValue<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, None, None, None, None, 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, None, None, None, None, None),
            _type: PhantomData,
        }
    }
}

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

impl<St: view_state::State, S: BosStr> ViewBuilder<St, S> {
    /// Set the `aspectRatio` field (optional)
    pub fn aspect_ratio(mut self, value: impl Into<Option<AspectRatio<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `aspectRatio` field to an Option value (optional)
    pub fn maybe_aspect_ratio(mut self, value: Option<AspectRatio<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> ViewBuilder<St, S>
where
    St: view_state::State,
    St::Cid: view_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> ViewBuilder<view_state::SetCid<St>, S> {
        self._fields.2 = 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::Playlist: view_state::IsUnset,
{
    /// Set the `playlist` field (required)
    pub fn playlist(
        mut self,
        value: impl Into<UriValue<S>>,
    ) -> ViewBuilder<view_state::SetPlaylist<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: view_state::State, S: BosStr> ViewBuilder<St, S> {
    /// Set the `presentation` field (optional)
    pub fn presentation(
        mut self,
        value: impl Into<Option<ViewPresentation<S>>>,
    ) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `presentation` field to an Option value (optional)
    pub fn maybe_presentation(mut self, value: Option<ViewPresentation<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: view_state::State, S: BosStr> ViewBuilder<St, S> {
    /// Set the `thumbnail` field (optional)
    pub fn thumbnail(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `thumbnail` field to an Option value (optional)
    pub fn maybe_thumbnail(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St, S: BosStr> ViewBuilder<St, S>
where
    St: view_state::State,
    St::Cid: view_state::IsSet,
    St::Playlist: view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> View<S> {
        View {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            cid: self._fields.2.unwrap(),
            playlist: self._fields.3.unwrap(),
            presentation: self._fields.4,
            thumbnail: self._fields.5,
            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 {
            alt: self._fields.0,
            aspect_ratio: self._fields.1,
            cid: self._fields.2.unwrap(),
            playlist: self._fields.3.unwrap(),
            presentation: self._fields.4,
            thumbnail: self._fields.5,
            extra_data: Some(extra_data),
        }
    }
}