// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.feed.post
//
// 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime, Language};
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::embed::external::ExternalRecord;
use crate::app_bsky::embed::gallery::Gallery;
use crate::app_bsky::embed::images::Images;
use crate::app_bsky::embed::record::Record;
use crate::app_bsky::embed::record_with_media::RecordWithMedia;
use crate::app_bsky::embed::video::Video;
use crate::app_bsky::richtext::facet::Facet;
use crate::com_atproto::label::SelfLabels;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::app_bsky::feed::post;
/// Deprecated: use facets instead.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Entity<S: BosStr = DefaultStr> {
    pub index: post::TextSlice<S>,
    ///Expected values are 'mention' and 'link'.
    pub r#type: S,
    pub value: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Record containing a Bluesky post.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "app.bsky.feed.post",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Post<S: BosStr = DefaultStr> {
    ///Client-declared timestamp when this post was originally created.
    pub created_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub embed: Option<PostEmbed<S>>,
    ///DEPRECATED: replaced by app.bsky.richtext.facet.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub entities: Option<Vec<post::Entity<S>>>,
    ///Annotations of text (mentions, URLs, hashtags, etc)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub facets: Option<Vec<Facet<S>>>,
    ///Self-label values for this post. Effectively content warnings.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub labels: Option<SelfLabels<S>>,
    ///Indicates human language of post primary text content.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub langs: Option<Vec<Language>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reply: Option<post::ReplyRef<S>>,
    ///Additional hashtags, in addition to any included in post text and facets.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<S>>,
    ///The primary post content. May be an empty string, if there are embeds.
    pub text: 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 PostEmbed<S: BosStr = DefaultStr> {
    #[serde(rename = "app.bsky.embed.images")]
    Images(Box<Images<S>>),
    #[serde(rename = "app.bsky.embed.video")]
    Video(Box<Video<S>>),
    #[serde(rename = "app.bsky.embed.gallery")]
    Gallery(Box<Gallery<S>>),
    #[serde(rename = "app.bsky.embed.external")]
    External(Box<ExternalRecord<S>>),
    #[serde(rename = "app.bsky.embed.record")]
    Record(Box<Record<S>>),
    #[serde(rename = "app.bsky.embed.recordWithMedia")]
    RecordWithMedia(Box<RecordWithMedia<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 PostGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Post<S>,
}


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

/// Deprecated. Use app.bsky.richtext instead -- A text segment. Start is inclusive, end is exclusive. Indices are for utf16-encoded strings.

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

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

impl<S: BosStr> LexiconSchema for Entity<S> {
    fn nsid() -> &'static str {
        "app.bsky.feed.post"
    }
    fn def_name() -> &'static str {
        "entity"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct PostRecord;
impl XrpcResp for PostRecord {
    const NSID: &'static str = "app.bsky.feed.post";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = PostGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Post<S> {
    const NSID: &'static str = "app.bsky.feed.post";
    type Record = PostRecord;
}

impl Collection for PostRecord {
    const NSID: &'static str = "app.bsky.feed.post";
    type Record = PostRecord;
}

impl<S: BosStr> LexiconSchema for Post<S> {
    fn nsid() -> &'static str {
        "app.bsky.feed.post"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.langs {
            #[allow(unused_comparisons)]
            if value.len() > 3usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("langs"),
                    max: 3usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.tags {
            #[allow(unused_comparisons)]
            if value.len() > 8usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tags"),
                    max: 8usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.text;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 3000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("text"),
                    max: 3000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.text;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 300usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("text"),
                        max: 300usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ReplyRef<S> {
    fn nsid() -> &'static str {
        "app.bsky.feed.post"
    }
    fn def_name() -> &'static str {
        "replyRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for TextSlice<S> {
    fn nsid() -> &'static str {
        "app.bsky.feed.post"
    }
    fn def_name() -> &'static str {
        "textSlice"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_feed_post()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.end;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("end"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.start;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("start"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Entity<S> {
    /// Create a new builder for this type
    pub fn builder() -> EntityBuilder<entity_state::Empty, S> {
        EntityBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> EntityBuilder<St, S>
where
    St: entity_state::State,
    St::Type: entity_state::IsUnset,
{
    /// Set the `type` field (required)
    pub fn r#type(
        mut self,
        value: impl Into<S>,
    ) -> EntityBuilder<entity_state::SetType<St>, S> {
        self._fields.1 = Option::Some(value.into());
        EntityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EntityBuilder<St, S>
where
    St: entity_state::State,
    St::Value: entity_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<S>,
    ) -> EntityBuilder<entity_state::SetValue<St>, S> {
        self._fields.2 = Option::Some(value.into());
        EntityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EntityBuilder<St, S>
where
    St: entity_state::State,
    St::Index: entity_state::IsSet,
    St::Type: entity_state::IsSet,
    St::Value: entity_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Entity<S> {
        Entity {
            index: self._fields.0.unwrap(),
            r#type: self._fields.1.unwrap(),
            value: self._fields.2.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>>) -> Entity<S> {
        Entity {
            index: self._fields.0.unwrap(),
            r#type: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_feed_post() -> 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("app.bsky.feed.post"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("entity"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Deprecated: use facets instead."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("index"), SmolStr::new_static("type"),
                            SmolStr::new_static("value")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("index"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#textSlice"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("type"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Expected values are 'mention' and 'link'.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("Record containing a Bluesky post."),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("text"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when this post was originally created.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("embed"),
                                LexObjectProperty::Union(LexRefUnion {
                                    refs: vec![
                                        CowStr::new_static("app.bsky.embed.images"),
                                        CowStr::new_static("app.bsky.embed.video"),
                                        CowStr::new_static("app.bsky.embed.gallery"),
                                        CowStr::new_static("app.bsky.embed.external"),
                                        CowStr::new_static("app.bsky.embed.record"),
                                        CowStr::new_static("app.bsky.embed.recordWithMedia")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("entities"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "DEPRECATED: replaced by app.bsky.richtext.facet.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#entity"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("facets"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Annotations of text (mentions, URLs, hashtags, etc)",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("app.bsky.richtext.facet"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("labels"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "Self-label values for this post. Effectively content warnings.",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("com.atproto.label.defs#selfLabels")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("langs"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Indicates human language of post primary text content.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::Language),
                                        ..Default::default()
                                    }),
                                    max_length: Some(3usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("reply"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#replyRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("tags"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Additional hashtags, in addition to any included in post text and facets.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        max_length: Some(640usize),
                                        max_graphemes: Some(64usize),
                                        ..Default::default()
                                    }),
                                    max_length: Some(8usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("text"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The primary post content. May be an empty string, if there are embeds.",
                                        ),
                                    ),
                                    max_length: Some(3000usize),
                                    max_graphemes: Some(300usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("replyRef"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("root"), SmolStr::new_static("parent")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("parent"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("root"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("textSlice"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Deprecated. Use app.bsky.richtext instead -- A text segment. Start is inclusive, end is exclusive. Indices are for utf16-encoded strings.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("start"), SmolStr::new_static("end")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("end"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("start"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod post_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 Text;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Text = 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 Text = St::Text;
    }
    ///State transition - sets the `text` field to Set
    pub struct SetText<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetText<St> {}
    impl<St: State> State for SetText<St> {
        type CreatedAt = St::CreatedAt;
        type Text = Set<members::text>;
    }
    /// 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 `text` field
        pub struct text(());
    }
}

/// Builder for constructing an instance of this type.
pub struct PostBuilder<St: post_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Datetime>,
        Option<PostEmbed<S>>,
        Option<Vec<post::Entity<S>>>,
        Option<Vec<Facet<S>>>,
        Option<SelfLabels<S>>,
        Option<Vec<Language>>,
        Option<post::ReplyRef<S>>,
        Option<Vec<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Post<S> {
    /// Create a new builder for this type
    pub fn builder() -> PostBuilder<post_state::Empty, S> {
        PostBuilder::builder()
    }
}

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

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

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

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

impl<St: post_state::State, S: BosStr> PostBuilder<St, S> {
    /// Set the `entities` field (optional)
    pub fn entities(mut self, value: impl Into<Option<Vec<post::Entity<S>>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `entities` field to an Option value (optional)
    pub fn maybe_entities(mut self, value: Option<Vec<post::Entity<S>>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: post_state::State, S: BosStr> PostBuilder<St, S> {
    /// Set the `facets` field (optional)
    pub fn facets(mut self, value: impl Into<Option<Vec<Facet<S>>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `facets` field to an Option value (optional)
    pub fn maybe_facets(mut self, value: Option<Vec<Facet<S>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: post_state::State, S: BosStr> PostBuilder<St, S> {
    /// Set the `labels` field (optional)
    pub fn labels(mut self, value: impl Into<Option<SelfLabels<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `labels` field to an Option value (optional)
    pub fn maybe_labels(mut self, value: Option<SelfLabels<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: post_state::State, S: BosStr> PostBuilder<St, S> {
    /// Set the `langs` field (optional)
    pub fn langs(mut self, value: impl Into<Option<Vec<Language>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `langs` field to an Option value (optional)
    pub fn maybe_langs(mut self, value: Option<Vec<Language>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: post_state::State, S: BosStr> PostBuilder<St, S> {
    /// Set the `reply` field (optional)
    pub fn reply(mut self, value: impl Into<Option<post::ReplyRef<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `reply` field to an Option value (optional)
    pub fn maybe_reply(mut self, value: Option<post::ReplyRef<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: post_state::State, S: BosStr> PostBuilder<St, S> {
    /// Set the `tags` field (optional)
    pub fn tags(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.7 = 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.7 = value;
        self
    }
}

impl<St, S: BosStr> PostBuilder<St, S>
where
    St: post_state::State,
    St::Text: post_state::IsUnset,
{
    /// Set the `text` field (required)
    pub fn text(
        mut self,
        value: impl Into<S>,
    ) -> PostBuilder<post_state::SetText<St>, S> {
        self._fields.8 = Option::Some(value.into());
        PostBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PostBuilder<St, S>
where
    St: post_state::State,
    St::CreatedAt: post_state::IsSet,
    St::Text: post_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Post<S> {
        Post {
            created_at: self._fields.0.unwrap(),
            embed: self._fields.1,
            entities: self._fields.2,
            facets: self._fields.3,
            labels: self._fields.4,
            langs: self._fields.5,
            reply: self._fields.6,
            tags: self._fields.7,
            text: self._fields.8.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>>) -> Post<S> {
        Post {
            created_at: self._fields.0.unwrap(),
            embed: self._fields.1,
            entities: self._fields.2,
            facets: self._fields.3,
            labels: self._fields.4,
            langs: self._fields.5,
            reply: self._fields.6,
            tags: self._fields.7,
            text: self._fields.8.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> ReplyRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> ReplyRefBuilder<reply_ref_state::Empty, S> {
        ReplyRefBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ReplyRefBuilder<St, S>
where
    St: reply_ref_state::State,
    St::Parent: reply_ref_state::IsUnset,
{
    /// Set the `parent` field (required)
    pub fn parent(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> ReplyRefBuilder<reply_ref_state::SetParent<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ReplyRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReplyRefBuilder<St, S>
where
    St: reply_ref_state::State,
    St::Root: reply_ref_state::IsUnset,
{
    /// Set the `root` field (required)
    pub fn root(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> ReplyRefBuilder<reply_ref_state::SetRoot<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ReplyRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ReplyRefBuilder<St, S>
where
    St: reply_ref_state::State,
    St::Parent: reply_ref_state::IsSet,
    St::Root: reply_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ReplyRef<S> {
        ReplyRef {
            parent: self._fields.0.unwrap(),
            root: 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>>) -> ReplyRef<S> {
        ReplyRef {
            parent: self._fields.0.unwrap(),
            root: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> TextSlice<S> {
    /// Create a new builder for this type
    pub fn builder() -> TextSliceBuilder<text_slice_state::Empty, S> {
        TextSliceBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> TextSliceBuilder<St, S>
where
    St: text_slice_state::State,
    St::End: text_slice_state::IsSet,
    St::Start: text_slice_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> TextSlice<S> {
        TextSlice {
            end: self._fields.0.unwrap(),
            start: 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>>,
    ) -> TextSlice<S> {
        TextSlice {
            end: self._fields.0.unwrap(),
            start: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}