// @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, 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};
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::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).

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

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

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

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

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

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "com.deckbelcher.social.comment",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Comment<S: BosStr = DefaultStr> {
    ///Rich text content.
    pub content: Document<S>,
    pub created_at: Datetime,
    ///What this comment is on.
    pub subject: CommentSubject<S>,
    ///Optional refinement within subject (card/section/tag in a deck).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target: Option<CommentTarget<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    #[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 CommentSubject<S: BosStr = DefaultStr> {
    #[serde(rename = "com.deckbelcher.social.comment#cardSubject")]
    CardSubject(Box<comment::CardSubject<S>>),
    #[serde(rename = "com.deckbelcher.social.comment#recordSubject")]
    RecordSubject(Box<comment::RecordSubject<S>>),
}


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

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

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

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

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

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

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

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

impl<S: BosStr> LexiconSchema for CardSubject<S> {
    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<S: BosStr> LexiconSchema for CardTarget<S> {
    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<S: BosStr> LexiconSchema for DeckTarget<S> {
    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<S: BosStr> = CommentGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Comment<S> {
    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<S: BosStr> LexiconSchema for Comment<S> {
    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<S: BosStr> LexiconSchema for RecordSubject<S> {
    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<S: BosStr> LexiconSchema for SectionTarget<S> {
    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<S: BosStr> LexiconSchema for TagTarget<S> {
    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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRef<St> {}
    impl<St: State> State for SetRef<St> {
        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<St: card_subject_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<CardRef<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> CardSubjectBuilder<St, S>
where
    St: card_subject_state::State,
    St::Ref: card_subject_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CardSubject<S> {
        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<SmolStr, Data<S>>,
    ) -> CardSubject<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRef<St> {}
    impl<St: State> State for SetRef<St> {
        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<St: card_target_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<CardRef<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> CardTargetBuilder<St, S>
where
    St: card_target_state::State,
    St::Ref: card_target_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CardTarget<S> {
        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<SmolStr, Data<S>>,
    ) -> CardTarget<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRef<St> {}
    impl<St: State> State for SetRef<St> {
        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<St: deck_target_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<StrongRef<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

impl<St, S: BosStr> DeckTargetBuilder<St, S>
where
    St: deck_target_state::State,
    St::Ref: deck_target_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> DeckTarget<S> {
        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<SmolStr, Data<S>>,
    ) -> DeckTarget<S> {
        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 Content;
        type CreatedAt;
        type Subject;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Content = Unset;
        type CreatedAt = Unset;
        type Subject = Unset;
    }
    ///State transition - sets the `content` field to Set
    pub struct SetContent<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetContent<St> {}
    impl<St: State> State for SetContent<St> {
        type Content = Set<members::content>;
        type CreatedAt = St::CreatedAt;
        type Subject = St::Subject;
    }
    ///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 Content = St::Content;
        type CreatedAt = Set<members::created_at>;
        type Subject = St::Subject;
    }
    ///State transition - sets the `subject` field to Set
    pub struct SetSubject<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSubject<St> {}
    impl<St: State> State for SetSubject<St> {
        type Content = St::Content;
        type CreatedAt = St::CreatedAt;
        type Subject = Set<members::subject>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `content` field
        pub struct content(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `subject` field
        pub struct subject(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CommentBuilder<St: comment_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Document<S>>,
        Option<Datetime>,
        Option<CommentSubject<S>>,
        Option<CommentTarget<S>>,
        Option<Datetime>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

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

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

impl<St: comment_state::State, S: BosStr> CommentBuilder<St, 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<St, S: BosStr> CommentBuilder<St, S>
where
    St: comment_state::State,
    St::Content: comment_state::IsSet,
    St::CreatedAt: comment_state::IsSet,
    St::Subject: comment_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Comment<S> {
        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<SmolStr, Data<S>>) -> Comment<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRef<St> {}
    impl<St: State> State for SetRef<St> {
        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<
    St: record_subject_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<StrongRef<S>>,),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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