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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Item<'a> {
    ///Strong reference to an item in this collection. Items can be activities (org.hypercerts.claim.activity) and/or other collections (org.hypercerts.collection).
    #[serde(borrow)]
    pub item_identifier: StrongRef<'a>,
    ///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")]
    #[serde(borrow)]
    pub item_weight: Option<CowStr<'a>>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Collection<'a> {
    ///The collection's avatar/profile image as a URI or image blob.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub avatar: Option<CollectionAvatar<'a>>,
    ///Larger horizontal image to display behind the collection view.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub banner: Option<CollectionBanner<'a>>,
    ///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")]
    #[serde(borrow)]
    pub description: Option<LinearDocument<'a>>,
    ///Array of items in this collection with optional weights.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub items: Option<Vec<collection::Item<'a>>>,
    ///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")]
    #[serde(borrow)]
    pub location: Option<StrongRef<'a>>,
    ///Short summary of this collection, suitable for previews and list views
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub short_description: Option<CowStr<'a>>,
    ///Display name for this collection (e.g. 'Q1 2025 Impact Projects')
    #[serde(borrow)]
    pub title: CowStr<'a>,
    ///The type of this collection. Possible fields can be 'favorites', 'project', or any other type of collection.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub r#type: Option<CowStr<'a>>,
}


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


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

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

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

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

impl jacquard_common::types::collection::Collection for Collection<'_> {
    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<'a> LexiconSchema for Collection<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetItemIdentifier<S> {}
    impl<S: State> State for SetItemIdentifier<S> {
        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<'a, S: item_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<StrongRef<'a>>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> ItemBuilder<'a, S>
where
    S: item_state::State,
    S::ItemIdentifier: item_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Item<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Item<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type CreatedAt = Set<members::created_at>;
        type Title = S::Title;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTitle<S> {}
    impl<S: State> State for SetTitle<S> {
        type CreatedAt = S::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<'a, S: collection_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CollectionAvatar<'a>>,
        Option<CollectionBanner<'a>>,
        Option<Datetime>,
        Option<LinearDocument<'a>>,
        Option<Vec<collection::Item<'a>>>,
        Option<StrongRef<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
    /// Set the `avatar` field (optional)
    pub fn avatar(mut self, value: impl Into<Option<CollectionAvatar<'a>>>) -> 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<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
    /// Set the `items` field (optional)
    pub fn items(mut self, value: impl Into<Option<Vec<collection::Item<'a>>>>) -> 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<'a>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<'a, S: collection_state::State> CollectionBuilder<'a, S> {
    /// Set the `location` field (optional)
    pub fn location(mut self, value: impl Into<Option<StrongRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

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

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

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

impl<'a, S> CollectionBuilder<'a, S>
where
    S: collection_state::State,
    S::CreatedAt: collection_state::IsSet,
    S::Title: collection_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Collection<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Collection<'a> {
        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),
        }
    }
}