// @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, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
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;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CommitCountBreakdown<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub by_email: Option<Vec<ref_update::IndividualEmailCommitCount<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct IndividualEmailCommitCount<S: BosStr = DefaultStr> {
    pub count: i64,
    pub email: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct IndividualLanguageSize<S: BosStr = DefaultStr> {
    pub lang: S,
    pub size: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct LangBreakdown<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inputs: Option<Vec<ref_update::IndividualLanguageSize<S>>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "sh.tangled.git.refUpdate",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct RefUpdate<S: BosStr = DefaultStr> {
    ///did of the user that pushed this ref
    pub committer_did: Did<S>,
    pub meta: ref_update::Meta<S>,
    ///new SHA of this ref
    pub new_sha: S,
    ///old SHA of this ref
    pub old_sha: S,
    ///did of the owner of the repo
    #[serde(skip_serializing_if = "Option::is_none")]
    pub owner_did: Option<Did<S>>,
    ///Ref being updated
    pub r#ref: S,
    ///DID of the repo itself
    pub repo: Did<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RefUpdateGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: RefUpdate<S>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Meta<S: BosStr = DefaultStr> {
    pub commit_count: ref_update::CommitCountBreakdown<S>,
    /// Defaults to `false`.
    #[serde(default = "_default_meta_is_default_ref")]
    pub is_default_ref: bool,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub lang_breakdown: Option<ref_update::LangBreakdown<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

impl<S: BosStr> LexiconSchema for CommitCountBreakdown<S> {
    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<S: BosStr> LexiconSchema for IndividualEmailCommitCount<S> {
    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<S: BosStr> LexiconSchema for IndividualLanguageSize<S> {
    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<S: BosStr> LexiconSchema for LangBreakdown<S> {
    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<S: BosStr> = RefUpdateGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for RefUpdate<S> {
    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<S: BosStr> LexiconSchema for RefUpdate<S> {
    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<S: BosStr> LexiconSchema for Meta<S> {
    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("repo"), 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("ownerDid"),
                                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("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("repo"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("DID of the repo itself"),
                                    ),
                                    format: Some(LexStringFormat::Did),
                                    ..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 Count;
        type Email;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Count = Unset;
        type Email = Unset;
    }
    ///State transition - sets the `count` field to Set
    pub struct SetCount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCount<St> {}
    impl<St: State> State for SetCount<St> {
        type Count = Set<members::count>;
        type Email = St::Email;
    }
    ///State transition - sets the `email` field to Set
    pub struct SetEmail<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEmail<St> {}
    impl<St: State> State for SetEmail<St> {
        type Count = St::Count;
        type Email = Set<members::email>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `count` field
        pub struct count(());
        ///Marker type for the `email` field
        pub struct email(());
    }
}

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

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

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

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

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

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

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

impl<St, S: BosStr> IndividualEmailCommitCountBuilder<St, S>
where
    St: individual_email_commit_count_state::State,
    St::Count: individual_email_commit_count_state::IsSet,
    St::Email: individual_email_commit_count_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> IndividualEmailCommitCount<S> {
        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<SmolStr, Data<S>>,
    ) -> IndividualEmailCommitCount<S> {
        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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLang<St> {}
    impl<St: State> State for SetLang<St> {
        type Lang = Set<members::lang>;
        type Size = St::Size;
    }
    ///State transition - sets the `size` field to Set
    pub struct SetSize<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSize<St> {}
    impl<St: State> State for SetSize<St> {
        type Lang = St::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<
    St: individual_language_size_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<S>, Option<i64>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

impl<St, S: BosStr> IndividualLanguageSizeBuilder<St, S>
where
    St: individual_language_size_state::State,
    St::Lang: individual_language_size_state::IsSet,
    St::Size: individual_language_size_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> IndividualLanguageSize<S> {
        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<SmolStr, Data<S>>,
    ) -> IndividualLanguageSize<S> {
        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 CommitterDid;
        type Meta;
        type NewSha;
        type OldSha;
        type Ref;
        type Repo;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CommitterDid = Unset;
        type Meta = Unset;
        type NewSha = Unset;
        type OldSha = Unset;
        type Ref = Unset;
        type Repo = Unset;
    }
    ///State transition - sets the `committer_did` field to Set
    pub struct SetCommitterDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCommitterDid<St> {}
    impl<St: State> State for SetCommitterDid<St> {
        type CommitterDid = Set<members::committer_did>;
        type Meta = St::Meta;
        type NewSha = St::NewSha;
        type OldSha = St::OldSha;
        type Ref = St::Ref;
        type Repo = St::Repo;
    }
    ///State transition - sets the `meta` field to Set
    pub struct SetMeta<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMeta<St> {}
    impl<St: State> State for SetMeta<St> {
        type CommitterDid = St::CommitterDid;
        type Meta = Set<members::meta>;
        type NewSha = St::NewSha;
        type OldSha = St::OldSha;
        type Ref = St::Ref;
        type Repo = St::Repo;
    }
    ///State transition - sets the `new_sha` field to Set
    pub struct SetNewSha<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetNewSha<St> {}
    impl<St: State> State for SetNewSha<St> {
        type CommitterDid = St::CommitterDid;
        type Meta = St::Meta;
        type NewSha = Set<members::new_sha>;
        type OldSha = St::OldSha;
        type Ref = St::Ref;
        type Repo = St::Repo;
    }
    ///State transition - sets the `old_sha` field to Set
    pub struct SetOldSha<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetOldSha<St> {}
    impl<St: State> State for SetOldSha<St> {
        type CommitterDid = St::CommitterDid;
        type Meta = St::Meta;
        type NewSha = St::NewSha;
        type OldSha = Set<members::old_sha>;
        type Ref = St::Ref;
        type Repo = St::Repo;
    }
    ///State transition - sets the `ref` field to Set
    pub struct SetRef<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRef<St> {}
    impl<St: State> State for SetRef<St> {
        type CommitterDid = St::CommitterDid;
        type Meta = St::Meta;
        type NewSha = St::NewSha;
        type OldSha = St::OldSha;
        type Ref = Set<members::r#ref>;
        type Repo = St::Repo;
    }
    ///State transition - sets the `repo` field to Set
    pub struct SetRepo<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRepo<St> {}
    impl<St: State> State for SetRepo<St> {
        type CommitterDid = St::CommitterDid;
        type Meta = St::Meta;
        type NewSha = St::NewSha;
        type OldSha = St::OldSha;
        type Ref = St::Ref;
        type Repo = Set<members::repo>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `committer_did` field
        pub struct committer_did(());
        ///Marker type for the `meta` field
        pub struct meta(());
        ///Marker type for the `new_sha` field
        pub struct new_sha(());
        ///Marker type for the `old_sha` field
        pub struct old_sha(());
        ///Marker type for the `ref` field
        pub struct r#ref(());
        ///Marker type for the `repo` field
        pub struct repo(());
    }
}

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

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

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

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

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

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

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

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

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

impl<St: ref_update_state::State, S: BosStr> RefUpdateBuilder<St, S> {
    /// Set the `ownerDid` field (optional)
    pub fn owner_did(mut self, value: impl Into<Option<Did<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `ownerDid` field to an Option value (optional)
    pub fn maybe_owner_did(mut self, value: Option<Did<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<St, S: BosStr> RefUpdateBuilder<St, S>
where
    St: ref_update_state::State,
    St::Repo: ref_update_state::IsUnset,
{
    /// Set the `repo` field (required)
    pub fn repo(
        mut self,
        value: impl Into<Did<S>>,
    ) -> RefUpdateBuilder<ref_update_state::SetRepo<St>, S> {
        self._fields.6 = Option::Some(value.into());
        RefUpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RefUpdateBuilder<St, S>
where
    St: ref_update_state::State,
    St::CommitterDid: ref_update_state::IsSet,
    St::Meta: ref_update_state::IsSet,
    St::NewSha: ref_update_state::IsSet,
    St::OldSha: ref_update_state::IsSet,
    St::Ref: ref_update_state::IsSet,
    St::Repo: ref_update_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> RefUpdate<S> {
        RefUpdate {
            committer_did: self._fields.0.unwrap(),
            meta: self._fields.1.unwrap(),
            new_sha: self._fields.2.unwrap(),
            old_sha: self._fields.3.unwrap(),
            owner_did: self._fields.4,
            r#ref: self._fields.5.unwrap(),
            repo: 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<SmolStr, Data<S>>,
    ) -> RefUpdate<S> {
        RefUpdate {
            committer_did: self._fields.0.unwrap(),
            meta: self._fields.1.unwrap(),
            new_sha: self._fields.2.unwrap(),
            old_sha: self._fields.3.unwrap(),
            owner_did: self._fields.4,
            r#ref: self._fields.5.unwrap(),
            repo: 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 CommitCount;
        type IsDefaultRef;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CommitCount = Unset;
        type IsDefaultRef = Unset;
    }
    ///State transition - sets the `commit_count` field to Set
    pub struct SetCommitCount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCommitCount<St> {}
    impl<St: State> State for SetCommitCount<St> {
        type CommitCount = Set<members::commit_count>;
        type IsDefaultRef = St::IsDefaultRef;
    }
    ///State transition - sets the `is_default_ref` field to Set
    pub struct SetIsDefaultRef<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetIsDefaultRef<St> {}
    impl<St: State> State for SetIsDefaultRef<St> {
        type CommitCount = St::CommitCount;
        type IsDefaultRef = Set<members::is_default_ref>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `commit_count` field
        pub struct commit_count(());
        ///Marker type for the `is_default_ref` field
        pub struct is_default_ref(());
    }
}

/// Builder for constructing an instance of this type.
pub struct MetaBuilder<St: meta_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<ref_update::CommitCountBreakdown<S>>,
        Option<bool>,
        Option<ref_update::LangBreakdown<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

impl<St: meta_state::State, S: BosStr> MetaBuilder<St, S> {
    /// Set the `langBreakdown` field (optional)
    pub fn lang_breakdown(
        mut self,
        value: impl Into<Option<ref_update::LangBreakdown<S>>>,
    ) -> 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<S>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

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