// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.git.refUpdate
//
// 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::{Did, AtUri, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
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::sh_tangled::git::ref_update;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct CommitCountBreakdown<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub by_email: Option<Vec<ref_update::IndividualEmailCommitCount<'a>>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct IndividualEmailCommitCount<'a> {
    pub count: i64,
    #[serde(borrow)]
    pub email: CowStr<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct IndividualLanguageSize<'a> {
    #[serde(borrow)]
    pub lang: CowStr<'a>,
    pub size: i64,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct LangBreakdown<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub inputs: Option<Vec<ref_update::IndividualLanguageSize<'a>>>,
}

/// An update to a git repository, emitted by knots.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RefUpdate<'a> {
    ///did of the user that pushed this ref
    #[serde(borrow)]
    pub committer_did: Did<'a>,
    #[serde(borrow)]
    pub meta: ref_update::Meta<'a>,
    ///new SHA of this ref
    #[serde(borrow)]
    pub new_sha: CowStr<'a>,
    ///old SHA of this ref
    #[serde(borrow)]
    pub old_sha: CowStr<'a>,
    ///Ref being updated
    #[serde(borrow)]
    pub r#ref: CowStr<'a>,
    ///did of the owner of the repo
    #[serde(borrow)]
    pub repo_did: Did<'a>,
    ///name of the repo
    #[serde(borrow)]
    pub repo_name: CowStr<'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 RefUpdateGetRecordOutput<'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: RefUpdate<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Meta<'a> {
    #[serde(borrow)]
    pub commit_count: ref_update::CommitCountBreakdown<'a>,
    /// Defaults to `false`.
    #[serde(default = "_default_meta_is_default_ref")]
    pub is_default_ref: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub lang_breakdown: Option<ref_update::LangBreakdown<'a>>,
}

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

impl<'a> LexiconSchema for CommitCountBreakdown<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.git.refUpdate"
    }
    fn def_name() -> &'static str {
        "commitCountBreakdown"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_refUpdate()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for IndividualEmailCommitCount<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.git.refUpdate"
    }
    fn def_name() -> &'static str {
        "individualEmailCommitCount"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_refUpdate()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for IndividualLanguageSize<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.git.refUpdate"
    }
    fn def_name() -> &'static str {
        "individualLanguageSize"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_refUpdate()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for LangBreakdown<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.git.refUpdate"
    }
    fn def_name() -> &'static str {
        "langBreakdown"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_refUpdate()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct RefUpdateRecord;
