// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: sh.tangled.knot.subscribeRepos
//
// 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::string::{Did, AtUri, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::sh_tangled::git::ref_update::RefUpdate;
use crate::sh_tangled::knot::subscribe_repos;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GitSync1<S: BosStr = DefaultStr> {
    ///Repository DID identifier
    pub did: Did<S>,
    ///The stream sequence number of this message.
    pub seq: 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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GitSync2<S: BosStr = DefaultStr> {
    ///Repository AT-URI identifier
    pub repo: AtUri<S>,
    ///The stream sequence number of this message.
    pub seq: 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)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Identity<S: BosStr = DefaultStr> {
    ///Repository DID identifier
    pub did: Did<S>,
    ///The stream sequence number of this message.
    pub seq: i64,
    pub time: Datetime,
    #[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")]
pub struct SubscribeRepos {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<i64>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum SubscribeReposMessage<S: BosStr = DefaultStr> {
    #[serde(rename = "#identity")]
    Identity(Box<subscribe_repos::Identity<S>>),
    #[serde(rename = "sh.tangled.git.refUpdate")]
    RefUpdate(Box<RefUpdate<S>>),
}

impl<S: BosStr> SubscribeReposMessage<S> {
    /// Decode a framed DAG-CBOR message (header + body).
    pub fn decode_framed<'de>(
        bytes: &'de [u8],
    ) -> Result<SubscribeReposMessage<S>, jacquard_common::error::DecodeError>
    where
        S: serde::Deserialize<'de>,
    {
        let (header, body) = jacquard_common::xrpc::subscription::parse_event_header(
            bytes,
        )?;
        match header.t.as_str() {
            "#identity" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
                    body,
                )?;
                Ok(Self::Identity(Box::new(variant)))
            }
            "sh.tangled.git.refUpdate" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
                    body,
                )?;
                Ok(Self::RefUpdate(Box::new(variant)))
            }
            unknown => {
                Err(
                    jacquard_common::error::DecodeError::UnknownEventType(unknown.into()),
                )
            }
        }
    }
}


