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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::blob::BlobRef;
use jacquard_common::types::string::{Cid, Language, UriValue};
use jacquard_derive::{IntoStatic, lexicon, open_union};
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::sh_weaver::embed::PercentSize;
use crate::sh_weaver::embed::PixelSize;
use crate::sh_weaver::embed::video;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Caption<'a> {
    #[serde(borrow)]
    pub file: BlobRef<'a>,
    pub lang: Language,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct VideoRecord<'a> {
    #[serde(borrow)]
    pub videos: Vec<video::Video<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Video<'a> {
    ///Alt text description of the video, for accessibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub alt: Option<CowStr<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub captions: Option<Vec<video::Caption<'a>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub dimensions: Option<VideoDimensions<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    ///The mp4 video file. May be up to 100mb, formerly limited to 50mb.
    #[serde(borrow)]
    pub video: BlobRef<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum VideoDimensions<'a> {
    #[serde(rename = "app.bsky.embed.defs#aspectRatio")]
    AspectRatio(Box<AspectRatio<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#percentSize")]
    PercentSize(Box<PercentSize<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#pixelSize")]
    PixelSize(Box<PixelSize<'a>>),
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct View<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub alt: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub cid: Cid<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub dimensions: Option<ViewDimensions<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub playlist: UriValue<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub thumbnail: Option<UriValue<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ViewDimensions<'a> {
    #[serde(rename = "app.bsky.embed.defs#aspectRatio")]
    AspectRatio(Box<AspectRatio<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#percentSize")]
    PercentSize(Box<PercentSize<'a>>),
    #[serde(rename = "sh.weaver.embed.defs#pixelSize")]
    PixelSize(Box<PixelSize<'a>>),
}

impl<'a> LexiconSchema for Caption<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.video"
    }
    fn def_name() -> &'static str {
        "caption"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_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<'a> LexiconSchema for VideoRecord<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.video"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_embed_video()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for Video<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.video"
    }
    fn def_name() -> &'static str {
        "video"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_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(),
                });
            }
        }
        if let Some(ref value) = self.name {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            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<'a> LexiconSchema for View<'a> {
    fn nsid() -> &'static str {
        "sh.weaver.embed.video"
    }
    fn def_name() -> &'static str {
        "view"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_weaver_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.name {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 128usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 128usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        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 Lang;
        type File;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Lang = Unset;
        type File = Unset;
    }
    ///State transition - sets the `lang` field to Set
    pub struct SetLang<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLang<S> {}
    impl<S: State> State for SetLang<S> {
        type Lang = Set<members::lang>;
        type File = S::File;
    }
    ///State transition - sets the `file` field to Set
    pub struct SetFile<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetFile<S> {}
    impl<S: State> State for SetFile<S> {
        type Lang = S::Lang;
        type File = Set<members::file>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `lang` field
        pub struct lang(());
        ///Marker type for the `file` field
        pub struct file(());
    }
}