impl XrpcResp for RefUpdateRecord {
    const NSID: &'static str = "sh.tangled.git.refUpdate";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = RefUpdateGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for RefUpdate<'_> {
    const NSID: &'static str = "sh.tangled.git.refUpdate";
    type Record = RefUpdateRecord;
}

impl Collection for RefUpdateRecord {
    const NSID: &'static str = "sh.tangled.git.refUpdate";
    type Record = RefUpdateRecord;
}

impl<'a> LexiconSchema for RefUpdate<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.git.refUpdate"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_refUpdate()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.new_sha;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 40usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("new_sha"),
                    max: 40usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.new_sha;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 40usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("new_sha"),
                    min: 40usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.old_sha;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 40usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("old_sha"),
                    max: 40usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.old_sha;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 40usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("old_sha"),
                    min: 40usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.r#ref;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2560usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("ref"),
                    max: 2560usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.r#ref;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("ref"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Meta<'a> {
    fn nsid() -> &'static str {
        "sh.tangled.git.refUpdate"
    }
    fn def_name() -> &'static str {
        "meta"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_git_refUpdate()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_sh_tangled_git_refUpdate() -> 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("sh.tangled.git.refUpdate"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("commitCountBreakdown"),
                LexUserType::Object(LexObject {
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("byEmail"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#individualEmailCommitCount"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("individualEmailCommitCount"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("email"), SmolStr::new_static("count")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("count"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("email"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("individualLanguageSize"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("lang"), SmolStr::new_static("size")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("lang"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("size"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("langBreakdown"),
                LexUserType::Object(LexObject {
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("inputs"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#individualLanguageSize"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "An update to a git repository, emitted by knots.",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("ref"),
                                SmolStr::new_static("committerDid"),
                                SmolStr::new_static("repoDid"),
                                SmolStr::new_static("repoName"),
                                SmolStr::new_static("oldSha"),
                                SmolStr::new_static("newSha"), SmolStr::new_static("meta")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("committerDid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("did of the user that pushed this ref"),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("meta"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#meta"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("newSha"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("new SHA of this ref"),
                                    ),
                                    min_length: Some(40usize),
                                    max_length: Some(40usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("oldSha"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("old SHA of this ref"),
                                    ),
                                    min_length: Some(40usize),
                                    max_length: Some(40usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("ref"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("Ref being updated")),
                                    max_length: Some(2560usize),
                                    max_graphemes: Some(256usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("repoDid"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("did of the owner of the repo"),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("repoName"),
                                LexObjectProperty::String(LexString {
                                    description: Some(CowStr::new_static("name of the repo")),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("meta"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("isDefaultRef"),
                            SmolStr::new_static("commitCount")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("commitCount"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#commitCountBreakdown"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("isDefaultRef"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("langBreakdown"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#langBreakdown"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod individual_email_commit_count_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 Email;
        type Count;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Email = Unset;
        type Count = Unset;
    }
    ///State transition - sets the `email` field to Set
    pub struct SetEmail<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEmail<S> {}
    impl<S: State> State for SetEmail<S> {
        type Email = Set<members::email>;
        type Count = S::Count;
    }
    ///State transition - sets the `count` field to Set
    pub struct SetCount<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCount<S> {}
    impl<S: State> State for SetCount<S> {
        type Email = S::Email;
        type Count = Set<members::count>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `email` field
        pub struct email(());
        ///Marker type for the `count` field
        pub struct count(());
    }
}

/// Builder for constructing an instance of this type
pub struct IndividualEmailCommitCountBuilder<
    'a,
    S: individual_email_commit_count_state::State,
> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>, Option<CowStr<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> IndividualEmailCommitCount<'a> {
    /// Create a new builder for this type
    pub fn new() -> IndividualEmailCommitCountBuilder<
        'a,
        individual_email_commit_count_state::Empty,
    > {
        IndividualEmailCommitCountBuilder::new()
    }
}

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

impl<'a, S> IndividualEmailCommitCountBuilder<'a, S>
where
    S: individual_email_commit_count_state::State,
    S::Count: individual_email_commit_count_state::IsUnset,
{
    /// Set the `count` field (required)
    pub fn count(
        mut self,
        value: impl Into<i64>,
    ) -> IndividualEmailCommitCountBuilder<
        'a,
        individual_email_commit_count_state::SetCount<S>,
    > {
        self._fields.0 = Option::Some(value.into());
        IndividualEmailCommitCountBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> IndividualEmailCommitCountBuilder<'a, S>
where
    S: individual_email_commit_count_state::State,
    S::Email: individual_email_commit_count_state::IsUnset,
{
    /// Set the `email` field (required)
    pub fn email(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> IndividualEmailCommitCountBuilder<
        'a,
        individual_email_commit_count_state::SetEmail<S>,
    > {
        self._fields.1 = Option::Some(value.into());
        IndividualEmailCommitCountBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> IndividualEmailCommitCountBuilder<'a, S>
where
    S: individual_email_commit_count_state::State,
    S::Email: individual_email_commit_count_state::IsSet,
    S::Count: individual_email_commit_count_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> IndividualEmailCommitCount<'a> {
        IndividualEmailCommitCount {
            count: self._fields.0.unwrap(),
            email: self._fields.1.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>,
        >,
    ) -> IndividualEmailCommitCount<'a> {
        IndividualEmailCommitCount {
            count: self._fields.0.unwrap(),
            email: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod individual_language_size_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 Lang;
        type Size;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Lang = Unset;
        type Size = Unset;
    }
    ///State transition - sets the `lang` field to Set
    pub struct SetLang<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetLang<S> {}
    impl<S: State> State for SetLang<S> {
        type Lang = Set<members::lang>;
        type Size = S::Size;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSize<S> {}
    impl<S: State> State for SetSize<S> {
        type Lang = S::Lang;
        type Size = Set<members::size>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `lang` field
        pub struct lang(());
        ///Marker type for the `size` field
        pub struct size(());
    }
}

/// Builder for constructing an instance of this type
pub struct IndividualLanguageSizeBuilder<'a, S: individual_language_size_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<i64>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> IndividualLanguageSize<'a> {
    /// Create a new builder for this type
    pub fn new() -> IndividualLanguageSizeBuilder<
        'a,
        individual_language_size_state::Empty,
    > {
        IndividualLanguageSizeBuilder::new()
    }
}

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

impl<'a, S> IndividualLanguageSizeBuilder<'a, S>
where
    S: individual_language_size_state::State,
    S::Lang: individual_language_size_state::IsUnset,
{
    /// Set the `lang` field (required)
    pub fn lang(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> IndividualLanguageSizeBuilder<'a, individual_language_size_state::SetLang<S>> {
        self._fields.0 = Option::Some(value.into());
        IndividualLanguageSizeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> IndividualLanguageSizeBuilder<'a, S>
where
    S: individual_language_size_state::State,
    S::Size: individual_language_size_state::IsUnset,
{
    /// Set the `size` field (required)
    pub fn size(
        mut self,
        value: impl Into<i64>,
    ) -> IndividualLanguageSizeBuilder<'a, individual_language_size_state::SetSize<S>> {
        self._fields.1 = Option::Some(value.into());
        IndividualLanguageSizeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> IndividualLanguageSizeBuilder<'a, S>
where
    S: individual_language_size_state::State,
    S::Lang: individual_language_size_state::IsSet,
    S::Size: individual_language_size_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> IndividualLanguageSize<'a> {
        IndividualLanguageSize {
            lang: self._fields.0.unwrap(),
            size: self._fields.1.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>,
        >,
    ) -> IndividualLanguageSize<'a> {
        IndividualLanguageSize {
            lang: self._fields.0.unwrap(),
            size: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod ref_update_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 NewSha;
        type CommitterDid;
        type RepoDid;
        type RepoName;
        type Meta;
        type Ref;
        type OldSha;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type NewSha = Unset;
        type CommitterDid = Unset;
        type RepoDid = Unset;
        type RepoName = Unset;
        type Meta = Unset;
        type Ref = Unset;
        type OldSha = Unset;
    }
    ///State transition - sets the `new_sha` field to Set
    pub struct SetNewSha<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetNewSha<S> {}
    impl<S: State> State for SetNewSha<S> {
        type NewSha = Set<members::new_sha>;
        type CommitterDid = S::CommitterDid;
        type RepoDid = S::RepoDid;
        type RepoName = S::RepoName;
        type Meta = S::Meta;
        type Ref = S::Ref;
        type OldSha = S::OldSha;
    }
    ///State transition - sets the `committer_did` field to Set
    pub struct SetCommitterDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCommitterDid<S> {}
    impl<S: State> State for SetCommitterDid<S> {
        type NewSha = S::NewSha;
        type CommitterDid = Set<members::committer_did>;
        type RepoDid = S::RepoDid;
        type RepoName = S::RepoName;
        type Meta = S::Meta;
        type Ref = S::Ref;
        type OldSha = S::OldSha;
    }
    ///State transition - sets the `repo_did` field to Set
    pub struct SetRepoDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRepoDid<S> {}
    impl<S: State> State for SetRepoDid<S> {
        type NewSha = S::NewSha;
        type CommitterDid = S::CommitterDid;
        type RepoDid = Set<members::repo_did>;
        type RepoName = S::RepoName;
        type Meta = S::Meta;
        type Ref = S::Ref;
        type OldSha = S::OldSha;
    }
    ///State transition - sets the `repo_name` field to Set
    pub struct SetRepoName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRepoName<S> {}
    impl<S: State> State for SetRepoName<S> {
        type NewSha = S::NewSha;
        type CommitterDid = S::CommitterDid;
        type RepoDid = S::RepoDid;
        type RepoName = Set<members::repo_name>;
        type Meta = S::Meta;
        type Ref = S::Ref;
        type OldSha = S::OldSha;
    }
    ///State transition - sets the `meta` field to Set
    pub struct SetMeta<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMeta<S> {}
    impl<S: State> State for SetMeta<S> {
        type NewSha = S::NewSha;
        type CommitterDid = S::CommitterDid;
        type RepoDid = S::RepoDid;
        type RepoName = S::RepoName;
        type Meta = Set<members::meta>;
        type Ref = S::Ref;
        type OldSha = S::OldSha;
    }
    ///State transition - sets the `ref` field to Set
    pub struct SetRef<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRef<S> {}
    impl<S: State> State for SetRef<S> {
        type NewSha = S::NewSha;
        type CommitterDid = S::CommitterDid;
        type RepoDid = S::RepoDid;
        type RepoName = S::RepoName;
        type Meta = S::Meta;
        type Ref = Set<members::r#ref>;
        type OldSha = S::OldSha;
    }
    ///State transition - sets the `old_sha` field to Set
    pub struct SetOldSha<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetOldSha<S> {}
    impl<S: State> State for SetOldSha<S> {
        type NewSha = S::NewSha;
        type CommitterDid = S::CommitterDid;
        type RepoDid = S::RepoDid;
        type RepoName = S::RepoName;
        type Meta = S::Meta;
        type Ref = S::Ref;
        type OldSha = Set<members::old_sha>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `new_sha` field
        pub struct new_sha(());
        ///Marker type for the `committer_did` field
        pub struct committer_did(());
        ///Marker type for the `repo_did` field
        pub struct repo_did(());
        ///Marker type for the `repo_name` field
        pub struct repo_name(());
        ///Marker type for the `meta` field
        pub struct meta(());
        ///Marker type for the `ref` field
        pub struct r#ref(());
        ///Marker type for the `old_sha` field
        pub struct old_sha(());
    }
}

/// Builder for constructing an instance of this type
pub struct RefUpdateBuilder<'a, S: ref_update_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Did<'a>>,
        Option<ref_update::Meta<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<CowStr<'a>>,
        Option<Did<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> RefUpdate<'a> {
    /// Create a new builder for this type
    pub fn new() -> RefUpdateBuilder<'a, ref_update_state::Empty> {
        RefUpdateBuilder::new()
    }
}

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

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::CommitterDid: ref_update_state::IsUnset,
{
    /// Set the `committerDid` field (required)
    pub fn committer_did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> RefUpdateBuilder<'a, ref_update_state::SetCommitterDid<S>> {
        self._fields.0 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::Meta: ref_update_state::IsUnset,
{
    /// Set the `meta` field (required)
    pub fn meta(
        mut self,
        value: impl Into<ref_update::Meta<'a>>,
    ) -> RefUpdateBuilder<'a, ref_update_state::SetMeta<S>> {
        self._fields.1 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::NewSha: ref_update_state::IsUnset,
{
    /// Set the `newSha` field (required)
    pub fn new_sha(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> RefUpdateBuilder<'a, ref_update_state::SetNewSha<S>> {
        self._fields.2 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::OldSha: ref_update_state::IsUnset,
{
    /// Set the `oldSha` field (required)
    pub fn old_sha(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> RefUpdateBuilder<'a, ref_update_state::SetOldSha<S>> {
        self._fields.3 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::Ref: ref_update_state::IsUnset,
{
    /// Set the `ref` field (required)
    pub fn r#ref(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> RefUpdateBuilder<'a, ref_update_state::SetRef<S>> {
        self._fields.4 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::RepoDid: ref_update_state::IsUnset,
{
    /// Set the `repoDid` field (required)
    pub fn repo_did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> RefUpdateBuilder<'a, ref_update_state::SetRepoDid<S>> {
        self._fields.5 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::RepoName: ref_update_state::IsUnset,
{
    /// Set the `repoName` field (required)
    pub fn repo_name(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> RefUpdateBuilder<'a, ref_update_state::SetRepoName<S>> {
        self._fields.6 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> RefUpdateBuilder<'a, S>
where
    S: ref_update_state::State,
    S::NewSha: ref_update_state::IsSet,
    S::CommitterDid: ref_update_state::IsSet,
    S::RepoDid: ref_update_state::IsSet,
    S::RepoName: ref_update_state::IsSet,
    S::Meta: ref_update_state::IsSet,
    S::Ref: ref_update_state::IsSet,
    S::OldSha: ref_update_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RefUpdate<'a> {
        RefUpdate {
            committer_did: self._fields.0.unwrap(),
            meta: self._fields.1.unwrap(),
            new_sha: self._fields.2.unwrap(),
            old_sha: self._fields.3.unwrap(),
            r#ref: self._fields.4.unwrap(),
            repo_did: self._fields.5.unwrap(),
            repo_name: self._fields.6.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>,
        >,
    ) -> RefUpdate<'a> {
        RefUpdate {
            committer_did: self._fields.0.unwrap(),
            meta: self._fields.1.unwrap(),
            new_sha: self._fields.2.unwrap(),
            old_sha: self._fields.3.unwrap(),
            r#ref: self._fields.4.unwrap(),
            repo_did: self._fields.5.unwrap(),
            repo_name: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn _default_meta_is_default_ref() -> bool {
    false
}

pub mod meta_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 IsDefaultRef;
        type CommitCount;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type IsDefaultRef = Unset;
        type CommitCount = Unset;
    }
    ///State transition - sets the `is_default_ref` field to Set
    pub struct SetIsDefaultRef<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIsDefaultRef<S> {}
    impl<S: State> State for SetIsDefaultRef<S> {
        type IsDefaultRef = Set<members::is_default_ref>;
        type CommitCount = S::CommitCount;
    }
    ///State transition - sets the `commit_count` field to Set
    pub struct SetCommitCount<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCommitCount<S> {}
    impl<S: State> State for SetCommitCount<S> {
        type IsDefaultRef = S::IsDefaultRef;
        type CommitCount = Set<members::commit_count>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `is_default_ref` field
        pub struct is_default_ref(());
        ///Marker type for the `commit_count` field
        pub struct commit_count(());
    }
}

/// Builder for constructing an instance of this type
pub struct MetaBuilder<'a, S: meta_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<ref_update::CommitCountBreakdown<'a>>,
        Option<bool>,
        Option<ref_update::LangBreakdown<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Meta<'a> {
    /// Create a new builder for this type
    pub fn new() -> MetaBuilder<'a, meta_state::Empty> {
        MetaBuilder::new()
    }
}

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

impl<'a, S> MetaBuilder<'a, S>
where
    S: meta_state::State,
    S::CommitCount: meta_state::IsUnset,
{
    /// Set the `commitCount` field (required)
    pub fn commit_count(
        mut self,
        value: impl Into<ref_update::CommitCountBreakdown<'a>>,
    ) -> MetaBuilder<'a, meta_state::SetCommitCount<S>> {
        self._fields.0 = Option::Some(value.into());
        MetaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MetaBuilder<'a, S>
where
    S: meta_state::State,
    S::IsDefaultRef: meta_state::IsUnset,
{
    /// Set the `isDefaultRef` field (required)
    pub fn is_default_ref(
        mut self,
        value: impl Into<bool>,
    ) -> MetaBuilder<'a, meta_state::SetIsDefaultRef<S>> {
        self._fields.1 = Option::Some(value.into());
        MetaBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: meta_state::State> MetaBuilder<'a, S> {
    /// Set the `langBreakdown` field (optional)
    pub fn lang_breakdown(
        mut self,
        value: impl Into<Option<ref_update::LangBreakdown<'a>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `langBreakdown` field to an Option value (optional)
    pub fn maybe_lang_breakdown(
        mut self,
        value: Option<ref_update::LangBreakdown<'a>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> MetaBuilder<'a, S>
where
    S: meta_state::State,
    S::IsDefaultRef: meta_state::IsSet,
    S::CommitCount: meta_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Meta<'a> {
        Meta {
            commit_count: self._fields.0.unwrap(),
            is_default_ref: self._fields.1.unwrap(),
            lang_breakdown: self._fields.2,
            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>,
        >,
    ) -> Meta<'a> {
        Meta {
            commit_count: self._fields.0.unwrap(),
            is_default_ref: self._fields.1.unwrap(),
            lang_breakdown: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}