// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.hypercerts.collection
//
// 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::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::org_hypercerts::LargeImage;
use crate::org_hypercerts::SmallImage;
use crate::org_hypercerts::Uri;
use crate::pub_leaflet::pages::linear_document::LinearDocument;
use crate::org_hypercerts::collection;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Item<S: BosStr = DefaultStr> {
    ///Strong reference to an item in this collection. Items can be activities (org.hypercerts.claim.activity) and/or other collections (org.hypercerts.collection).
    pub item_identifier: StrongRef<S>,
    ///Optional weight for this item (positive numeric value stored as string). Weights do not need to sum to a specific total; normalization can be performed by the consuming application as needed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub item_weight: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A collection/group of items (activities and/or other collections). Collections support recursive nesting.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "org.hypercerts.collection",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Collection<S: BosStr = DefaultStr> {
    ///The collection's avatar/profile image as a URI or image blob.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<CollectionAvatar<S>>,
    ///Larger horizontal image to display behind the collection view.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub banner: Option<CollectionBanner<S>>,
    ///Client-declared timestamp when this record was originally created
    pub created_at: Datetime,
    ///Rich-text description, represented as a Leaflet linear document.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<LinearDocument<S>>,
    ///Array of items in this collection with optional weights.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub items: Option<Vec<collection::Item<S>>>,
    ///A strong reference to the location where this collection's activities were performed. The record referenced must conform with the lexicon app.certified.location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<StrongRef<S>>,
    ///Short summary of this collection, suitable for previews and list views
    #[serde(skip_serializing_if = "Option::is_none")]
    pub short_description: Option<S>,
    ///Display name for this collection (e.g. 'Q1 2025 Impact Projects')
    pub title: S,
    ///The type of this collection. Possible fields can be 'favorites', 'project', or any other type of collection.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CollectionAvatar<S: BosStr = DefaultStr> {
    #[serde(rename = "org.hypercerts.defs#uri")]
    Uri(Box<Uri<S>>),
    #[serde(rename = "org.hypercerts.defs#smallImage")]
    SmallImage(Box<SmallImage<S>>),
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum CollectionBanner<S: BosStr = DefaultStr> {
    #[serde(rename = "org.hypercerts.defs#uri")]
    Uri(Box<Uri<S>>),
    #[serde(rename = "org.hypercerts.defs#largeImage")]
    LargeImage(Box<LargeImage<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 CollectionGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Collection<S>,
}

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

impl<S: BosStr> LexiconSchema for Item<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.collection"
    }
    fn def_name() -> &'static str {
        "item"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_collection()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.item_weight {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("item_weight"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct CollectionRecord;
impl XrpcResp for CollectionRecord {
    const NSID: &'static str = "org.hypercerts.collection";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = CollectionGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> jacquard_common::types::collection::Collection for Collection<S> {
    const NSID: &'static str = "org.hypercerts.collection";
    type Record = CollectionRecord;
}

impl jacquard_common::types::collection::Collection for CollectionRecord {
    const NSID: &'static str = "org.hypercerts.collection";
    type Record = CollectionRecord;
}

impl<S: BosStr> LexiconSchema for Collection<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.collection"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_collection()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.items {
            #[allow(unused_comparisons)]
            if value.len() > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("items"),
                    max: 1000usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.short_description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 3000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("short_description"),
                    max: 3000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.short_description {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 300usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("short_description"),
                        max: 300usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.title;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 800usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 800usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.title;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 80usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("title"),
                        max: 80usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.r#type {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 64usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("type"),
                    max: 64usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Item<S> {
    /// Create a new builder for this type
    pub fn builder() -> ItemBuilder<item_state::Empty, S> {
        ItemBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ItemBuilder<St, S>
where
    St: item_state::State,
    St::ItemIdentifier: item_state::IsUnset,
{
    /// Set the `itemIdentifier` field (required)
    pub fn item_identifier(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> ItemBuilder<item_state::SetItemIdentifier<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ItemBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: item_state::State, S: BosStr> ItemBuilder<St, S> {
    /// Set the `itemWeight` field (optional)
    pub fn item_weight(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `itemWeight` field to an Option value (optional)
    pub fn maybe_item_weight(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> ItemBuilder<St, S>
where
    St: item_state::State,
    St::ItemIdentifier: item_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Item<S> {
        Item {
            item_identifier: self._fields.0.unwrap(),
            item_weight: self._fields.1,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Item<S> {
        Item {
            item_identifier: self._fields.0.unwrap(),
            item_weight: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_hypercerts_collection() -> 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("org.hypercerts.collection"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("item"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("itemIdentifier")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("itemIdentifier"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("itemWeight"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional weight for this item (positive numeric value stored as string). Weights do not need to sum to a specific total; normalization can be performed by the consuming application as needed.",
                                    ),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A collection/group of items (activities and/or other collections). Collections support recursive nesting.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("title"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("avatar"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "The collection's avatar/profile image as a URI or image blob.",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("org.hypercerts.defs#uri"),
                                        CowStr::new_static("org.hypercerts.defs#smallImage")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("banner"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "Larger horizontal image to display behind the collection view.",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("org.hypercerts.defs#uri"),
                                        CowStr::new_static("org.hypercerts.defs#largeImage")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when this record was originally created",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "pub.leaflet.pages.linearDocument#main",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("items"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Array of items in this collection with optional weights.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#item"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("location"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("shortDescription"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Short summary of this collection, suitable for previews and list views",
                                        ),
                                    ),
                                    max_length: Some(3000usize),
                                    max_graphemes: Some(300usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Display name for this collection (e.g. 'Q1 2025 Impact Projects')",
                                        ),
                                    ),
                                    max_length: Some(800usize),
                                    max_graphemes: Some(80usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("type"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The type of this collection. Possible fields can be 'favorites', 'project', or any other type of collection.",
                                        ),
                                    ),
                                    max_length: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod collection_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type CreatedAt;
        type Title;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Title = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Title = St::Title;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type CreatedAt = St::CreatedAt;
        type Title = Set<members::title>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CollectionBuilder<St: collection_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<CollectionAvatar<S>>,
        Option<CollectionBanner<S>>,
        Option<Datetime>,
        Option<LinearDocument<S>>,
        Option<Vec<collection::Item<S>>>,
        Option<StrongRef<S>>,
        Option<S>,
        Option<S>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Collection<S> {
    /// Create a new builder for this type
    pub fn builder() -> CollectionBuilder<collection_state::Empty, S> {
        CollectionBuilder::builder()
    }
}

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

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

impl<St: collection_state::State, S: BosStr> CollectionBuilder<St, S> {
    /// Set the `avatar` field (optional)
    pub fn avatar(mut self, value: impl Into<Option<CollectionAvatar<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `avatar` field to an Option value (optional)
    pub fn maybe_avatar(mut self, value: Option<CollectionAvatar<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: collection_state::State, S: BosStr> CollectionBuilder<St, S> {
    /// Set the `banner` field (optional)
    pub fn banner(mut self, value: impl Into<Option<CollectionBanner<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `banner` field to an Option value (optional)
    pub fn maybe_banner(mut self, value: Option<CollectionBanner<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<St: collection_state::State, S: BosStr> CollectionBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<LinearDocument<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<LinearDocument<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: collection_state::State, S: BosStr> CollectionBuilder<St, S> {
    /// Set the `items` field (optional)
    pub fn items(mut self, value: impl Into<Option<Vec<collection::Item<S>>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `items` field to an Option value (optional)
    pub fn maybe_items(mut self, value: Option<Vec<collection::Item<S>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: collection_state::State, S: BosStr> CollectionBuilder<St, S> {
    /// Set the `location` field (optional)
    pub fn location(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `location` field to an Option value (optional)
    pub fn maybe_location(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: collection_state::State, S: BosStr> CollectionBuilder<St, S> {
    /// Set the `shortDescription` field (optional)
    pub fn short_description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `shortDescription` field to an Option value (optional)
    pub fn maybe_short_description(mut self, value: Option<S>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> CollectionBuilder<St, S>
where
    St: collection_state::State,
    St::Title: collection_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> CollectionBuilder<collection_state::SetTitle<St>, S> {
        self._fields.7 = Option::Some(value.into());
        CollectionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: collection_state::State, S: BosStr> CollectionBuilder<St, S> {
    /// Set the `type` field (optional)
    pub fn r#type(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `type` field to an Option value (optional)
    pub fn maybe_type(mut self, value: Option<S>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St, S: BosStr> CollectionBuilder<St, S>
where
    St: collection_state::State,
    St::CreatedAt: collection_state::IsSet,
    St::Title: collection_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Collection<S> {
        Collection {
            avatar: self._fields.0,
            banner: self._fields.1,
            created_at: self._fields.2.unwrap(),
            description: self._fields.3,
            items: self._fields.4,
            location: self._fields.5,
            short_description: self._fields.6,
            title: self._fields.7.unwrap(),
            r#type: self._fields.8,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Collection<S> {
        Collection {
            avatar: self._fields.0,
            banner: self._fields.1,
            created_at: self._fields.2.unwrap(),
            description: self._fields.3,
            items: self._fields.4,
            location: self._fields.5,
            short_description: self._fields.6,
            title: self._fields.7.unwrap(),
            r#type: self._fields.8,
            extra_data: Some(extra_data),
        }
    }
}