// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.repo.pull
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

//! Generated bindings for the `sh.tangled.repo.pull` Lexicon namespace/module.
pub mod comment;
pub mod list_statuses;
pub mod list_statuses_by;
pub mod status;


#[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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{Did, AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
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::repo::pull;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "sh.tangled.repo.pull",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Pull<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub body: Option<S>,
    pub created_at: Datetime,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub dependent_on: Option<AtUri<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mentions: Option<Vec<Did<S>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub references: Option<Vec<AtUri<S>>>,
    pub rounds: Vec<pull::Round<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub source: Option<pull::Source<S>>,
    pub target: pull::Target<S>,
    pub title: 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 PullGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Pull<S>,
}

/// revisions of this pull request, newer rounds are appended to this array. appviews may reject records do not treat this field as append-only. the blob format is gzipped text-based git-format-patches.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Round<S: BosStr = DefaultStr> {
    pub created_at: Datetime,
    pub patch_blob: BlobRef<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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Source<S: BosStr = DefaultStr> {
    pub branch: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub repo: Option<Did<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 Target<S: BosStr = DefaultStr> {
    pub branch: S,
    pub repo: Did<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

#[derive(Debug, Serialize, Deserialize)]
pub struct PullRecord;
impl XrpcResp for PullRecord {
    const NSID: &'static str = "sh.tangled.repo.pull";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = PullGetRecordOutput<S>;
    type Err = RecordError;
}

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

impl<S: BosStr> Collection for Pull<S> {
    const NSID: &'static str = "sh.tangled.repo.pull";
    type Record = PullRecord;
}

impl Collection for PullRecord {
    const NSID: &'static str = "sh.tangled.repo.pull";
    type Record = PullRecord;
}

impl<S: BosStr> LexiconSchema for Pull<S> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.pull"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_pull()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Round<S> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.pull"
    }
    fn def_name() -> &'static str {
        "round"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_pull()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.patch_blob;
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["application/gzip"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("patch_blob"),
                        accepted: vec!["application/gzip".to_string()],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Source<S> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.pull"
    }
    fn def_name() -> &'static str {
        "source"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_pull()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Target<S> {
    fn nsid() -> &'static str {
        "sh.tangled.repo.pull"
    }
    fn def_name() -> &'static str {
        "target"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_repo_pull()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod pull_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type CreatedAt;
        type Rounds;
        type Target;
        type Title;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Rounds = Unset;
        type Target = Unset;
        type Title = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Rounds = St::Rounds;
        type Target = St::Target;
        type Title = St::Title;
    }
    ///State transition - sets the `rounds` field to Set
    pub struct SetRounds<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRounds<St> {}
    impl<St: State> State for SetRounds<St> {
        type CreatedAt = St::CreatedAt;
        type Rounds = Set<members::rounds>;
        type Target = St::Target;
        type Title = St::Title;
    }
    ///State transition - sets the `target` field to Set
    pub struct SetTarget<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTarget<St> {}
    impl<St: State> State for SetTarget<St> {
        type CreatedAt = St::CreatedAt;
        type Rounds = St::Rounds;
        type Target = Set<members::target>;
        type Title = St::Title;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type CreatedAt = St::CreatedAt;
        type Rounds = St::Rounds;
        type Target = St::Target;
        type Title = Set<members::title>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `rounds` field
        pub struct rounds(());
        ///Marker type for the `target` field
        pub struct target(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

/// Builder for constructing an instance of this type.
pub struct PullBuilder<St: pull_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<Datetime>,
        Option<AtUri<S>>,
        Option<Vec<Did<S>>>,
        Option<Vec<AtUri<S>>>,
        Option<Vec<pull::Round<S>>>,
        Option<pull::Source<S>>,
        Option<pull::Target<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Pull<S> {
    /// Create a new builder for this type
    pub fn builder() -> PullBuilder<pull_state::Empty, S> {
        PullBuilder::builder()
    }
}

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

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

impl<St: pull_state::State, S: BosStr> PullBuilder<St, S> {
    /// Set the `body` field (optional)
    pub fn body(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `body` field to an Option value (optional)
    pub fn maybe_body(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St: pull_state::State, S: BosStr> PullBuilder<St, S> {
    /// Set the `dependentOn` field (optional)
    pub fn dependent_on(mut self, value: impl Into<Option<AtUri<S>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `dependentOn` field to an Option value (optional)
    pub fn maybe_dependent_on(mut self, value: Option<AtUri<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: pull_state::State, S: BosStr> PullBuilder<St, S> {
    /// Set the `mentions` field (optional)
    pub fn mentions(mut self, value: impl Into<Option<Vec<Did<S>>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `mentions` field to an Option value (optional)
    pub fn maybe_mentions(mut self, value: Option<Vec<Did<S>>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: pull_state::State, S: BosStr> PullBuilder<St, S> {
    /// Set the `references` field (optional)
    pub fn references(mut self, value: impl Into<Option<Vec<AtUri<S>>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `references` field to an Option value (optional)
    pub fn maybe_references(mut self, value: Option<Vec<AtUri<S>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> PullBuilder<St, S>
where
    St: pull_state::State,
    St::Rounds: pull_state::IsUnset,
{
    /// Set the `rounds` field (required)
    pub fn rounds(
        mut self,
        value: impl Into<Vec<pull::Round<S>>>,
    ) -> PullBuilder<pull_state::SetRounds<St>, S> {
        self._fields.5 = Option::Some(value.into());
        PullBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: pull_state::State, S: BosStr> PullBuilder<St, S> {
    /// Set the `source` field (optional)
    pub fn source(mut self, value: impl Into<Option<pull::Source<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `source` field to an Option value (optional)
    pub fn maybe_source(mut self, value: Option<pull::Source<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> PullBuilder<St, S>
where
    St: pull_state::State,
    St::Target: pull_state::IsUnset,
{
    /// Set the `target` field (required)
    pub fn target(
        mut self,
        value: impl Into<pull::Target<S>>,
    ) -> PullBuilder<pull_state::SetTarget<St>, S> {
        self._fields.7 = Option::Some(value.into());
        PullBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> PullBuilder<St, S>
where
    St: pull_state::State,
    St::CreatedAt: pull_state::IsSet,
    St::Rounds: pull_state::IsSet,
    St::Target: pull_state::IsSet,
    St::Title: pull_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Pull<S> {
        Pull {
            body: self._fields.0,
            created_at: self._fields.1.unwrap(),
            dependent_on: self._fields.2,
            mentions: self._fields.3,
            references: self._fields.4,
            rounds: self._fields.5.unwrap(),
            source: self._fields.6,
            target: self._fields.7.unwrap(),
            title: self._fields.8.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>>) -> Pull<S> {
        Pull {
            body: self._fields.0,
            created_at: self._fields.1.unwrap(),
            dependent_on: self._fields.2,
            mentions: self._fields.3,
            references: self._fields.4,
            rounds: self._fields.5.unwrap(),
            source: self._fields.6,
            target: self._fields.7.unwrap(),
            title: self._fields.8.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_tangled_repo_pull() -> 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.repo.pull"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("target"), SmolStr::new_static("title"),
                                SmolStr::new_static("createdAt"),
                                SmolStr::new_static("rounds")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("body"),
                                LexObjectProperty::String(LexString {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("dependentOn"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::AtUri),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("mentions"),
                                LexObjectProperty::Array(LexArray {
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::Did),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("references"),
                                LexObjectProperty::Array(LexArray {
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::AtUri),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("rounds"),
                                LexObjectProperty::Array(LexArray {
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#round"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("source"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#source"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("target"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#target"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("round"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "revisions of this pull request, newer rounds are appended to this array. appviews may reject records do not treat this field as append-only. the blob format is gzipped text-based git-format-patches.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("patchBlob"),
                            SmolStr::new_static("createdAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("patchBlob"),
                            LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("source"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("branch")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("branch"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("repo"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("target"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("repo"), SmolStr::new_static("branch")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("branch"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("repo"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod round_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type CreatedAt;
        type PatchBlob;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type PatchBlob = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type PatchBlob = St::PatchBlob;
    }
    ///State transition - sets the `patch_blob` field to Set
    pub struct SetPatchBlob<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPatchBlob<St> {}
    impl<St: State> State for SetPatchBlob<St> {
        type CreatedAt = St::CreatedAt;
        type PatchBlob = Set<members::patch_blob>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `patch_blob` field
        pub struct patch_blob(());
    }
}

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

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

impl<S: BosStr> Round<S> {
    /// Create a new builder for this type
    pub fn builder() -> RoundBuilder<round_state::Empty, S> {
        RoundBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> RoundBuilder<St, S>
where
    St: round_state::State,
    St::PatchBlob: round_state::IsUnset,
{
    /// Set the `patchBlob` field (required)
    pub fn patch_blob(
        mut self,
        value: impl Into<BlobRef<S>>,
    ) -> RoundBuilder<round_state::SetPatchBlob<St>, S> {
        self._fields.1 = Option::Some(value.into());
        RoundBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> RoundBuilder<St, S>
where
    St: round_state::State,
    St::CreatedAt: round_state::IsSet,
    St::PatchBlob: round_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Round<S> {
        Round {
            created_at: self._fields.0.unwrap(),
            patch_blob: 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>>) -> Round<S> {
        Round {
            created_at: self._fields.0.unwrap(),
            patch_blob: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> Target<S> {
    /// Create a new builder for this type
    pub fn builder() -> TargetBuilder<target_state::Empty, S> {
        TargetBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> TargetBuilder<St, S>
where
    St: target_state::State,
    St::Branch: target_state::IsUnset,
{
    /// Set the `branch` field (required)
    pub fn branch(
        mut self,
        value: impl Into<S>,
    ) -> TargetBuilder<target_state::SetBranch<St>, S> {
        self._fields.0 = Option::Some(value.into());
        TargetBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> TargetBuilder<St, S>
where
    St: target_state::State,
    St::Branch: target_state::IsSet,
    St::Repo: target_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Target<S> {
        Target {
            branch: self._fields.0.unwrap(),
            repo: 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>>) -> Target<S> {
        Target {
            branch: self._fields.0.unwrap(),
            repo: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}