/// Builder for constructing an instance of this type
pub struct CaptionBuilder<'a, S: caption_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<BlobRef<'a>>, Option<Language>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> CaptionBuilder<'a, S>
where
    S: caption_state::State,
    S::Lang: caption_state::IsSet,
    S::File: caption_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Caption<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Caption<'a> {
        Caption {
            file: self._fields.0.unwrap(),
            lang: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_weaver_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("sh.weaver.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("videos")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("videos"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#video"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("video"),
                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("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("dimensions"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("app.bsky.embed.defs#aspectRatio"),
                                    CowStr::new_static("sh.weaver.embed.defs#percentSize"),
                                    CowStr::new_static("sh.weaver.embed.defs#pixelSize")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..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("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("dimensions"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("app.bsky.embed.defs#aspectRatio"),
                                    CowStr::new_static("sh.weaver.embed.defs#percentSize"),
                                    CowStr::new_static("sh.weaver.embed.defs#pixelSize")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("playlist"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..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_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 Videos;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Videos = Unset;
    }
    ///State transition - sets the `videos` field to Set
    pub struct SetVideos<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetVideos<S> {}
    impl<S: State> State for SetVideos<S> {
        type Videos = Set<members::videos>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `videos` field
        pub struct videos(());
    }
}

/// Builder for constructing an instance of this type
pub struct VideoRecordBuilder<'a, S: video_record_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Vec<video::Video<'a>>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> VideoRecord<'a> {
    /// Create a new builder for this type
    pub fn new() -> VideoRecordBuilder<'a, video_record_state::Empty> {
        VideoRecordBuilder::new()
    }
}

impl<'a> VideoRecordBuilder<'a, video_record_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        VideoRecordBuilder {
            _state: PhantomData,
            _fields: (None,),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> VideoRecordBuilder<'a, S>
where
    S: video_record_state::State,
    S::Videos: video_record_state::IsUnset,
{
    /// Set the `videos` field (required)
    pub fn videos(
        mut self,
        value: impl Into<Vec<video::Video<'a>>>,
    ) -> VideoRecordBuilder<'a, video_record_state::SetVideos<S>> {
        self._fields.0 = Option::Some(value.into());
        VideoRecordBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> VideoRecordBuilder<'a, S>
where
    S: video_record_state::State,
    S::Videos: video_record_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> VideoRecord<'a> {
        VideoRecord {
            videos: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> VideoRecord<'a> {
        VideoRecord {
            videos: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetVideo<S> {}
    impl<S: State> State for SetVideo<S> {
        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<'a, S: video_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<Vec<video::Caption<'a>>>,
        Option<VideoDimensions<'a>>,
        Option<CowStr<'a>>,
        Option<BlobRef<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: video_state::State> VideoBuilder<'a, S> {
    /// Set the `dimensions` field (optional)
    pub fn dimensions(mut self, value: impl Into<Option<VideoDimensions<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `dimensions` field to an Option value (optional)
    pub fn maybe_dimensions(mut self, value: Option<VideoDimensions<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

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

impl<'a, S> VideoBuilder<'a, S>
where
    S: video_state::State,
    S::Video: video_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Video<'a> {
        Video {
            alt: self._fields.0,
            captions: self._fields.1,
            dimensions: self._fields.2,
            name: 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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Video<'a> {
        Video {
            alt: self._fields.0,
            captions: self._fields.1,
            dimensions: self._fields.2,
            name: 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCid<S> {}
    impl<S: State> State for SetCid<S> {
        type Cid = Set<members::cid>;
        type Playlist = S::Playlist;
    }
    ///State transition - sets the `playlist` field to Set
    pub struct SetPlaylist<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPlaylist<S> {}
    impl<S: State> State for SetPlaylist<S> {
        type Cid = S::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<'a, S: view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<Cid<'a>>,
        Option<ViewDimensions<'a>>,
        Option<CowStr<'a>>,
        Option<UriValue<'a>>,
        Option<UriValue<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> ViewBuilder<'a, S>
where
    S: view_state::State,
    S::Cid: view_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<'a>>,
    ) -> ViewBuilder<'a, view_state::SetCid<S>> {
        self._fields.1 = Option::Some(value.into());
        ViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: view_state::State> ViewBuilder<'a, S> {
    /// Set the `dimensions` field (optional)
    pub fn dimensions(mut self, value: impl Into<Option<ViewDimensions<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `dimensions` field to an Option value (optional)
    pub fn maybe_dimensions(mut self, value: Option<ViewDimensions<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<'a, S> ViewBuilder<'a, S>
where
    S: view_state::State,
    S::Playlist: view_state::IsUnset,
{
    /// Set the `playlist` field (required)
    pub fn playlist(
        mut self,
        value: impl Into<UriValue<'a>>,
    ) -> ViewBuilder<'a, view_state::SetPlaylist<S>> {
        self._fields.4 = Option::Some(value.into());
        ViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: view_state::State> ViewBuilder<'a, S> {
    /// Set the `thumbnail` field (optional)
    pub fn thumbnail(mut self, value: impl Into<Option<UriValue<'a>>>) -> 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<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S> ViewBuilder<'a, S>
where
    S: view_state::State,
    S::Cid: view_state::IsSet,
    S::Playlist: view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> View<'a> {
        View {
            alt: self._fields.0,
            cid: self._fields.1.unwrap(),
            dimensions: self._fields.2,
            name: self._fields.3,
            playlist: self._fields.4.unwrap(),
            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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> View<'a> {
        View {
            alt: self._fields.0,
            cid: self._fields.1.unwrap(),
            dimensions: self._fields.2,
            name: self._fields.3,
            playlist: self._fields.4.unwrap(),
            thumbnail: self._fields.5,
            extra_data: Some(extra_data),
        }
    }
}