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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::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;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Contributor<'a> {
    ///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")]
    #[serde(borrow)]
    pub contribution_details: Option<ContributorContributionDetails<'a>>,
    ///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")]
    #[serde(borrow)]
    pub contribution_weight: Option<CowStr<'a>>,
    ///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.
    #[serde(borrow)]
    pub contributor_identity: ContributorContributorIdentity<'a>,
}


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


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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ContributorIdentity<'a> {
    ///The contributor identity string (DID or identifier).
    #[serde(borrow)]
    pub identity: CowStr<'a>,
}

/// Contribution details as a string.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ContributorRole<'a> {
    ///The contribution role or details.
    #[serde(borrow)]
    pub role: CowStr<'a>,
}

/// A hypercert record tracking impact work.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Activity<'a> {
    ///An array of contributor objects, each containing contributor information, weight, and contribution details.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub contributors: Option<Vec<activity::Contributor<'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>>,
    ///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")]
    #[serde(borrow)]
    pub image: Option<ActivityImage<'a>>,
    ///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")]
    #[serde(borrow)]
    pub locations: Option<Vec<StrongRef<'a>>>,
    ///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")]
    #[serde(borrow)]
    pub rights: Option<StrongRef<'a>>,
    ///Short summary of this activity claim, suitable for previews and list views. Rich text annotations may be provided via `shortDescriptionFacets`.
    #[serde(borrow)]
    pub short_description: CowStr<'a>,
    ///Rich text annotations for `shortDescription` (mentions, URLs, hashtags, etc).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub short_description_facets: Option<Vec<Facet<'a>>>,
    ///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')
    #[serde(borrow)]
    pub title: CowStr<'a>,
    ///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")]
    #[serde(borrow)]
    pub work_scope: Option<ActivityWorkScope<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ActivityImage<'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 ActivityWorkScope<'a> {
    #[serde(rename = "org.hypercerts.workscope.cel")]
    Cel(Box<Cel<'a>>),
    #[serde(rename = "org.hypercerts.claim.activity#workScopeString")]
    WorkScopeString(Box<activity::WorkScopeString<'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 ActivityGetRecordOutput<'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: Activity<'a>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct WorkScopeString<'a> {
    ///The work scope description string.
    #[serde(borrow)]
    pub scope: CowStr<'a>,
}

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

impl<'a> LexiconSchema for Contributor<'a> {
    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<'a> LexiconSchema for ContributorIdentity<'a> {
    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<'a> LexiconSchema for ContributorRole<'a> {
    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<'de> = ActivityGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Activity<'_> {
    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<'a> LexiconSchema for Activity<'a> {
    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<'a> LexiconSchema for WorkScopeString<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetContributorIdentity<S> {}
    impl<S: State> State for SetContributorIdentity<S> {
        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<'a, S: contributor_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<ContributorContributionDetails<'a>>,
        Option<CowStr<'a>>,
        Option<ContributorContributorIdentity<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> ContributorBuilder<'a, S>
where
    S: contributor_state::State,
    S::ContributorIdentity: contributor_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Contributor<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Contributor<'a> {
        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 Title;
        type CreatedAt;
        type ShortDescription;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Title = Unset;
        type CreatedAt = Unset;
        type ShortDescription = Unset;
    }
    ///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 Title = Set<members::title>;
        type CreatedAt = S::CreatedAt;
        type ShortDescription = S::ShortDescription;
    }
    ///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 Title = S::Title;
        type CreatedAt = Set<members::created_at>;
        type ShortDescription = S::ShortDescription;
    }
    ///State transition - sets the `short_description` field to Set
    pub struct SetShortDescription<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetShortDescription<S> {}
    impl<S: State> State for SetShortDescription<S> {
        type Title = S::Title;
        type CreatedAt = S::CreatedAt;
        type ShortDescription = Set<members::short_description>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `title` field
        pub struct title(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `short_description` field
        pub struct short_description(());
    }
}

/// Builder for constructing an instance of this type
pub struct ActivityBuilder<'a, S: activity_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<activity::Contributor<'a>>>,
        Option<Datetime>,
        Option<LinearDocument<'a>>,
        Option<Datetime>,
        Option<ActivityImage<'a>>,
        Option<Vec<StrongRef<'a>>>,
        Option<StrongRef<'a>>,
        Option<CowStr<'a>>,
        Option<Vec<Facet<'a>>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<ActivityWorkScope<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: activity_state::State> ActivityBuilder<'a, S> {
    /// Set the `contributors` field (optional)
    pub fn contributors(
        mut self,
        value: impl Into<Option<Vec<activity::Contributor<'a>>>>,
    ) -> 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<'a>>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

impl<'a, S: activity_state::State> ActivityBuilder<'a, 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<'a, S: activity_state::State> ActivityBuilder<'a, S> {
    /// Set the `image` field (optional)
    pub fn image(mut self, value: impl Into<Option<ActivityImage<'a>>>) -> 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<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

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

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

impl<'a, S: activity_state::State> ActivityBuilder<'a, S> {
    /// Set the `shortDescriptionFacets` field (optional)
    pub fn short_description_facets(
        mut self,
        value: impl Into<Option<Vec<Facet<'a>>>>,
    ) -> 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<'a>>>,
    ) -> Self {
        self._fields.8 = value;
        self
    }
}

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

impl<'a, S: activity_state::State> ActivityBuilder<'a, S> {
    /// Set the `workScope` field (optional)
    pub fn work_scope(
        mut self,
        value: impl Into<Option<ActivityWorkScope<'a>>>,
    ) -> 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<'a>>) -> Self {
        self._fields.11 = value;
        self
    }
}

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