// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.stream.livestream
//
// 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, UriValue};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
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::actor::ProfileViewBasic;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::place_stream::ActivityGame;
use crate::place_stream::ActivityLabel;
use crate::place_stream::BlockView;
use crate::place_stream::Rendition;
use crate::place_stream::Renditions;
use crate::place_stream::chat::MessageView;
use crate::place_stream::chat::PinnedRecordView;
use crate::place_stream::chat::profile::Profile;
use crate::place_stream::livestream;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LivestreamView<S: BosStr = DefaultStr> {
    pub author: ProfileViewBasic<S>,
    pub cid: Cid<S>,
    pub indexed_at: Datetime,
    pub record: Data<S>,
    pub uri: AtUri<S>,
    ///The number of viewers watching this livestream. Use when you can't reasonably use #viewerCount directly.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub viewer_count: Option<livestream::ViewerCount<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Record announcing a livestream is happening

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "place.stream.livestream",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Livestream<S: BosStr = DefaultStr> {
    ///The game or activity being streamed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub activity: Option<LivestreamActivity<S>>,
    ///The source of the livestream, if available, in a User Agent format: `<product> / <product-version> <comment>` e.g. Streamplace/0.7.5 iOS
    #[serde(skip_serializing_if = "Option::is_none")]
    pub agent: Option<S>,
    ///The primary URL where this livestream can be viewed, if available.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub canonical_url: Option<UriValue<S>>,
    ///Client-declared timestamp when this livestream started.
    pub created_at: Datetime,
    ///Client-declared timestamp when this livestream ended. Ended livestreams are not supposed to start up again.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub ended_at: Option<Datetime>,
    ///Time in seconds after which this livestream should be automatically ended if idle. Zero means no timeout.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub idle_timeout_seconds: Option<i64>,
    ///Client-declared timestamp when this livestream was last seen by the Streamplace station.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_seen_at: Option<Datetime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub notification_settings: Option<livestream::NotificationSettings<S>>,
    ///The post that announced this livestream.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub post: Option<StrongRef<S>>,
    ///Freeform tags for this stream. Each tag must be alphanumeric (a-z, A-Z, 0-9) plus colon. Tags with colons indicate a specific tag group (e.g. 'lang:en' indicates the stream's primary language).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thumb: Option<BlobRef<S>>,
    ///The title of the livestream, as it will be announced to followers.
    pub title: S,
    ///The URL where this stream can be found. This is primarily a hint for other Streamplace nodes to locate and replicate the stream.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub url: Option<UriValue<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 LivestreamActivity<S: BosStr = DefaultStr> {
    #[serde(rename = "place.stream.defs#activityGame")]
    ActivityGame(Box<ActivityGame<S>>),
    #[serde(rename = "place.stream.defs#activityLabel")]
    ActivityLabel(Box<ActivityLabel<S>>),
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LivestreamGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Livestream<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct NotificationSettings<S: BosStr = DefaultStr> {
    ///Whether this livestream should trigger a push notification to followers.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub push_notification: Option<bool>,
    #[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 StreamplaceAnything<S: BosStr = DefaultStr> {
    pub livestream: StreamplaceAnythingLivestream<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 StreamplaceAnythingLivestream<S: BosStr = DefaultStr> {
    #[serde(rename = "place.stream.livestream#livestreamView")]
    LivestreamView(Box<livestream::LivestreamView<S>>),
    #[serde(rename = "place.stream.livestream#viewerCount")]
    ViewerCount(Box<livestream::ViewerCount<S>>),
    #[serde(rename = "place.stream.livestream#teleportArrival")]
    TeleportArrival(Box<livestream::TeleportArrival<S>>),
    #[serde(rename = "place.stream.livestream#teleportCanceled")]
    TeleportCanceled(Box<livestream::TeleportCanceled<S>>),
    #[serde(rename = "place.stream.defs#blockView")]
    BlockView(Box<BlockView<S>>),
    #[serde(rename = "place.stream.defs#renditions")]
    Renditions(Box<Renditions<S>>),
    #[serde(rename = "place.stream.defs#rendition")]
    Rendition(Box<Rendition<S>>),
    #[serde(rename = "place.stream.chat.defs#messageView")]
    MessageView(Box<MessageView<S>>),
    #[serde(rename = "place.stream.chat.defs#pinnedRecordView")]
    PinnedRecordView(Box<PinnedRecordView<S>>),
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct TeleportArrival<S: BosStr = DefaultStr> {
    ///The chat profile of the source streamer
    #[serde(skip_serializing_if = "Option::is_none")]
    pub chat_profile: Option<Profile<S>>,
    ///The streamer who is teleporting their viewers here
    pub source: ProfileViewBasic<S>,
    ///When this teleport started
    pub starts_at: Datetime,
    ///The URI of the teleport record
    pub teleport_uri: AtUri<S>,
    ///How many viewers are arriving from this teleport
    pub viewer_count: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct TeleportCanceled<S: BosStr = DefaultStr> {
    ///Why this teleport was canceled
    pub reason: S,
    ///The URI of the teleport record that was canceled
    pub teleport_uri: AtUri<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


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

impl<S: BosStr> Livestream<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, LivestreamRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

impl<S: BosStr> LexiconSchema for LivestreamView<S> {
    fn nsid() -> &'static str {
        "place.stream.livestream"
    }
    fn def_name() -> &'static str {
        "livestreamView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_livestream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct LivestreamRecord;
impl XrpcResp for LivestreamRecord {
    const NSID: &'static str = "place.stream.livestream";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = LivestreamGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<LivestreamGetRecordOutput<S>> for Livestream<S> {
    fn from(output: LivestreamGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Livestream<S> {
    const NSID: &'static str = "place.stream.livestream";
    type Record = LivestreamRecord;
}

impl Collection for LivestreamRecord {
    const NSID: &'static str = "place.stream.livestream";
    type Record = LivestreamRecord;
}

impl<S: BosStr> LexiconSchema for Livestream<S> {
    fn nsid() -> &'static str {
        "place.stream.livestream"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_livestream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.tags {
            #[allow(unused_comparisons)]
            if value.len() > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tags"),
                    max: 10usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.thumb {
            {
                let size = value.blob().size;
                if size > 1000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("thumb"),
                        max: 1000000usize,
                        actual: size,
                    });
                }
            }
        }
        if let Some(ref value) = self.thumb {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/*"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("thumb"),
                        accepted: vec!["image/*".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        {
            let value = &self.title;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1400usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 1400usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.title;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 140usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("title"),
                        max: 140usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for NotificationSettings<S> {
    fn nsid() -> &'static str {
        "place.stream.livestream"
    }
    fn def_name() -> &'static str {
        "notificationSettings"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_livestream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for StreamplaceAnything<S> {
    fn nsid() -> &'static str {
        "place.stream.livestream"
    }
    fn def_name() -> &'static str {
        "streamplaceAnything"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_livestream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for TeleportArrival<S> {
    fn nsid() -> &'static str {
        "place.stream.livestream"
    }
    fn def_name() -> &'static str {
        "teleportArrival"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_livestream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for TeleportCanceled<S> {
    fn nsid() -> &'static str {
        "place.stream.livestream"
    }
    fn def_name() -> &'static str {
        "teleportCanceled"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_livestream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ViewerCount<S> {
    fn nsid() -> &'static str {
        "place.stream.livestream"
    }
    fn def_name() -> &'static str {
        "viewerCount"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_livestream()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod livestream_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 IndexedAt;
        type Record;
        type Uri;
    }
    /// 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 IndexedAt = Unset;
        type Record = Unset;
        type Uri = 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 IndexedAt = St::IndexedAt;
        type Record = St::Record;
        type Uri = St::Uri;
    }
    ///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 IndexedAt = St::IndexedAt;
        type Record = St::Record;
        type Uri = St::Uri;
    }
    ///State transition - sets the `indexed_at` field to Set
    pub struct SetIndexedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetIndexedAt<St> {}
    impl<St: State> State for SetIndexedAt<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type IndexedAt = Set<members::indexed_at>;
        type Record = St::Record;
        type Uri = St::Uri;
    }
    ///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 IndexedAt = St::IndexedAt;
        type Record = Set<members::record>;
        type Uri = St::Uri;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUri<St> {}
    impl<St: State> State for SetUri<St> {
        type Author = St::Author;
        type Cid = St::Cid;
        type IndexedAt = St::IndexedAt;
        type Record = St::Record;
        type Uri = Set<members::uri>;
    }
    /// 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 `indexed_at` field
        pub struct indexed_at(());
        ///Marker type for the `record` field
        pub struct record(());
        ///Marker type for the `uri` field
        pub struct uri(());
    }
}

/// Builder for constructing an instance of this type.
pub struct LivestreamViewBuilder<
    St: livestream_view_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<ProfileViewBasic<S>>,
        Option<Cid<S>>,
        Option<Datetime>,
        Option<Data<S>>,
        Option<AtUri<S>>,
        Option<livestream::ViewerCount<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> LivestreamView<S> {
    /// Create a new builder for this type
    pub fn builder() -> LivestreamViewBuilder<livestream_view_state::Empty, S> {
        LivestreamViewBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> LivestreamViewBuilder<St, S>
where
    St: livestream_view_state::State,
    St::IndexedAt: livestream_view_state::IsUnset,
{
    /// Set the `indexedAt` field (required)
    pub fn indexed_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> LivestreamViewBuilder<livestream_view_state::SetIndexedAt<St>, S> {
        self._fields.2 = Option::Some(value.into());
        LivestreamViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St: livestream_view_state::State, S: BosStr> LivestreamViewBuilder<St, S> {
    /// Set the `viewerCount` field (optional)
    pub fn viewer_count(
        mut self,
        value: impl Into<Option<livestream::ViewerCount<S>>>,
    ) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `viewerCount` field to an Option value (optional)
    pub fn maybe_viewer_count(
        mut self,
        value: Option<livestream::ViewerCount<S>>,
    ) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St, S: BosStr> LivestreamViewBuilder<St, S>
where
    St: livestream_view_state::State,
    St::Author: livestream_view_state::IsSet,
    St::Cid: livestream_view_state::IsSet,
    St::IndexedAt: livestream_view_state::IsSet,
    St::Record: livestream_view_state::IsSet,
    St::Uri: livestream_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> LivestreamView<S> {
        LivestreamView {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            indexed_at: self._fields.2.unwrap(),
            record: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            viewer_count: 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>>,
    ) -> LivestreamView<S> {
        LivestreamView {
            author: self._fields.0.unwrap(),
            cid: self._fields.1.unwrap(),
            indexed_at: self._fields.2.unwrap(),
            record: self._fields.3.unwrap(),
            uri: self._fields.4.unwrap(),
            viewer_count: self._fields.5,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_stream_livestream() -> 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.livestream"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("livestreamView"),
                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("indexedAt")
                        ],
                    ),
                    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("indexedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("record"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("viewerCount"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#viewerCount"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("Record announcing a livestream is happening"),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("title"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("activity"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static("The game or activity being streamed."),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("place.stream.defs#activityGame"),
                                        CowStr::new_static("place.stream.defs#activityLabel")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("agent"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The source of the livestream, if available, in a User Agent format: `<product> / <product-version> <comment>` e.g. Streamplace/0.7.5 iOS",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("canonicalUrl"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The primary URL where this livestream can be viewed, if available.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when this livestream started.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("endedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when this livestream ended. Ended livestreams are not supposed to start up again.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("idleTimeoutSeconds"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("lastSeenAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when this livestream was last seen by the Streamplace station.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("notificationSettings"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "place.stream.livestream#notificationSettings",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("post"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tags"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Freeform tags for this stream. Each tag must be alphanumeric (a-z, A-Z, 0-9) plus colon. Tags with colons indicate a specific tag group (e.g. 'lang:en' indicates the stream's primary language).",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        max_length: Some(640usize),
                                        max_graphemes: Some(64usize),
                                        ..Default::default()
                                    }),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("thumb"),
                                LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The title of the livestream, as it will be announced to followers.",
                                        ),
                                    ),
                                    max_length: Some(1400usize),
                                    max_graphemes: Some(140usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("url"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The URL where this stream can be found. This is primarily a hint for other Streamplace nodes to locate and replicate the stream.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("notificationSettings"),
                LexUserType::Object(LexObject {
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("pushNotification"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("streamplaceAnything"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("livestream")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("livestream"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("#livestreamView"),
                                    CowStr::new_static("#viewerCount"),
                                    CowStr::new_static("#teleportArrival"),
                                    CowStr::new_static("#teleportCanceled"),
                                    CowStr::new_static("place.stream.defs#blockView"),
                                    CowStr::new_static("place.stream.defs#renditions"),
                                    CowStr::new_static("place.stream.defs#rendition"),
                                    CowStr::new_static("place.stream.chat.defs#messageView"),
                                    CowStr::new_static("place.stream.chat.defs#pinnedRecordView")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("teleportArrival"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("teleportUri"),
                            SmolStr::new_static("source"),
                            SmolStr::new_static("viewerCount"),
                            SmolStr::new_static("startsAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("chatProfile"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("place.stream.chat.profile"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("source"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.actor.defs#profileViewBasic",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("startsAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When this teleport started"),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("teleportUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The URI of the teleport record"),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("viewerCount"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("teleportCanceled"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("teleportUri"),
                            SmolStr::new_static("reason")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("reason"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Why this teleport was canceled"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("teleportUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The URI of the teleport record that was canceled",
                                    ),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("viewerCount"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("count")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("count"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type.
pub struct LivestreamBuilder<St: livestream_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<LivestreamActivity<S>>,
        Option<S>,
        Option<UriValue<S>>,
        Option<Datetime>,
        Option<Datetime>,
        Option<i64>,
        Option<Datetime>,
        Option<livestream::NotificationSettings<S>>,
        Option<StrongRef<S>>,
        Option<Vec<S>>,
        Option<BlobRef<S>>,
        Option<S>,
        Option<UriValue<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Livestream<S> {
    /// Create a new builder for this type
    pub fn builder() -> LivestreamBuilder<livestream_state::Empty, S> {
        LivestreamBuilder::builder()
    }
}

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

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

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

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

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `canonicalUrl` field (optional)
    pub fn canonical_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `canonicalUrl` field to an Option value (optional)
    pub fn maybe_canonical_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> LivestreamBuilder<St, S>
where
    St: livestream_state::State,
    St::CreatedAt: livestream_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> LivestreamBuilder<livestream_state::SetCreatedAt<St>, S> {
        self._fields.3 = Option::Some(value.into());
        LivestreamBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `endedAt` field (optional)
    pub fn ended_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `endedAt` field to an Option value (optional)
    pub fn maybe_ended_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `idleTimeoutSeconds` field (optional)
    pub fn idle_timeout_seconds(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `idleTimeoutSeconds` field to an Option value (optional)
    pub fn maybe_idle_timeout_seconds(mut self, value: Option<i64>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `lastSeenAt` field (optional)
    pub fn last_seen_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `lastSeenAt` field to an Option value (optional)
    pub fn maybe_last_seen_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `notificationSettings` field (optional)
    pub fn notification_settings(
        mut self,
        value: impl Into<Option<livestream::NotificationSettings<S>>>,
    ) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `notificationSettings` field to an Option value (optional)
    pub fn maybe_notification_settings(
        mut self,
        value: Option<livestream::NotificationSettings<S>>,
    ) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `post` field (optional)
    pub fn post(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `post` field to an Option value (optional)
    pub fn maybe_post(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `tags` field to an Option value (optional)
    pub fn maybe_tags(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `thumb` field (optional)
    pub fn thumb(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `thumb` field to an Option value (optional)
    pub fn maybe_thumb(mut self, value: Option<BlobRef<S>>) -> Self {
        self._fields.10 = value;
        self
    }
}

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

impl<St: livestream_state::State, S: BosStr> LivestreamBuilder<St, S> {
    /// Set the `url` field (optional)
    pub fn url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `url` field to an Option value (optional)
    pub fn maybe_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<St, S: BosStr> LivestreamBuilder<St, S>
where
    St: livestream_state::State,
    St::CreatedAt: livestream_state::IsSet,
    St::Title: livestream_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Livestream<S> {
        Livestream {
            activity: self._fields.0,
            agent: self._fields.1,
            canonical_url: self._fields.2,
            created_at: self._fields.3.unwrap(),
            ended_at: self._fields.4,
            idle_timeout_seconds: self._fields.5,
            last_seen_at: self._fields.6,
            notification_settings: self._fields.7,
            post: self._fields.8,
            tags: self._fields.9,
            thumb: self._fields.10,
            title: self._fields.11.unwrap(),
            url: self._fields.12,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Livestream<S> {
        Livestream {
            activity: self._fields.0,
            agent: self._fields.1,
            canonical_url: self._fields.2,
            created_at: self._fields.3.unwrap(),
            ended_at: self._fields.4,
            idle_timeout_seconds: self._fields.5,
            last_seen_at: self._fields.6,
            notification_settings: self._fields.7,
            post: self._fields.8,
            tags: self._fields.9,
            thumb: self._fields.10,
            title: self._fields.11.unwrap(),
            url: self._fields.12,
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> StreamplaceAnything<S> {
    /// Create a new builder for this type
    pub fn builder() -> StreamplaceAnythingBuilder<
        streamplace_anything_state::Empty,
        S,
    > {
        StreamplaceAnythingBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> StreamplaceAnythingBuilder<St, S>
where
    St: streamplace_anything_state::State,
    St::Livestream: streamplace_anything_state::IsUnset,
{
    /// Set the `livestream` field (required)
    pub fn livestream(
        mut self,
        value: impl Into<StreamplaceAnythingLivestream<S>>,
    ) -> StreamplaceAnythingBuilder<streamplace_anything_state::SetLivestream<St>, S> {
        self._fields.0 = Option::Some(value.into());
        StreamplaceAnythingBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> StreamplaceAnythingBuilder<St, S>
where
    St: streamplace_anything_state::State,
    St::Livestream: streamplace_anything_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> StreamplaceAnything<S> {
        StreamplaceAnything {
            livestream: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> StreamplaceAnything<S> {
        StreamplaceAnything {
            livestream: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod teleport_arrival_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 Source;
        type StartsAt;
        type TeleportUri;
        type ViewerCount;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Source = Unset;
        type StartsAt = Unset;
        type TeleportUri = Unset;
        type ViewerCount = Unset;
    }
    ///State transition - sets the `source` field to Set
    pub struct SetSource<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSource<St> {}
    impl<St: State> State for SetSource<St> {
        type Source = Set<members::source>;
        type StartsAt = St::StartsAt;
        type TeleportUri = St::TeleportUri;
        type ViewerCount = St::ViewerCount;
    }
    ///State transition - sets the `starts_at` field to Set
    pub struct SetStartsAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetStartsAt<St> {}
    impl<St: State> State for SetStartsAt<St> {
        type Source = St::Source;
        type StartsAt = Set<members::starts_at>;
        type TeleportUri = St::TeleportUri;
        type ViewerCount = St::ViewerCount;
    }
    ///State transition - sets the `teleport_uri` field to Set
    pub struct SetTeleportUri<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTeleportUri<St> {}
    impl<St: State> State for SetTeleportUri<St> {
        type Source = St::Source;
        type StartsAt = St::StartsAt;
        type TeleportUri = Set<members::teleport_uri>;
        type ViewerCount = St::ViewerCount;
    }
    ///State transition - sets the `viewer_count` field to Set
    pub struct SetViewerCount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetViewerCount<St> {}
    impl<St: State> State for SetViewerCount<St> {
        type Source = St::Source;
        type StartsAt = St::StartsAt;
        type TeleportUri = St::TeleportUri;
        type ViewerCount = Set<members::viewer_count>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `source` field
        pub struct source(());
        ///Marker type for the `starts_at` field
        pub struct starts_at(());
        ///Marker type for the `teleport_uri` field
        pub struct teleport_uri(());
        ///Marker type for the `viewer_count` field
        pub struct viewer_count(());
    }
}

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

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

impl<S: BosStr> TeleportArrival<S> {
    /// Create a new builder for this type
    pub fn builder() -> TeleportArrivalBuilder<teleport_arrival_state::Empty, S> {
        TeleportArrivalBuilder::builder()
    }
}

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

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

impl<St: teleport_arrival_state::State, S: BosStr> TeleportArrivalBuilder<St, S> {
    /// Set the `chatProfile` field (optional)
    pub fn chat_profile(mut self, value: impl Into<Option<Profile<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `chatProfile` field to an Option value (optional)
    pub fn maybe_chat_profile(mut self, value: Option<Profile<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> TeleportArrivalBuilder<St, S>
where
    St: teleport_arrival_state::State,
    St::Source: teleport_arrival_state::IsUnset,
{
    /// Set the `source` field (required)
    pub fn source(
        mut self,
        value: impl Into<ProfileViewBasic<S>>,
    ) -> TeleportArrivalBuilder<teleport_arrival_state::SetSource<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TeleportArrivalBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TeleportArrivalBuilder<St, S>
where
    St: teleport_arrival_state::State,
    St::StartsAt: teleport_arrival_state::IsUnset,
{
    /// Set the `startsAt` field (required)
    pub fn starts_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> TeleportArrivalBuilder<teleport_arrival_state::SetStartsAt<St>, S> {
        self._fields.2 = Option::Some(value.into());
        TeleportArrivalBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TeleportArrivalBuilder<St, S>
where
    St: teleport_arrival_state::State,
    St::TeleportUri: teleport_arrival_state::IsUnset,
{
    /// Set the `teleportUri` field (required)
    pub fn teleport_uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> TeleportArrivalBuilder<teleport_arrival_state::SetTeleportUri<St>, S> {
        self._fields.3 = Option::Some(value.into());
        TeleportArrivalBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TeleportArrivalBuilder<St, S>
where
    St: teleport_arrival_state::State,
    St::ViewerCount: teleport_arrival_state::IsUnset,
{
    /// Set the `viewerCount` field (required)
    pub fn viewer_count(
        mut self,
        value: impl Into<i64>,
    ) -> TeleportArrivalBuilder<teleport_arrival_state::SetViewerCount<St>, S> {
        self._fields.4 = Option::Some(value.into());
        TeleportArrivalBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TeleportArrivalBuilder<St, S>
where
    St: teleport_arrival_state::State,
    St::Source: teleport_arrival_state::IsSet,
    St::StartsAt: teleport_arrival_state::IsSet,
    St::TeleportUri: teleport_arrival_state::IsSet,
    St::ViewerCount: teleport_arrival_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TeleportArrival<S> {
        TeleportArrival {
            chat_profile: self._fields.0,
            source: self._fields.1.unwrap(),
            starts_at: self._fields.2.unwrap(),
            teleport_uri: self._fields.3.unwrap(),
            viewer_count: 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>>,
    ) -> TeleportArrival<S> {
        TeleportArrival {
            chat_profile: self._fields.0,
            source: self._fields.1.unwrap(),
            starts_at: self._fields.2.unwrap(),
            teleport_uri: self._fields.3.unwrap(),
            viewer_count: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> TeleportCanceled<S> {
    /// Create a new builder for this type
    pub fn builder() -> TeleportCanceledBuilder<teleport_canceled_state::Empty, S> {
        TeleportCanceledBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> TeleportCanceledBuilder<St, S>
where
    St: teleport_canceled_state::State,
    St::Reason: teleport_canceled_state::IsUnset,
{
    /// Set the `reason` field (required)
    pub fn reason(
        mut self,
        value: impl Into<S>,
    ) -> TeleportCanceledBuilder<teleport_canceled_state::SetReason<St>, S> {
        self._fields.0 = Option::Some(value.into());
        TeleportCanceledBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TeleportCanceledBuilder<St, S>
where
    St: teleport_canceled_state::State,
    St::TeleportUri: teleport_canceled_state::IsUnset,
{
    /// Set the `teleportUri` field (required)
    pub fn teleport_uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> TeleportCanceledBuilder<teleport_canceled_state::SetTeleportUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TeleportCanceledBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TeleportCanceledBuilder<St, S>
where
    St: teleport_canceled_state::State,
    St::Reason: teleport_canceled_state::IsSet,
    St::TeleportUri: teleport_canceled_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TeleportCanceled<S> {
        TeleportCanceled {
            reason: self._fields.0.unwrap(),
            teleport_uri: 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>>,
    ) -> TeleportCanceled<S> {
        TeleportCanceled {
            reason: self._fields.0.unwrap(),
            teleport_uri: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> ViewerCount<S> {
    /// Create a new builder for this type
    pub fn builder() -> ViewerCountBuilder<viewer_count_state::Empty, S> {
        ViewerCountBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> ViewerCountBuilder<St, S>
where
    St: viewer_count_state::State,
    St::Count: viewer_count_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ViewerCount<S> {
        ViewerCount {
            count: self._fields.0.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ViewerCount<S> {
        ViewerCount {
            count: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}