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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::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::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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Entity<'a> {
    #[serde(borrow)]
    pub index: post::TextSlice<'a>,
    ///Expected values are 'mention' and 'link'.
    #[serde(borrow)]
    pub r#type: CowStr<'a>,
    #[serde(borrow)]
    pub value: CowStr<'a>,
}

/// Record containing a Bluesky post.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Post<'a> {
    ///Client-declared timestamp when this post was originally created.
    pub created_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub embed: Option<PostEmbed<'a>>,
    ///DEPRECATED: replaced by app.bsky.richtext.facet.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub entities: Option<Vec<post::Entity<'a>>>,
    ///Annotations of text (mentions, URLs, hashtags, etc)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub facets: Option<Vec<Facet<'a>>>,
    ///Self-label values for this post. Effectively content warnings.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub labels: Option<SelfLabels<'a>>,
    ///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")]
    #[serde(borrow)]
    pub reply: Option<post::ReplyRef<'a>>,
    ///Additional hashtags, in addition to any included in post text and facets.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub tags: Option<Vec<CowStr<'a>>>,
    ///The primary post content. May be an empty string, if there are embeds.
    #[serde(borrow)]
    pub text: CowStr<'a>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum PostEmbed<'a> {
    #[serde(rename = "app.bsky.embed.images")]
    Images(Box<Images<'a>>),
    #[serde(rename = "app.bsky.embed.video")]
    Video(Box<Video<'a>>),
    #[serde(rename = "app.bsky.embed.external")]
    External(Box<ExternalRecord<'a>>),
    #[serde(rename = "app.bsky.embed.record")]
    Record(Box<Record<'a>>),
    #[serde(rename = "app.bsky.embed.recordWithMedia")]
    RecordWithMedia(Box<RecordWithMedia<'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 PostGetRecordOutput<'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: Post<'a>,
}


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

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

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

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

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

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

impl Collection for Post<'_> {
    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<'a> LexiconSchema for Post<'a> {
    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<'a> LexiconSchema for ReplyRef<'a> {
    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<'a> LexiconSchema for TextSlice<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIndex<S> {}
    impl<S: State> State for SetIndex<S> {
        type Index = Set<members::index>;
        type Type = S::Type;
        type Value = S::Value;
    }
    ///State transition - sets the `type` field to Set
    pub struct SetType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetType<S> {}
    impl<S: State> State for SetType<S> {
        type Index = S::Index;
        type Type = Set<members::r#type>;
        type Value = S::Value;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetValue<S> {}
    impl<S: State> State for SetValue<S> {
        type Index = S::Index;
        type Type = S::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<'a, S: entity_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<post::TextSlice<'a>>, Option<CowStr<'a>>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> EntityBuilder<'a, S>
where
    S: entity_state::State,
    S::Index: entity_state::IsSet,
    S::Type: entity_state::IsSet,
    S::Value: entity_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Entity<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Entity<'a> {
        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.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 Text;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Text = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `text` field to Set
    pub struct SetText<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetText<S> {}
    impl<S: State> State for SetText<S> {
        type Text = Set<members::text>;
        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 Text = S::Text;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `text` field
        pub struct text(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct PostBuilder<'a, S: post_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Datetime>,
        Option<PostEmbed<'a>>,
        Option<Vec<post::Entity<'a>>>,
        Option<Vec<Facet<'a>>>,
        Option<SelfLabels<'a>>,
        Option<Vec<Language>>,
        Option<post::ReplyRef<'a>>,
        Option<Vec<CowStr<'a>>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

impl<'a, S: post_state::State> PostBuilder<'a, 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<'a, S: post_state::State> PostBuilder<'a, S> {
    /// Set the `reply` field (optional)
    pub fn reply(mut self, value: impl Into<Option<post::ReplyRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

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

impl<'a, S> PostBuilder<'a, S>
where
    S: post_state::State,
    S::Text: post_state::IsSet,
    S::CreatedAt: post_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Post<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Post<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetParent<S> {}
    impl<S: State> State for SetParent<S> {
        type Parent = Set<members::parent>;
        type Root = S::Root;
    }
    ///State transition - sets the `root` field to Set
    pub struct SetRoot<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRoot<S> {}
    impl<S: State> State for SetRoot<S> {
        type Parent = S::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<'a, S: reply_ref_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<StrongRef<'a>>, Option<StrongRef<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> ReplyRefBuilder<'a, S>
where
    S: reply_ref_state::State,
    S::Parent: reply_ref_state::IsSet,
    S::Root: reply_ref_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ReplyRef<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> ReplyRef<'a> {
        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 Start;
        type End;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Start = Unset;
        type End = Unset;
    }
    ///State transition - sets the `start` field to Set
    pub struct SetStart<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetStart<S> {}
    impl<S: State> State for SetStart<S> {
        type Start = Set<members::start>;
        type End = S::End;
    }
    ///State transition - sets the `end` field to Set
    pub struct SetEnd<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEnd<S> {}
    impl<S: State> State for SetEnd<S> {
        type Start = S::Start;
        type End = Set<members::end>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `start` field
        pub struct start(());
        ///Marker type for the `end` field
        pub struct end(());
    }
}

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

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

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

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

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

impl<'a, S> TextSliceBuilder<'a, S>
where
    S: text_slice_state::State,
    S::Start: text_slice_state::IsSet,
    S::End: text_slice_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> TextSlice<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> TextSlice<'a> {
        TextSlice {
            end: self._fields.0.unwrap(),
            start: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}