// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: org.hypercerts.claim.activity
//
// 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::app_bsky::richtext::facet::Facet;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::org_hypercerts::SmallImage;
use crate::org_hypercerts::Uri;
use crate::org_hypercerts::workscope::cel::Cel;
use crate::pub_leaflet::pages::linear_document::LinearDocument;
use crate::org_hypercerts::claim::activity;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Contributor<S: BosStr = DefaultStr> {
    ///Inline contribution role object with a role string via org.hypercerts.claim.activity#contributorRole, or a strong reference to a contribution details record. The record referenced must conform with the lexicon org.hypercerts.claim.contribution.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contribution_details: Option<ContributorContributionDetails<S>>,
    ///The relative weight/importance of this contribution (stored as a string to avoid float precision issues). Must be a positive numeric value. 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 contribution_weight: Option<S>,
    ///Inline contributor identity object with an identity string (DID or identifier) via org.hypercerts.claim.activity#contributorIdentity, or a strong reference to a contributor information record. The record referenced must conform with the lexicon org.hypercerts.claim.contributorInformation.
    pub contributor_identity: ContributorContributorIdentity<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 ContributorContributionDetails<S: BosStr = DefaultStr> {
    #[serde(rename = "org.hypercerts.claim.activity#contributorRole")]
    ContributorRole(Box<activity::ContributorRole<S>>),
    #[serde(rename = "com.atproto.repo.strongRef")]
    StrongRef(Box<StrongRef<S>>),
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum ContributorContributorIdentity<S: BosStr = DefaultStr> {
    #[serde(rename = "org.hypercerts.claim.activity#contributorIdentity")]
    ContributorIdentity(Box<activity::ContributorIdentity<S>>),
    #[serde(rename = "com.atproto.repo.strongRef")]
    StrongRef(Box<StrongRef<S>>),
}

/// Contributor information as a string (DID or identifier).

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ContributorIdentity<S: BosStr = DefaultStr> {
    ///The contributor identity string (DID or identifier).
    pub identity: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Contribution details as a string.

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

/// A hypercert record tracking impact work.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "org.hypercerts.claim.activity",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Activity<S: BosStr = DefaultStr> {
    ///An array of contributor objects, each containing contributor information, weight, and contribution details.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub contributors: Option<Vec<activity::Contributor<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>>,
    ///When the work ended
    #[serde(skip_serializing_if = "Option::is_none")]
    pub end_date: Option<Datetime>,
    ///The hypercert visual representation as a URI or image blob.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image: Option<ActivityImage<S>>,
    ///An array of strong references to the location where activity was performed. The record referenced must conform with the lexicon app.certified.location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub locations: Option<Vec<StrongRef<S>>>,
    ///A strong reference to the rights that this hypercert has. The record referenced must conform with the lexicon org.hypercerts.claim.rights.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rights: Option<StrongRef<S>>,
    ///Short summary of this activity claim, suitable for previews and list views. Rich text annotations may be provided via `shortDescriptionFacets`.
    pub short_description: S,
    ///Rich text annotations for `shortDescription` (mentions, URLs, hashtags, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub short_description_facets: Option<Vec<Facet<S>>>,
    ///When the work began
    #[serde(skip_serializing_if = "Option::is_none")]
    pub start_date: Option<Datetime>,
    ///Display title summarizing the impact work (e.g. 'Reforestation in Amazon Basin 2024')
    pub title: S,
    ///Work scope definition. A CEL expression for structured, machine-evaluable scopes or a free-form string for simple and legacy scopes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub work_scope: Option<ActivityWorkScope<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 ActivityImage<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 ActivityWorkScope<S: BosStr = DefaultStr> {
    #[serde(rename = "org.hypercerts.workscope.cel")]
    Cel(Box<Cel<S>>),
    #[serde(rename = "org.hypercerts.claim.activity#workScopeString")]
    WorkScopeString(Box<activity::WorkScopeString<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 ActivityGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Activity<S>,
}

/// A free-form string describing the work scope for simple or legacy scopes.

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

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

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

impl<S: BosStr> LexiconSchema for ContributorIdentity<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.claim.activity"
    }
    fn def_name() -> &'static str {
        "contributorIdentity"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_claim_activity()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.identity;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("identity"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.identity;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 100usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("identity"),
                        max: 100usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ContributorRole<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.claim.activity"
    }
    fn def_name() -> &'static str {
        "contributorRole"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_claim_activity()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.role;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("role"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.role;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 100usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("role"),
                        max: 100usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Collection for Activity<S> {
    const NSID: &'static str = "org.hypercerts.claim.activity";
    type Record = ActivityRecord;
}

impl Collection for ActivityRecord {
    const NSID: &'static str = "org.hypercerts.claim.activity";
    type Record = ActivityRecord;
}

impl<S: BosStr> LexiconSchema for Activity<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.claim.activity"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_claim_activity()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.contributors {
            #[allow(unused_comparisons)]
            if value.len() > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("contributors"),
                    max: 1000usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.locations {
            #[allow(unused_comparisons)]
            if value.len() > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("locations"),
                    max: 1000usize,
                    actual: value.len(),
                });
            }
        }
        {
            let 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()),
                });
            }
        }
        {
            let 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()) > 256usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 256usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for WorkScopeString<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.claim.activity"
    }
    fn def_name() -> &'static str {
        "workScopeString"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_claim_activity()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.scope;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("scope"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.scope;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 100usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("scope"),
                        max: 100usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Contributor<S> {
    /// Create a new builder for this type
    pub fn builder() -> ContributorBuilder<contributor_state::Empty, S> {
        ContributorBuilder::builder()
    }
}

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

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

impl<St: contributor_state::State, S: BosStr> ContributorBuilder<St, S> {
    /// Set the `contributionDetails` field (optional)
    pub fn contribution_details(
        mut self,
        value: impl Into<Option<ContributorContributionDetails<S>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `contributionDetails` field to an Option value (optional)
    pub fn maybe_contribution_details(
        mut self,
        value: Option<ContributorContributionDetails<S>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: contributor_state::State, S: BosStr> ContributorBuilder<St, S> {
    /// Set the `contributionWeight` field (optional)
    pub fn contribution_weight(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `contributionWeight` field to an Option value (optional)
    pub fn maybe_contribution_weight(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> ContributorBuilder<St, S>
where
    St: contributor_state::State,
    St::ContributorIdentity: contributor_state::IsUnset,
{
    /// Set the `contributorIdentity` field (required)
    pub fn contributor_identity(
        mut self,
        value: impl Into<ContributorContributorIdentity<S>>,
    ) -> ContributorBuilder<contributor_state::SetContributorIdentity<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ContributorBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ContributorBuilder<St, S>
where
    St: contributor_state::State,
    St::ContributorIdentity: contributor_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Contributor<S> {
        Contributor {
            contribution_details: self._fields.0,
            contribution_weight: self._fields.1,
            contributor_identity: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> Contributor<S> {
        Contributor {
            contribution_details: self._fields.0,
            contribution_weight: self._fields.1,
            contributor_identity: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_hypercerts_claim_activity() -> 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.claim.activity"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("contributor"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("contributorIdentity")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("contributionDetails"),
                            LexObjectProperty::Union(LexRefUnion {
                                description: Some(
                                    CowStr::new_static(
                                        "Inline contribution role object with a role string via org.hypercerts.claim.activity#contributorRole, or a strong reference to a contribution details record. The record referenced must conform with the lexicon org.hypercerts.claim.contribution.",
                                    ),
                                ),
                                refs: vec![
                                    CowStr::new_static("#contributorRole"),
                                    CowStr::new_static("com.atproto.repo.strongRef")
                                ],
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("contributionWeight"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The relative weight/importance of this contribution (stored as a string to avoid float precision issues). Must be a positive numeric value. 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.insert(
                            SmolStr::new_static("contributorIdentity"),
                            LexObjectProperty::Union(LexRefUnion {
                                description: Some(
                                    CowStr::new_static(
                                        "Inline contributor identity object with an identity string (DID or identifier) via org.hypercerts.claim.activity#contributorIdentity, or a strong reference to a contributor information record. The record referenced must conform with the lexicon org.hypercerts.claim.contributorInformation.",
                                    ),
                                ),
                                refs: vec![
                                    CowStr::new_static("#contributorIdentity"),
                                    CowStr::new_static("com.atproto.repo.strongRef")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("contributorIdentity"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Contributor information as a string (DID or identifier).",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("identity")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("identity"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The contributor identity string (DID or identifier).",
                                    ),
                                ),
                                max_length: Some(1000usize),
                                max_graphemes: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("contributorRole"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Contribution details as a string."),
                    ),
                    required: Some(vec![SmolStr::new_static("role")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("role"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The contribution role or details."),
                                ),
                                max_length: Some(1000usize),
                                max_graphemes: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("A hypercert record tracking impact work."),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("title"),
                                SmolStr::new_static("shortDescription"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("contributors"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "An array of contributor objects, each containing contributor information, weight, and contribution details.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#contributor"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(1000usize),
                                    ..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("endDate"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the work ended"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("image"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "The hypercert visual representation 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("locations"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "An array of strong references to the location where activity was performed. The record referenced must conform with the lexicon app.certified.location.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("rights"),
                                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 activity claim, suitable for previews and list views. Rich text annotations may be provided via `shortDescriptionFacets`.",
                                        ),
                                    ),
                                    max_length: Some(3000usize),
                                    max_graphemes: Some(300usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("shortDescriptionFacets"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Rich text annotations for `shortDescription` (mentions, URLs, hashtags, etc).",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("app.bsky.richtext.facet"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("startDate"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the work began"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Display title summarizing the impact work (e.g. 'Reforestation in Amazon Basin 2024')",
                                        ),
                                    ),
                                    max_length: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("workScope"),
                                LexObjectProperty::Union(LexRefUnion {
                                    description: Some(
                                        CowStr::new_static(
                                            "Work scope definition. A CEL expression for structured, machine-evaluable scopes or a free-form string for simple and legacy scopes.",
                                        ),
                                    ),
                                    refs: vec![
                                        CowStr::new_static("org.hypercerts.workscope.cel"),
                                        CowStr::new_static("#workScopeString")
                                    ],
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("workScopeString"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A free-form string describing the work scope for simple or legacy scopes.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("scope")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("scope"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The work scope description string."),
                                ),
                                max_length: Some(1000usize),
                                max_graphemes: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod activity_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 ShortDescription;
        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 ShortDescription = 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 ShortDescription = St::ShortDescription;
        type Title = St::Title;
    }
    ///State transition - sets the `short_description` field to Set
    pub struct SetShortDescription<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetShortDescription<St> {}
    impl<St: State> State for SetShortDescription<St> {
        type CreatedAt = St::CreatedAt;
        type ShortDescription = Set<members::short_description>;
        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 ShortDescription = St::ShortDescription;
        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 `short_description` field
        pub struct short_description(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

/// Builder for constructing an instance of this type.
pub struct ActivityBuilder<St: activity_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<activity::Contributor<S>>>,
        Option<Datetime>,
        Option<LinearDocument<S>>,
        Option<Datetime>,
        Option<ActivityImage<S>>,
        Option<Vec<StrongRef<S>>>,
        Option<StrongRef<S>>,
        Option<S>,
        Option<Vec<Facet<S>>>,
        Option<Datetime>,
        Option<S>,
        Option<ActivityWorkScope<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Activity<S> {
    /// Create a new builder for this type
    pub fn builder() -> ActivityBuilder<activity_state::Empty, S> {
        ActivityBuilder::builder()
    }
}

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

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

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `contributors` field (optional)
    pub fn contributors(
        mut self,
        value: impl Into<Option<Vec<activity::Contributor<S>>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `contributors` field to an Option value (optional)
    pub fn maybe_contributors(
        mut self,
        value: Option<Vec<activity::Contributor<S>>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<LinearDocument<S>>>) -> Self {
        self._fields.2 = 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.2 = value;
        self
    }
}

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `endDate` field (optional)
    pub fn end_date(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `endDate` field to an Option value (optional)
    pub fn maybe_end_date(mut self, value: Option<Datetime>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `image` field (optional)
    pub fn image(mut self, value: impl Into<Option<ActivityImage<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `image` field to an Option value (optional)
    pub fn maybe_image(mut self, value: Option<ActivityImage<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `rights` field (optional)
    pub fn rights(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `rights` field to an Option value (optional)
    pub fn maybe_rights(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> ActivityBuilder<St, S>
where
    St: activity_state::State,
    St::ShortDescription: activity_state::IsUnset,
{
    /// Set the `shortDescription` field (required)
    pub fn short_description(
        mut self,
        value: impl Into<S>,
    ) -> ActivityBuilder<activity_state::SetShortDescription<St>, S> {
        self._fields.7 = Option::Some(value.into());
        ActivityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `shortDescriptionFacets` field (optional)
    pub fn short_description_facets(
        mut self,
        value: impl Into<Option<Vec<Facet<S>>>>,
    ) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `shortDescriptionFacets` field to an Option value (optional)
    pub fn maybe_short_description_facets(
        mut self,
        value: Option<Vec<Facet<S>>>,
    ) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `startDate` field (optional)
    pub fn start_date(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `startDate` field to an Option value (optional)
    pub fn maybe_start_date(mut self, value: Option<Datetime>) -> Self {
        self._fields.9 = value;
        self
    }
}

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

impl<St: activity_state::State, S: BosStr> ActivityBuilder<St, S> {
    /// Set the `workScope` field (optional)
    pub fn work_scope(mut self, value: impl Into<Option<ActivityWorkScope<S>>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `workScope` field to an Option value (optional)
    pub fn maybe_work_scope(mut self, value: Option<ActivityWorkScope<S>>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<St, S: BosStr> ActivityBuilder<St, S>
where
    St: activity_state::State,
    St::CreatedAt: activity_state::IsSet,
    St::ShortDescription: activity_state::IsSet,
    St::Title: activity_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Activity<S> {
        Activity {
            contributors: self._fields.0,
            created_at: self._fields.1.unwrap(),
            description: self._fields.2,
            end_date: self._fields.3,
            image: self._fields.4,
            locations: self._fields.5,
            rights: self._fields.6,
            short_description: self._fields.7.unwrap(),
            short_description_facets: self._fields.8,
            start_date: self._fields.9,
            title: self._fields.10.unwrap(),
            work_scope: self._fields.11,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Activity<S> {
        Activity {
            contributors: self._fields.0,
            created_at: self._fields.1.unwrap(),
            description: self._fields.2,
            end_date: self._fields.3,
            image: self._fields.4,
            locations: self._fields.5,
            rights: self._fields.6,
            short_description: self._fields.7.unwrap(),
            short_description_facets: self._fields.8,
            start_date: self._fields.9,
            title: self._fields.10.unwrap(),
            work_scope: self._fields.11,
            extra_data: Some(extra_data),
        }
    }
}