#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum SubscribeReposError {
    #[serde(rename = "FutureCursor")]
    FutureCursor(Option<SmolStr>),
    /// If the consumer of the stream can not keep up with events, and a backlog gets too large, the server will drop the connection.
    #[serde(rename = "ConsumerTooSlow")]
    ConsumerTooSlow(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for SubscribeReposError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::FutureCursor(msg) => {
                write!(f, "FutureCursor")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::ConsumerTooSlow(msg) => {
                write!(f, "ConsumerTooSlow")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

impl<S: BosStr> LexiconSchema for GitSync1<S> {
    fn nsid() -> &'static str {
        "sh.tangled.knot.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "gitSync1"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_knot_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for GitSync2<S> {
    fn nsid() -> &'static str {
        "sh.tangled.knot.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "gitSync2"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_knot_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Identity<S> {
    fn nsid() -> &'static str {
        "sh.tangled.knot.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "identity"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_sh_tangled_knot_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

///Stream response type for
///sh.tangled.knot.subscribeRepos
pub struct SubscribeReposStream;
impl jacquard_common::xrpc::SubscriptionResp for SubscribeReposStream {
    const NSID: &'static str = "sh.tangled.knot.subscribeRepos";
    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
    type Message<S: BosStr> = SubscribeReposMessage<S>;
    type Error = SubscribeReposError;
}

impl jacquard_common::xrpc::XrpcSubscription for SubscribeRepos {
    const NSID: &'static str = "sh.tangled.knot.subscribeRepos";
    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
    type Stream = SubscribeReposStream;
}

pub struct SubscribeReposEndpoint;
impl jacquard_common::xrpc::SubscriptionEndpoint for SubscribeReposEndpoint {
    const PATH: &'static str = "/xrpc/sh.tangled.knot.subscribeRepos";
    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::Json;
    type Params<S: BosStr> = SubscribeRepos;
    type Stream = SubscribeReposStream;
}

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

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

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

impl<S: BosStr> GitSync1<S> {
    /// Create a new builder for this type
    pub fn builder() -> GitSync1Builder<git_sync1_state::Empty, S> {
        GitSync1Builder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> GitSync1Builder<St, S>
where
    St: git_sync1_state::State,
    St::Did: git_sync1_state::IsSet,
    St::Seq: git_sync1_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GitSync1<S> {
        GitSync1 {
            did: self._fields.0.unwrap(),
            seq: 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>>) -> GitSync1<S> {
        GitSync1 {
            did: self._fields.0.unwrap(),
            seq: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_sh_tangled_knot_subscribeRepos() -> 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.knot.subscribeRepos"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("gitSync1"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("seq"), SmolStr::new_static("did")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Repository DID identifier"),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("seq"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("gitSync2"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("seq"), SmolStr::new_static("repo")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("repo"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Repository AT-URI identifier"),
                                ),
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("seq"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("identity"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("seq"), SmolStr::new_static("did"),
                            SmolStr::new_static("time")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Repository DID identifier"),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("seq"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("time"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcSubscription(LexXrpcSubscription {
                    parameters: Some(
                        LexXrpcSubscriptionParameter::Params(LexXrpcParameters {
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> GitSync2<S> {
    /// Create a new builder for this type
    pub fn builder() -> GitSync2Builder<git_sync2_state::Empty, S> {
        GitSync2Builder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> GitSync2Builder<St, S>
where
    St: git_sync2_state::State,
    St::Repo: git_sync2_state::IsSet,
    St::Seq: git_sync2_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GitSync2<S> {
        GitSync2 {
            repo: self._fields.0.unwrap(),
            seq: 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>>) -> GitSync2<S> {
        GitSync2 {
            repo: self._fields.0.unwrap(),
            seq: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod identity_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 Did;
        type Seq;
        type Time;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Did = Unset;
        type Seq = Unset;
        type Time = Unset;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDid<St> {}
    impl<St: State> State for SetDid<St> {
        type Did = Set<members::did>;
        type Seq = St::Seq;
        type Time = St::Time;
    }
    ///State transition - sets the `seq` field to Set
    pub struct SetSeq<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSeq<St> {}
    impl<St: State> State for SetSeq<St> {
        type Did = St::Did;
        type Seq = Set<members::seq>;
        type Time = St::Time;
    }
    ///State transition - sets the `time` field to Set
    pub struct SetTime<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTime<St> {}
    impl<St: State> State for SetTime<St> {
        type Did = St::Did;
        type Seq = St::Seq;
        type Time = Set<members::time>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `seq` field
        pub struct seq(());
        ///Marker type for the `time` field
        pub struct time(());
    }
}

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

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

impl<S: BosStr> Identity<S> {
    /// Create a new builder for this type
    pub fn builder() -> IdentityBuilder<identity_state::Empty, S> {
        IdentityBuilder::builder()
    }
}

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

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

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

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

impl<St, S: BosStr> IdentityBuilder<St, S>
where
    St: identity_state::State,
    St::Time: identity_state::IsUnset,
{
    /// Set the `time` field (required)
    pub fn time(
        mut self,
        value: impl Into<Datetime>,
    ) -> IdentityBuilder<identity_state::SetTime<St>, S> {
        self._fields.2 = Option::Some(value.into());
        IdentityBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> IdentityBuilder<St, S>
where
    St: identity_state::State,
    St::Did: identity_state::IsSet,
    St::Seq: identity_state::IsSet,
    St::Time: identity_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Identity<S> {
        Identity {
            did: self._fields.0.unwrap(),
            seq: self._fields.1.unwrap(),
            time: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Identity<S> {
        Identity {
            did: self._fields.0.unwrap(),
            seq: self._fields.1.unwrap(),
            time: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod subscribe_repos_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 {}
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {}
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {}
}

/// Builder for constructing an instance of this type.
pub struct SubscribeReposBuilder<St: subscribe_repos_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<i64>,),
}

impl SubscribeRepos {
    /// Create a new builder for this type.
    pub fn new() -> SubscribeReposBuilder<subscribe_repos_state::Empty> {
        SubscribeReposBuilder::new()
    }
}

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

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

impl<St: subscribe_repos_state::State> SubscribeReposBuilder<St> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `cursor` field to an Option value (optional)
    pub fn maybe_cursor(mut self, value: Option<i64>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St> SubscribeReposBuilder<St>
where
    St: subscribe_repos_state::State,
{
    /// Build the final struct.
    pub fn build(self) -> SubscribeRepos {
        SubscribeRepos {
            cursor: self._fields.0,
        }
    }
}