// @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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::BlockView;
use crate::place_stream::Rendition;
use crate::place_stream::Renditions;
use crate::place_stream::chat::MessageView;
use crate::place_stream::chat::profile::Profile;
use crate::place_stream::livestream;

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

/// Record announcing a livestream is happening

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Livestream<'a> {
    ///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")]
    #[serde(borrow)]
    pub agent: Option<CowStr<'a>>,
    ///The primary URL where this livestream can be viewed, if available.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub canonical_url: Option<UriValue<'a>>,
    ///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")]
    #[serde(borrow)]
    pub notification_settings: Option<livestream::NotificationSettings<'a>>,
    ///The post that announced this livestream.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub post: Option<StrongRef<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub thumb: Option<BlobRef<'a>>,
    ///The title of the livestream, as it will be announced to followers.
    #[serde(borrow)]
    pub title: CowStr<'a>,
    ///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")]
    #[serde(borrow)]
    pub url: Option<UriValue<'a>>,
}

/// 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<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Livestream<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct NotificationSettings<'a> {
    ///Whether this livestream should trigger a push notification to followers.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub push_notification: Option<bool>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct StreamplaceAnything<'a> {
    #[serde(borrow)]
    pub livestream: StreamplaceAnythingLivestream<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum StreamplaceAnythingLivestream<'a> {
    #[serde(rename = "place.stream.livestream#livestreamView")]
    LivestreamView(Box<livestream::LivestreamView<'a>>),
    #[serde(rename = "place.stream.livestream#viewerCount")]
    ViewerCount(Box<livestream::ViewerCount<'a>>),
    #[serde(rename = "place.stream.livestream#teleportArrival")]
    TeleportArrival(Box<livestream::TeleportArrival<'a>>),
    #[serde(rename = "place.stream.livestream#teleportCanceled")]
    TeleportCanceled(Box<livestream::TeleportCanceled<'a>>),
    #[serde(rename = "place.stream.defs#blockView")]
    BlockView(Box<BlockView<'a>>),
    #[serde(rename = "place.stream.defs#renditions")]
    Renditions(Box<Renditions<'a>>),
    #[serde(rename = "place.stream.defs#rendition")]
    Rendition(Box<Rendition<'a>>),
    #[serde(rename = "place.stream.chat.defs#messageView")]
    MessageView(Box<MessageView<'a>>),
}


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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct TeleportCanceled<'a> {
    ///Why this teleport was canceled
    #[serde(borrow)]
    pub reason: CowStr<'a>,
    ///The URI of the teleport record that was canceled
    #[serde(borrow)]
    pub teleport_uri: AtUri<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ViewerCount<'a> {
    pub count: i64,
}

impl<'a> Livestream<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, LivestreamRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

impl<'a> LexiconSchema for LivestreamView<'a> {
    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<'de> = LivestreamGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<LivestreamGetRecordOutput<'_>> for Livestream<'_> {
    fn from(output: LivestreamGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Livestream<'_> {
    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<'a> LexiconSchema for Livestream<'a> {
    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.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<'a> LexiconSchema for NotificationSettings<'a> {
    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<'a> LexiconSchema for StreamplaceAnything<'a> {
    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<'a> LexiconSchema for TeleportArrival<'a> {
    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<'a> LexiconSchema for TeleportCanceled<'a> {
    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<'a> LexiconSchema for ViewerCount<'a> {
    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 Record;
        type Uri;
        type Cid;
        type Author;
        type IndexedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Record = Unset;
        type Uri = Unset;
        type Cid = Unset;
        type Author = Unset;
        type IndexedAt = Unset;
    }
    ///State transition - sets the `record` field to Set
    pub struct SetRecord<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecord<S> {}
    impl<S: State> State for SetRecord<S> {
        type Record = Set<members::record>;
        type Uri = S::Uri;
        type Cid = S::Cid;
        type Author = S::Author;
        type IndexedAt = S::IndexedAt;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Record = S::Record;
        type Uri = Set<members::uri>;
        type Cid = S::Cid;
        type Author = S::Author;
        type IndexedAt = S::IndexedAt;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCid<S> {}
    impl<S: State> State for SetCid<S> {
        type Record = S::Record;
        type Uri = S::Uri;
        type Cid = Set<members::cid>;
        type Author = S::Author;
        type IndexedAt = S::IndexedAt;
    }
    ///State transition - sets the `author` field to Set
    pub struct SetAuthor<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAuthor<S> {}
    impl<S: State> State for SetAuthor<S> {
        type Record = S::Record;
        type Uri = S::Uri;
        type Cid = S::Cid;
        type Author = Set<members::author>;
        type IndexedAt = S::IndexedAt;
    }
    ///State transition - sets the `indexed_at` field to Set
    pub struct SetIndexedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIndexedAt<S> {}
    impl<S: State> State for SetIndexedAt<S> {
        type Record = S::Record;
        type Uri = S::Uri;
        type Cid = S::Cid;
        type Author = S::Author;
        type IndexedAt = Set<members::indexed_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `record` field
        pub struct record(());
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `cid` field
        pub struct cid(());
        ///Marker type for the `author` field
        pub struct author(());
        ///Marker type for the `indexed_at` field
        pub struct indexed_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct LivestreamViewBuilder<'a, S: livestream_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<ProfileViewBasic<'a>>,
        Option<Cid<'a>>,
        Option<Datetime>,
        Option<Data<'a>>,
        Option<AtUri<'a>>,
        Option<livestream::ViewerCount<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

impl<'a, S: livestream_view_state::State> LivestreamViewBuilder<'a, S> {
    /// Set the `viewerCount` field (optional)
    pub fn viewer_count(
        mut self,
        value: impl Into<Option<livestream::ViewerCount<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S> LivestreamViewBuilder<'a, S>
where
    S: livestream_view_state::State,
    S::Record: livestream_view_state::IsSet,
    S::Uri: livestream_view_state::IsSet,
    S::Cid: livestream_view_state::IsSet,
    S::Author: livestream_view_state::IsSet,
    S::IndexedAt: livestream_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> LivestreamView<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> LivestreamView<'a> {
        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("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("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")
                                ],
                                ..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 Title;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Title = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTitle<S> {}
    impl<S: State> State for SetTitle<S> {
        type Title = Set<members::title>;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Title = S::Title;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct LivestreamBuilder<'a, S: livestream_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<UriValue<'a>>,
        Option<Datetime>,
        Option<Datetime>,
        Option<i64>,
        Option<Datetime>,
        Option<livestream::NotificationSettings<'a>>,
        Option<StrongRef<'a>>,
        Option<BlobRef<'a>>,
        Option<CowStr<'a>>,
        Option<UriValue<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S: livestream_state::State> LivestreamBuilder<'a, S> {
    /// Set the `endedAt` field (optional)
    pub fn ended_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.3 = 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.3 = value;
        self
    }
}

impl<'a, S: livestream_state::State> LivestreamBuilder<'a, S> {
    /// Set the `idleTimeoutSeconds` field (optional)
    pub fn idle_timeout_seconds(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.4 = 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.4 = value;
        self
    }
}

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

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

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

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

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

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

impl<'a, S> LivestreamBuilder<'a, S>
where
    S: livestream_state::State,
    S::Title: livestream_state::IsSet,
    S::CreatedAt: livestream_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Livestream<'a> {
        Livestream {
            agent: self._fields.0,
            canonical_url: self._fields.1,
            created_at: self._fields.2.unwrap(),
            ended_at: self._fields.3,
            idle_timeout_seconds: self._fields.4,
            last_seen_at: self._fields.5,
            notification_settings: self._fields.6,
            post: self._fields.7,
            thumb: self._fields.8,
            title: self._fields.9.unwrap(),
            url: self._fields.10,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Livestream<'a> {
        Livestream {
            agent: self._fields.0,
            canonical_url: self._fields.1,
            created_at: self._fields.2.unwrap(),
            ended_at: self._fields.3,
            idle_timeout_seconds: self._fields.4,
            last_seen_at: self._fields.5,
            notification_settings: self._fields.6,
            post: self._fields.7,
            thumb: self._fields.8,
            title: self._fields.9.unwrap(),
            url: self._fields.10,
            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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLivestream<S> {}
    impl<S: State> State for SetLivestream<S> {
        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<'a, S: streamplace_anything_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<StreamplaceAnythingLivestream<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> StreamplaceAnythingBuilder<'a, S>
where
    S: streamplace_anything_state::State,
    S::Livestream: streamplace_anything_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> StreamplaceAnything<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> StreamplaceAnything<'a> {
        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 ViewerCount;
        type Source;
        type TeleportUri;
        type StartsAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type ViewerCount = Unset;
        type Source = Unset;
        type TeleportUri = Unset;
        type StartsAt = Unset;
    }
    ///State transition - sets the `viewer_count` field to Set
    pub struct SetViewerCount<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetViewerCount<S> {}
    impl<S: State> State for SetViewerCount<S> {
        type ViewerCount = Set<members::viewer_count>;
        type Source = S::Source;
        type TeleportUri = S::TeleportUri;
        type StartsAt = S::StartsAt;
    }
    ///State transition - sets the `source` field to Set
    pub struct SetSource<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSource<S> {}
    impl<S: State> State for SetSource<S> {
        type ViewerCount = S::ViewerCount;
        type Source = Set<members::source>;
        type TeleportUri = S::TeleportUri;
        type StartsAt = S::StartsAt;
    }
    ///State transition - sets the `teleport_uri` field to Set
    pub struct SetTeleportUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTeleportUri<S> {}
    impl<S: State> State for SetTeleportUri<S> {
        type ViewerCount = S::ViewerCount;
        type Source = S::Source;
        type TeleportUri = Set<members::teleport_uri>;
        type StartsAt = S::StartsAt;
    }
    ///State transition - sets the `starts_at` field to Set
    pub struct SetStartsAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStartsAt<S> {}
    impl<S: State> State for SetStartsAt<S> {
        type ViewerCount = S::ViewerCount;
        type Source = S::Source;
        type TeleportUri = S::TeleportUri;
        type StartsAt = Set<members::starts_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `viewer_count` field
        pub struct viewer_count(());
        ///Marker type for the `source` field
        pub struct source(());
        ///Marker type for the `teleport_uri` field
        pub struct teleport_uri(());
        ///Marker type for the `starts_at` field
        pub struct starts_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct TeleportArrivalBuilder<'a, S: teleport_arrival_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Profile<'a>>,
        Option<ProfileViewBasic<'a>>,
        Option<Datetime>,
        Option<AtUri<'a>>,
        Option<i64>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: teleport_arrival_state::State> TeleportArrivalBuilder<'a, S> {
    /// Set the `chatProfile` field (optional)
    pub fn chat_profile(mut self, value: impl Into<Option<Profile<'a>>>) -> 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<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

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

impl<'a, S> TeleportArrivalBuilder<'a, S>
where
    S: teleport_arrival_state::State,
    S::ViewerCount: teleport_arrival_state::IsSet,
    S::Source: teleport_arrival_state::IsSet,
    S::TeleportUri: teleport_arrival_state::IsSet,
    S::StartsAt: teleport_arrival_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> TeleportArrival<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> TeleportArrival<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetReason<S> {}
    impl<S: State> State for SetReason<S> {
        type Reason = Set<members::reason>;
        type TeleportUri = S::TeleportUri;
    }
    ///State transition - sets the `teleport_uri` field to Set
    pub struct SetTeleportUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTeleportUri<S> {}
    impl<S: State> State for SetTeleportUri<S> {
        type Reason = S::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<'a, S: teleport_canceled_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<AtUri<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> TeleportCanceledBuilder<'a, S>
where
    S: teleport_canceled_state::State,
    S::Reason: teleport_canceled_state::IsSet,
    S::TeleportUri: teleport_canceled_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> TeleportCanceled<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> TeleportCanceled<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCount<S> {}
    impl<S: State> State for SetCount<S> {
        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<'a, S: viewer_count_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>,),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S> ViewerCountBuilder<'a, S>
where
    S: viewer_count_state::State,
    S::Count: viewer_count_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ViewerCount<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> ViewerCount<'a> {
        ViewerCount {
            count: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}