// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.deckbelcher.social.comment
//
// 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};
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::com_atproto::repo::strong_ref::StrongRef;
use crate::com_deckbelcher::CardRef;
use crate::com_deckbelcher::richtext::Document;
use crate::com_deckbelcher::social::comment;
/// Subject: a card (global comment on the card itself).

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

/// Target: a card (in a deck or collection).

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

/// Target: a deck (in a collection).

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

/// Top-level comment on a card, deck, or collection.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Comment<'a> {
    ///Rich text content.
    #[serde(borrow)]
    pub content: Document<'a>,
    pub created_at: Datetime,
    ///What this comment is on.
    #[serde(borrow)]
    pub subject: CommentSubject<'a>,
    ///Optional refinement within subject (card/section/tag in a deck).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub target: Option<CommentTarget<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum CommentSubject<'a> {
    #[serde(rename = "com.deckbelcher.social.comment#cardSubject")]
    CardSubject(Box<comment::CardSubject<'a>>),
    #[serde(rename = "com.deckbelcher.social.comment#recordSubject")]
    RecordSubject(Box<comment::RecordSubject<'a>>),
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum CommentTarget<'a> {
    #[serde(rename = "com.deckbelcher.social.comment#cardTarget")]
    CardTarget(Box<comment::CardTarget<'a>>),
    #[serde(rename = "com.deckbelcher.social.comment#deckTarget")]
    DeckTarget(Box<comment::DeckTarget<'a>>),
    #[serde(rename = "com.deckbelcher.social.comment#sectionTarget")]
    SectionTarget(Box<comment::SectionTarget<'a>>),
    #[serde(rename = "com.deckbelcher.social.comment#tagTarget")]
    TagTarget(Box<comment::TagTarget<'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 CommentGetRecordOutput<'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: Comment<'a>,
}

/// Subject: an ATProto record (deck, collection).

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

/// Target: a deck section (mainboard, sideboard, etc).

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

/// Target: a tag package (ramp, removal, wincons, etc).

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

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

impl<'a> LexiconSchema for CardSubject<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.social.comment"
    }
    fn def_name() -> &'static str {
        "cardSubject"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_social_comment()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for CardTarget<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.social.comment"
    }
    fn def_name() -> &'static str {
        "cardTarget"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_social_comment()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for DeckTarget<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.social.comment"
    }
    fn def_name() -> &'static str {
        "deckTarget"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_social_comment()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct CommentRecord;
impl XrpcResp for CommentRecord {
    const NSID: &'static str = "com.deckbelcher.social.comment";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = CommentGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Comment<'_> {
    const NSID: &'static str = "com.deckbelcher.social.comment";
    type Record = CommentRecord;
}

impl Collection for CommentRecord {
    const NSID: &'static str = "com.deckbelcher.social.comment";
    type Record = CommentRecord;
}

impl<'a> LexiconSchema for Comment<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.social.comment"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_social_comment()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for RecordSubject<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.social.comment"
    }
    fn def_name() -> &'static str {
        "recordSubject"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_social_comment()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for SectionTarget<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.social.comment"
    }
    fn def_name() -> &'static str {
        "sectionTarget"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_social_comment()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.section;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("section"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.section;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("section"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for TagTarget<'a> {
    fn nsid() -> &'static str {
        "com.deckbelcher.social.comment"
    }
    fn def_name() -> &'static str {
        "tagTarget"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_deckbelcher_social_comment()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.tag;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("tag"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.tag;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("tag"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

impl<'a> CardSubject<'a> {
    /// Create a new builder for this type
    pub fn new() -> CardSubjectBuilder<'a, card_subject_state::Empty> {
        CardSubjectBuilder::new()
    }
}

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

impl<'a, S> CardSubjectBuilder<'a, S>
where
    S: card_subject_state::State,
    S::Ref: card_subject_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<CardRef<'a>>,
    ) -> CardSubjectBuilder<'a, card_subject_state::SetRef<S>> {
        self._fields.0 = Option::Some(value.into());
        CardSubjectBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CardSubjectBuilder<'a, S>
where
    S: card_subject_state::State,
    S::Ref: card_subject_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CardSubject<'a> {
        CardSubject {
            r#ref: 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,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> CardSubject<'a> {
        CardSubject {
            r#ref: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_deckbelcher_social_comment() -> 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("com.deckbelcher.social.comment"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("cardSubject"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Subject: a card (global comment on the card itself).",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("ref")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.deckbelcher.defs#cardRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("cardTarget"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Target: a card (in a deck or collection)."),
                    ),
                    required: Some(vec![SmolStr::new_static("ref")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.deckbelcher.defs#cardRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("deckTarget"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Target: a deck (in a collection)."),
                    ),
                    required: Some(vec![SmolStr::new_static("ref")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "Top-level comment on a card, deck, or collection.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("subject"),
                                SmolStr::new_static("content"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("content"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "com.deckbelcher.richtext#document",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("subject"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static("What this comment is on."),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("#cardSubject"),
                                        CowStr::new_static("#recordSubject")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("target"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optional refinement within subject (card/section/tag in a deck).",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("#cardTarget"),
                                        CowStr::new_static("#deckTarget"),
                                        CowStr::new_static("#sectionTarget"),
                                        CowStr::new_static("#tagTarget")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("recordSubject"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Subject: an ATProto record (deck, collection).",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("ref")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("ref"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("sectionTarget"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Target: a deck section (mainboard, sideboard, etc).",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("section")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("section"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(640usize),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("tagTarget"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Target: a tag package (ramp, removal, wincons, etc).",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("tag")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("tag"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(640usize),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

impl<'a> CardTarget<'a> {
    /// Create a new builder for this type
    pub fn new() -> CardTargetBuilder<'a, card_target_state::Empty> {
        CardTargetBuilder::new()
    }
}

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

impl<'a, S> CardTargetBuilder<'a, S>
where
    S: card_target_state::State,
    S::Ref: card_target_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<CardRef<'a>>,
    ) -> CardTargetBuilder<'a, card_target_state::SetRef<S>> {
        self._fields.0 = Option::Some(value.into());
        CardTargetBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> CardTargetBuilder<'a, S>
where
    S: card_target_state::State,
    S::Ref: card_target_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CardTarget<'a> {
        CardTarget {
            r#ref: 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,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> CardTarget<'a> {
        CardTarget {
            r#ref: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

impl<'a> DeckTarget<'a> {
    /// Create a new builder for this type
    pub fn new() -> DeckTargetBuilder<'a, deck_target_state::Empty> {
        DeckTargetBuilder::new()
    }
}

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

impl<'a, S> DeckTargetBuilder<'a, S>
where
    S: deck_target_state::State,
    S::Ref: deck_target_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<StrongRef<'a>>,
    ) -> DeckTargetBuilder<'a, deck_target_state::SetRef<S>> {
        self._fields.0 = Option::Some(value.into());
        DeckTargetBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> DeckTargetBuilder<'a, S>
where
    S: deck_target_state::State,
    S::Ref: deck_target_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> DeckTarget<'a> {
        DeckTarget {
            r#ref: 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,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> DeckTarget<'a> {
        DeckTarget {
            r#ref: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod comment_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 Subject;
        type Content;
        type CreatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Subject = Unset;
        type Content = Unset;
        type CreatedAt = Unset;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSubject<S> {}
    impl<S: State> State for SetSubject<S> {
        type Subject = Set<members::subject>;
        type Content = S::Content;
        type CreatedAt = S::CreatedAt;
    }
    ///State transition - sets the `content` field to Set
    pub struct SetContent<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContent<S> {}
    impl<S: State> State for SetContent<S> {
        type Subject = S::Subject;
        type Content = Set<members::content>;
        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 Subject = S::Subject;
        type Content = S::Content;
        type CreatedAt = Set<members::created_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `subject` field
        pub struct subject(());
        ///Marker type for the `content` field
        pub struct content(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct CommentBuilder<'a, S: comment_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Document<'a>>,
        Option<Datetime>,
        Option<CommentSubject<'a>>,
        Option<CommentTarget<'a>>,
        Option<Datetime>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Comment<'a> {
    /// Create a new builder for this type
    pub fn new() -> CommentBuilder<'a, comment_state::Empty> {
        CommentBuilder::new()
    }
}

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

impl<'a, S> CommentBuilder<'a, S>
where
    S: comment_state::State,
    S::Content: comment_state::IsUnset,
{
    /// Set the `content` field (required)
    pub fn content(
        mut self,
        value: impl Into<Document<'a>>,
    ) -> CommentBuilder<'a, comment_state::SetContent<S>> {
        self._fields.0 = Option::Some(value.into());
        CommentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> CommentBuilder<'a, S>
where
    S: comment_state::State,
    S::Subject: comment_state::IsUnset,
{
    /// Set the `subject` field (required)
    pub fn subject(
        mut self,
        value: impl Into<CommentSubject<'a>>,
    ) -> CommentBuilder<'a, comment_state::SetSubject<S>> {
        self._fields.2 = Option::Some(value.into());
        CommentBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
    /// Set the `target` field (optional)
    pub fn target(mut self, value: impl Into<Option<CommentTarget<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `target` field to an Option value (optional)
    pub fn maybe_target(mut self, value: Option<CommentTarget<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: comment_state::State> CommentBuilder<'a, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `updatedAt` field to an Option value (optional)
    pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S> CommentBuilder<'a, S>
where
    S: comment_state::State,
    S::Subject: comment_state::IsSet,
    S::Content: comment_state::IsSet,
    S::CreatedAt: comment_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Comment<'a> {
        Comment {
            content: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            subject: self._fields.2.unwrap(),
            target: self._fields.3,
            updated_at: self._fields.4,
            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>,
        >,
    ) -> Comment<'a> {
        Comment {
            content: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            subject: self._fields.2.unwrap(),
            target: self._fields.3,
            updated_at: self._fields.4,
            extra_data: Some(extra_data),
        }
    }
}

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

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

impl<'a> RecordSubject<'a> {
    /// Create a new builder for this type
    pub fn new() -> RecordSubjectBuilder<'a, record_subject_state::Empty> {
        RecordSubjectBuilder::new()
    }
}

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

impl<'a, S> RecordSubjectBuilder<'a, S>
where
    S: record_subject_state::State,
    S::Ref: record_subject_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<StrongRef<'a>>,
    ) -> RecordSubjectBuilder<'a, record_subject_state::SetRef<S>> {
        self._fields.0 = Option::Some(value.into());
        RecordSubjectBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RecordSubjectBuilder<'a, S>
where
    S: record_subject_state::State,
    S::Ref: record_subject_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RecordSubject<'a> {
        RecordSubject {
            r#ref: 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,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> RecordSubject<'a> {
        RecordSubject {
            r#ref: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}