// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.stream.richtext.videoFacet
//
// 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::{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::value::Data;
use jacquard_derive::{IntoStatic, 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::richtext::facet::ByteSlice;
use crate::app_bsky::richtext::facet::Link;
use crate::app_bsky::richtext::facet::Mention;
/// Annotation of a sub-string within rich text in a VOD description or comment.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct VideoFacet<S: BosStr = DefaultStr> {
    pub features: Vec<VideoFacetFeaturesItem<S>>,
    pub index: ByteSlice<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum VideoFacetFeaturesItem<S: BosStr = DefaultStr> {
    #[serde(rename = "app.bsky.richtext.facet#mention")]
    FacetMention(Box<Mention<S>>),
    #[serde(rename = "app.bsky.richtext.facet#link")]
    FacetLink(Box<Link<S>>),
}

impl<S: BosStr> LexiconSchema for VideoFacet<S> {
    fn nsid() -> &'static str {
        "place.stream.richtext.videoFacet"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_richtext_videoFacet()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

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

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

impl<S: BosStr> VideoFacet<S> {
    /// Create a new builder for this type
    pub fn builder() -> VideoFacetBuilder<video_facet_state::Empty, S> {
        VideoFacetBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> VideoFacetBuilder<St, S>
where
    St: video_facet_state::State,
    St::Features: video_facet_state::IsUnset,
{
    /// Set the `features` field (required)
    pub fn features(
        mut self,
        value: impl Into<Vec<VideoFacetFeaturesItem<S>>>,
    ) -> VideoFacetBuilder<video_facet_state::SetFeatures<St>, S> {
        self._fields.0 = Option::Some(value.into());
        VideoFacetBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoFacetBuilder<St, S>
where
    St: video_facet_state::State,
    St::Index: video_facet_state::IsUnset,
{
    /// Set the `index` field (required)
    pub fn index(
        mut self,
        value: impl Into<ByteSlice<S>>,
    ) -> VideoFacetBuilder<video_facet_state::SetIndex<St>, S> {
        self._fields.1 = Option::Some(value.into());
        VideoFacetBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoFacetBuilder<St, S>
where
    St: video_facet_state::State,
    St::Features: video_facet_state::IsSet,
    St::Index: video_facet_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> VideoFacet<S> {
        VideoFacet {
            features: self._fields.0.unwrap(),
            index: 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>>,
    ) -> VideoFacet<S> {
        VideoFacet {
            features: self._fields.0.unwrap(),
            index: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_stream_richtext_videoFacet() -> 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("place.stream.richtext.videoFacet"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Annotation of a sub-string within rich text in a VOD description or comment.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("index"), SmolStr::new_static("features")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("features"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Union(LexRefUnion {
                                    refs: vec![
                                        CowStr::new_static("app.bsky.richtext.facet#mention"),
                                        CowStr::new_static("app.bsky.richtext.facet#link")
                                    ],
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("index"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.richtext.facet#byteSlice",
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}