// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.stream.media.getVideo
//
// 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::string::{AtUri, Cid};
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::actor::ProfileViewBasic;
use crate::place_stream::media::track::TrackView;
use crate::place_stream::media::get_video;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetVideo<S: BosStr = DefaultStr> {
    pub uri: AtUri<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetVideoOutput<S: BosStr = DefaultStr> {
    #[serde(flatten)]
    pub value: Data<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,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum GetVideoError {
    /// No record indexed at the supplied AT-URI.
    #[serde(rename = "VideoNotFound")]
    VideoNotFound(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for GetVideoError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::VideoNotFound(msg) => {
                write!(f, "VideoNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct VideoView<S: BosStr = DefaultStr> {
    pub author: ProfileViewBasic<S>,
    pub cid: Cid<S>,
    ///Total number of place.stream.like records whose subject is this video. Always present; zero when none, so consumers can render a count unconditionally.
    pub like_count: i64,
    pub record: Data<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tracks: Option<Vec<TrackView<S>>>,
    pub uri: AtUri<S>,
    ///Aggregated view counts across every indexed reporter. Always present; zero-valued (count=0, reporters=0) when no place.stream.media.viewCount records have been observed yet, so consumers can render a count unconditionally.
    pub view_counts: get_video::ViewCountSummary<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Sums across every place.stream.media.viewCount record indexed for this video, regardless of reporter or window. The underlying records are window-bounded; the consumer sees a running total.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ViewCountSummary<S: BosStr = DefaultStr> {
    ///Sum of bytes transferred across every track row in every indexed report.
    pub bytes: i64,
    ///Sum of `count` across every indexed report.
    pub count: i64,
    ///Sum of playback duration (ms) across every track row in every indexed report.
    pub duration_ms: i64,
    ///Number of distinct streamplace nodes that have contributed at least one viewCount record for this video.
    pub reporters: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/** Response marker for the `place.stream.media.getVideo` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetVideoOutput<S>` for this endpoint.*/
pub struct GetVideoResponse;
impl jacquard_common::xrpc::XrpcResp for GetVideoResponse {
    const NSID: &'static str = "place.stream.media.getVideo";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetVideoOutput<S>;
    type Err = GetVideoError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetVideo<S> {
    const NSID: &'static str = "place.stream.media.getVideo";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetVideoResponse;
}

/** Endpoint marker for the `place.stream.media.getVideo` query.

Path: `/xrpc/place.stream.media.getVideo`. The request payload type is `GetVideo<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetVideoRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetVideoRequest {
    const PATH: &'static str = "/xrpc/place.stream.media.getVideo";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetVideo<S>;
    type Response = GetVideoResponse;
}

impl<S: BosStr> LexiconSchema for VideoView<S> {
    fn nsid() -> &'static str {
        "place.stream.media.getVideo"
    }
    fn def_name() -> &'static str {
        "videoView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_media_getVideo()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.like_count;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("like_count"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ViewCountSummary<S> {
    fn nsid() -> &'static str {
        "place.stream.media.getVideo"
    }
    fn def_name() -> &'static str {
        "viewCountSummary"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_media_getVideo()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.bytes;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("bytes"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.count;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("count"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.duration_ms;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("duration_ms"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.reporters;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("reporters"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

pub mod get_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 Uri;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
    }
    ///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 Uri = Set<members::uri>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

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

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

impl<S: BosStr> GetVideo<S> {
    /// Create a new builder for this type
    pub fn builder() -> GetVideoBuilder<get_video_state::Empty, S> {
        GetVideoBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> GetVideoBuilder<St, S>
where
    St: get_video_state::State,
    St::Uri: get_video_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetVideo<S> {
        GetVideo {
            uri: self._fields.0.unwrap(),
        }
    }
}

pub mod video_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 Author;
        type Cid;
        type LikeCount;
        type Record;
        type Uri;
        type ViewCounts;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Author = Unset;
        type Cid = Unset;
        type LikeCount = Unset;
        type Record = Unset;
        type Uri = Unset;
        type ViewCounts = Unset;
    }
    ///State transition - sets the `author` field to Set
    pub struct SetAuthor<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAuthor<St> {}
    impl<St: State> State for SetAuthor<St> {
        type Author = Set<members::author>;
        type Cid = St::Cid;
        type LikeCount = St::LikeCount;
        type Record = St::Record;
        type Uri = St::Uri;
        type ViewCounts = St::ViewCounts;
    }
    ///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 Author = St::Author;
        type Cid = Set<members::cid>;
        type LikeCount = St::LikeCount;
        type Record = St::Record;
        type Uri = St::Uri;
        type ViewCounts = St::ViewCounts;
    }
    ///State transition - sets the `like_count` field to Set
    pub struct SetLikeCount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLikeCount<St> {}
    impl<St: State> State for SetLikeCount<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type LikeCount = Set<members::like_count>;
        type Record = St::Record;
        type Uri = St::Uri;
        type ViewCounts = St::ViewCounts;
    }
    ///State transition - sets the `record` field to Set
    pub struct SetRecord<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRecord<St> {}
    impl<St: State> State for SetRecord<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type LikeCount = St::LikeCount;
        type Record = Set<members::record>;
        type Uri = St::Uri;
        type ViewCounts = St::ViewCounts;
    }
    ///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 Author = St::Author;
        type Cid = St::Cid;
        type LikeCount = St::LikeCount;
        type Record = St::Record;
        type Uri = Set<members::uri>;
        type ViewCounts = St::ViewCounts;
    }
    ///State transition - sets the `view_counts` field to Set
    pub struct SetViewCounts<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetViewCounts<St> {}
    impl<St: State> State for SetViewCounts<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type LikeCount = St::LikeCount;
        type Record = St::Record;
        type Uri = St::Uri;
        type ViewCounts = Set<members::view_counts>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `author` field
        pub struct author(());
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `like_count` field
        pub struct like_count(());
        ///Marker type for the `record` field
        pub struct record(());
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `view_counts` field
        pub struct view_counts(());
    }
}

/// Builder for constructing an instance of this type.
pub struct VideoViewBuilder<St: video_view_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<ProfileViewBasic<S>>,
        Option<Cid<S>>,
        Option<i64>,
        Option<Data<S>>,
        Option<Vec<TrackView<S>>>,
        Option<AtUri<S>>,
        Option<get_video::ViewCountSummary<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> VideoView<S> {
    /// Create a new builder for this type
    pub fn builder() -> VideoViewBuilder<video_view_state::Empty, S> {
        VideoViewBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> VideoViewBuilder<St, S>
where
    St: video_view_state::State,
    St::Author: video_view_state::IsUnset,
{
    /// Set the `author` field (required)
    pub fn author(
        mut self,
        value: impl Into<ProfileViewBasic<S>>,
    ) -> VideoViewBuilder<video_view_state::SetAuthor<St>, S> {
        self._fields.0 = Option::Some(value.into());
        VideoViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoViewBuilder<St, S>
where
    St: video_view_state::State,
    St::Cid: video_view_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> VideoViewBuilder<video_view_state::SetCid<St>, S> {
        self._fields.1 = Option::Some(value.into());
        VideoViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoViewBuilder<St, S>
where
    St: video_view_state::State,
    St::LikeCount: video_view_state::IsUnset,
{
    /// Set the `likeCount` field (required)
    pub fn like_count(
        mut self,
        value: impl Into<i64>,
    ) -> VideoViewBuilder<video_view_state::SetLikeCount<St>, S> {
        self._fields.2 = Option::Some(value.into());
        VideoViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoViewBuilder<St, S>
where
    St: video_view_state::State,
    St::Record: video_view_state::IsUnset,
{
    /// Set the `record` field (required)
    pub fn record(
        mut self,
        value: impl Into<Data<S>>,
    ) -> VideoViewBuilder<video_view_state::SetRecord<St>, S> {
        self._fields.3 = Option::Some(value.into());
        VideoViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: video_view_state::State, S: BosStr> VideoViewBuilder<St, S> {
    /// Set the `tracks` field (optional)
    pub fn tracks(mut self, value: impl Into<Option<Vec<TrackView<S>>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `tracks` field to an Option value (optional)
    pub fn maybe_tracks(mut self, value: Option<Vec<TrackView<S>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<St, S: BosStr> VideoViewBuilder<St, S>
where
    St: video_view_state::State,
    St::ViewCounts: video_view_state::IsUnset,
{
    /// Set the `viewCounts` field (required)
    pub fn view_counts(
        mut self,
        value: impl Into<get_video::ViewCountSummary<S>>,
    ) -> VideoViewBuilder<video_view_state::SetViewCounts<St>, S> {
        self._fields.6 = Option::Some(value.into());
        VideoViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> VideoViewBuilder<St, S>
where
    St: video_view_state::State,
    St::Author: video_view_state::IsSet,
    St::Cid: video_view_state::IsSet,
    St::LikeCount: video_view_state::IsSet,
    St::Record: video_view_state::IsSet,
    St::Uri: video_view_state::IsSet,
    St::ViewCounts: video_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> VideoView<S> {
        VideoView {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            like_count: self._fields.2.unwrap(),
            record: self._fields.3.unwrap(),
            tracks: self._fields.4,
            uri: self._fields.5.unwrap(),
            view_counts: self._fields.6.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>>,
    ) -> VideoView<S> {
        VideoView {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            like_count: self._fields.2.unwrap(),
            record: self._fields.3.unwrap(),
            tracks: self._fields.4,
            uri: self._fields.5.unwrap(),
            view_counts: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_stream_media_getVideo() -> 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.media.getVideo"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("uri")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("uri"),
                                    LexXrpcParametersProperty::String(LexString {
                                        description: Some(
                                            CowStr::new_static(
                                                "AT-URI of the place.stream.video record.",
                                            ),
                                        ),
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("videoView"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("uri"), SmolStr::new_static("cid"),
                            SmolStr::new_static("author"), SmolStr::new_static("record"),
                            SmolStr::new_static("viewCounts"),
                            SmolStr::new_static("likeCount")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("author"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.actor.defs#profileViewBasic",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("likeCount"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("record"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("tracks"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "place.stream.media.track#trackView",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("viewCounts"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#viewCountSummary"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viewCountSummary"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Sums across every place.stream.media.viewCount record indexed for this video, regardless of reporter or window. The underlying records are window-bounded; the consumer sees a running total.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("count"), SmolStr::new_static("bytes"),
                            SmolStr::new_static("durationMs"),
                            SmolStr::new_static("reporters")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("bytes"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("count"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("durationMs"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reporters"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod view_count_summary_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 Bytes;
        type Count;
        type DurationMs;
        type Reporters;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Bytes = Unset;
        type Count = Unset;
        type DurationMs = Unset;
        type Reporters = Unset;
    }
    ///State transition - sets the `bytes` field to Set
    pub struct SetBytes<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBytes<St> {}
    impl<St: State> State for SetBytes<St> {
        type Bytes = Set<members::bytes>;
        type Count = St::Count;
        type DurationMs = St::DurationMs;
        type Reporters = St::Reporters;
    }
    ///State transition - sets the `count` field to Set
    pub struct SetCount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCount<St> {}
    impl<St: State> State for SetCount<St> {
        type Bytes = St::Bytes;
        type Count = Set<members::count>;
        type DurationMs = St::DurationMs;
        type Reporters = St::Reporters;
    }
    ///State transition - sets the `duration_ms` field to Set
    pub struct SetDurationMs<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDurationMs<St> {}
    impl<St: State> State for SetDurationMs<St> {
        type Bytes = St::Bytes;
        type Count = St::Count;
        type DurationMs = Set<members::duration_ms>;
        type Reporters = St::Reporters;
    }
    ///State transition - sets the `reporters` field to Set
    pub struct SetReporters<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReporters<St> {}
    impl<St: State> State for SetReporters<St> {
        type Bytes = St::Bytes;
        type Count = St::Count;
        type DurationMs = St::DurationMs;
        type Reporters = Set<members::reporters>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `bytes` field
        pub struct bytes(());
        ///Marker type for the `count` field
        pub struct count(());
        ///Marker type for the `duration_ms` field
        pub struct duration_ms(());
        ///Marker type for the `reporters` field
        pub struct reporters(());
    }
}

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

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

impl<S: BosStr> ViewCountSummary<S> {
    /// Create a new builder for this type
    pub fn builder() -> ViewCountSummaryBuilder<view_count_summary_state::Empty, S> {
        ViewCountSummaryBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> ViewCountSummaryBuilder<St, S>
where
    St: view_count_summary_state::State,
    St::DurationMs: view_count_summary_state::IsUnset,
{
    /// Set the `durationMs` field (required)
    pub fn duration_ms(
        mut self,
        value: impl Into<i64>,
    ) -> ViewCountSummaryBuilder<view_count_summary_state::SetDurationMs<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ViewCountSummaryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ViewCountSummaryBuilder<St, S>
where
    St: view_count_summary_state::State,
    St::Reporters: view_count_summary_state::IsUnset,
{
    /// Set the `reporters` field (required)
    pub fn reporters(
        mut self,
        value: impl Into<i64>,
    ) -> ViewCountSummaryBuilder<view_count_summary_state::SetReporters<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ViewCountSummaryBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ViewCountSummaryBuilder<St, S>
where
    St: view_count_summary_state::State,
    St::Bytes: view_count_summary_state::IsSet,
    St::Count: view_count_summary_state::IsSet,
    St::DurationMs: view_count_summary_state::IsSet,
    St::Reporters: view_count_summary_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ViewCountSummary<S> {
        ViewCountSummary {
            bytes: self._fields.0.unwrap(),
            count: self._fields.1.unwrap(),
            duration_ms: self._fields.2.unwrap(),
            reporters: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ViewCountSummary<S> {
        ViewCountSummary {
            bytes: self._fields.0.unwrap(),
            count: self._fields.1.unwrap(),
            duration_ms: self._fields.2.unwrap(),
            reporters: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}