// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.sync.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};
use jacquard_common::deps::bytes::Bytes;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::cid::CidLink;
use jacquard_common::types::string::{Did, Handle, Tid, 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::com_atproto::sync::subscribe_repos;
/// Represents a change to an account's status on a host (eg, PDS or Relay). The semantics of this event are that the status is at the host which emitted the event, not necessarily that at the currently active PDS. Eg, a Relay takedown would emit a takedown with active=false, even if the PDS is still active.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Account<S: BosStr = DefaultStr> {
    ///Indicates that the account has a repository which can be fetched from the host that emitted this event.
    pub active: bool,
    pub did: Did<S>,
    pub seq: i64,
    ///If active=false, this optional field indicates a reason for why the account is not active.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<AccountStatus<S>>,
    pub time: Datetime,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// If active=false, this optional field indicates a reason for why the account is not active.

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum AccountStatus<S: BosStr = DefaultStr> {
    Takendown,
    Suspended,
    Deleted,
    Deactivated,
    Desynchronized,
    Throttled,
    Other(S),
}

impl<S: BosStr> AccountStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Takendown => "takendown",
            Self::Suspended => "suspended",
            Self::Deleted => "deleted",
            Self::Deactivated => "deactivated",
            Self::Desynchronized => "desynchronized",
            Self::Throttled => "throttled",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for AccountStatus<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for AccountStatus<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for AccountStatus<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for AccountStatus<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for AccountStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for AccountStatus<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = AccountStatus<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            AccountStatus::Takendown => AccountStatus::Takendown,
            AccountStatus::Suspended => AccountStatus::Suspended,
            AccountStatus::Deleted => AccountStatus::Deleted,
            AccountStatus::Deactivated => AccountStatus::Deactivated,
            AccountStatus::Desynchronized => AccountStatus::Desynchronized,
            AccountStatus::Throttled => AccountStatus::Throttled,
            AccountStatus::Other(v) => AccountStatus::Other(v.into_static()),
        }
    }
}

/// Represents an update of repository state. Note that empty commits are allowed, which include no repo data changes, but an update to rev and signature.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Commit<S: BosStr = DefaultStr> {
    pub blobs: Vec<CidLink<S>>,
    ///CAR file containing relevant blocks, as a diff since the previous repo state. The commit must be included as a block, and the commit block CID must be the first entry in the CAR header 'roots' list.
    #[serde(with = "jacquard_common::serde_bytes_helper")]
    pub blocks: Bytes,
    ///Repo commit object CID.
    pub commit: CidLink<S>,
    pub ops: Vec<subscribe_repos::RepoOp<S>>,
    ///The root CID of the MST tree for the previous commit from this repo (indicated by the 'since' revision field in this message). Corresponds to the 'data' field in the repo commit object. NOTE: this field is effectively required for the 'inductive' version of firehose.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prev_data: Option<CidLink<S>>,
    ///DEPRECATED -- unused
    pub rebase: bool,
    ///The repo this event comes from. Note that all other message types name this field 'did'.
    pub repo: Did<S>,
    ///The rev of the emitted commit. Note that this information is also in the commit object included in blocks, unless this is a tooBig event.
    pub rev: Tid,
    ///The stream sequence number of this message.
    pub seq: i64,
    ///The rev of the last emitted commit from this repo (if any).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub since: Option<Tid>,
    ///Timestamp of when this message was originally broadcast.
    pub time: Datetime,
    ///DEPRECATED -- replaced by #sync event and data limits. Indicates that this commit contained too many ops, or data size was too large. Consumers will need to make a separate request to get missing data.
    pub too_big: bool,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Represents a change to an account's identity. Could be an updated handle, signing key, or pds hosting endpoint. Serves as a prod to all downstream services to refresh their identity cache.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Identity<S: BosStr = DefaultStr> {
    pub did: Did<S>,
    ///The current handle for the account, or 'handle.invalid' if validation fails. This field is optional, might have been validated or passed-through from an upstream source. Semantics and behaviors for PDS vs Relay may evolve in the future; see atproto specs for more details.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub handle: Option<Handle<S>>,
    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, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Info<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub message: Option<S>,
    pub name: InfoName<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum InfoName<S: BosStr = DefaultStr> {
    OutdatedCursor,
    Other(S),
}

impl<S: BosStr> InfoName<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::OutdatedCursor => "OutdatedCursor",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "OutdatedCursor" => Self::OutdatedCursor,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for InfoName<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for InfoName<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for InfoName<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for InfoName<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for InfoName<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for InfoName<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = InfoName<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            InfoName::OutdatedCursor => InfoName::OutdatedCursor,
            InfoName::Other(v) => InfoName::Other(v.into_static()),
        }
    }
}


#[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 = "#commit")]
    Commit(Box<subscribe_repos::Commit<S>>),
    #[serde(rename = "#sync")]
    Sync(Box<subscribe_repos::Sync<S>>),
    #[serde(rename = "#identity")]
    Identity(Box<subscribe_repos::Identity<S>>),
    #[serde(rename = "#account")]
    Account(Box<subscribe_repos::Account<S>>),
    #[serde(rename = "#info")]
    Info(Box<subscribe_repos::Info<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() {
            "#commit" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
                    body,
                )?;
                Ok(Self::Commit(Box::new(variant)))
            }
            "#sync" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
                    body,
                )?;
                Ok(Self::Sync(Box::new(variant)))
            }
            "#identity" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
                    body,
                )?;
                Ok(Self::Identity(Box::new(variant)))
            }
            "#account" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
                    body,
                )?;
                Ok(Self::Account(Box::new(variant)))
            }
            "#info" => {
                let variant = jacquard_common::deps::codegen::serde_ipld_dagcbor::from_slice(
                    body,
                )?;
                Ok(Self::Info(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(())
            }
        }
    }
}

/// A repo operation, ie a mutation of a single record.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RepoOp<S: BosStr = DefaultStr> {
    pub action: RepoOpAction<S>,
    ///For creates and updates, the new record CID. For deletions, null.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<CidLink<S>>,
    pub path: S,
    ///For updates and deletes, the previous record CID (required for inductive firehose). For creations, field should not be defined.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prev: Option<CidLink<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RepoOpAction<S: BosStr = DefaultStr> {
    Create,
    Update,
    Delete,
    Other(S),
}

impl<S: BosStr> RepoOpAction<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Create => "create",
            Self::Update => "update",
            Self::Delete => "delete",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "create" => Self::Create,
            "update" => Self::Update,
            "delete" => Self::Delete,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for RepoOpAction<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for RepoOpAction<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for RepoOpAction<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for RepoOpAction<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for RepoOpAction<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for RepoOpAction<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = RepoOpAction<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            RepoOpAction::Create => RepoOpAction::Create,
            RepoOpAction::Update => RepoOpAction::Update,
            RepoOpAction::Delete => RepoOpAction::Delete,
            RepoOpAction::Other(v) => RepoOpAction::Other(v.into_static()),
        }
    }
}

/// Updates the repo to a new state, without necessarily including that state on the firehose. Used to recover from broken commit streams, data loss incidents, or in situations where upstream host does not know recent state of the repository.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Sync<S: BosStr = DefaultStr> {
    ///CAR file containing the commit, as a block. The CAR header must include the commit block CID as the first 'root'.
    #[serde(with = "jacquard_common::serde_bytes_helper")]
    pub blocks: Bytes,
    ///The account this repo event corresponds to. Must match that in the commit object.
    pub did: Did<S>,
    ///The rev of the commit. This value must match that in the commit object.
    pub rev: S,
    ///The stream sequence number of this message.
    pub seq: i64,
    ///Timestamp of when this message was originally broadcast.
    pub time: Datetime,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Account<S> {
    fn nsid() -> &'static str {
        "com.atproto.sync.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "account"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_sync_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Commit<S> {
    fn nsid() -> &'static str {
        "com.atproto.sync.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "commit"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_sync_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.ops;
            #[allow(unused_comparisons)]
            if value.len() > 200usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("ops"),
                    max: 200usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

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

impl<S: BosStr> LexiconSchema for Info<S> {
    fn nsid() -> &'static str {
        "com.atproto.sync.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "info"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_sync_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

///Stream response type for
///com.atproto.sync.subscribeRepos
pub struct SubscribeReposStream;
impl jacquard_common::xrpc::SubscriptionResp for SubscribeReposStream {
    const NSID: &'static str = "com.atproto.sync.subscribeRepos";
    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::DagCbor;
    type Message<S: BosStr> = SubscribeReposMessage<S>;
    type Error = SubscribeReposError;
    fn decode_message<'de, S>(
        bytes: &'de [u8],
    ) -> Result<Self::Message<S>, jacquard_common::error::DecodeError>
    where
        S: BosStr + serde::Deserialize<'de>,
        Self::Message<S>: serde::Deserialize<'de>,
    {
        SubscribeReposMessage::decode_framed(bytes)
    }
}

impl jacquard_common::xrpc::XrpcSubscription for SubscribeRepos {
    const NSID: &'static str = "com.atproto.sync.subscribeRepos";
    const ENCODING: jacquard_common::xrpc::MessageEncoding = jacquard_common::xrpc::MessageEncoding::DagCbor;
    type Stream = SubscribeReposStream;
}

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

impl<S: BosStr> LexiconSchema for RepoOp<S> {
    fn nsid() -> &'static str {
        "com.atproto.sync.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "repoOp"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_sync_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Sync<S> {
    fn nsid() -> &'static str {
        "com.atproto.sync.subscribeRepos"
    }
    fn def_name() -> &'static str {
        "sync"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_sync_subscribeRepos()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod account_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 Active;
        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 Active = Unset;
        type Did = Unset;
        type Seq = Unset;
        type Time = Unset;
    }
    ///State transition - sets the `active` field to Set
    pub struct SetActive<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetActive<St> {}
    impl<St: State> State for SetActive<St> {
        type Active = Set<members::active>;
        type Did = St::Did;
        type Seq = St::Seq;
        type Time = St::Time;
    }
    ///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 Active = St::Active;
        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 Active = St::Active;
        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 Active = St::Active;
        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 `active` field
        pub struct active(());
        ///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 AccountBuilder<St: account_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<bool>,
        Option<Did<S>>,
        Option<i64>,
        Option<AccountStatus<S>>,
        Option<Datetime>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Account<S> {
    /// Create a new builder for this type
    pub fn builder() -> AccountBuilder<account_state::Empty, S> {
        AccountBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> AccountBuilder<St, S>
where
    St: account_state::State,
    St::Active: account_state::IsUnset,
{
    /// Set the `active` field (required)
    pub fn active(
        mut self,
        value: impl Into<bool>,
    ) -> AccountBuilder<account_state::SetActive<St>, S> {
        self._fields.0 = Option::Some(value.into());
        AccountBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St: account_state::State, S: BosStr> AccountBuilder<St, S> {
    /// Set the `status` field (optional)
    pub fn status(mut self, value: impl Into<Option<AccountStatus<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `status` field to an Option value (optional)
    pub fn maybe_status(mut self, value: Option<AccountStatus<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<St, S: BosStr> AccountBuilder<St, S>
where
    St: account_state::State,
    St::Active: account_state::IsSet,
    St::Did: account_state::IsSet,
    St::Seq: account_state::IsSet,
    St::Time: account_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Account<S> {
        Account {
            active: self._fields.0.unwrap(),
            did: self._fields.1.unwrap(),
            seq: self._fields.2.unwrap(),
            status: self._fields.3,
            time: self._fields.4.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>>) -> Account<S> {
        Account {
            active: self._fields.0.unwrap(),
            did: self._fields.1.unwrap(),
            seq: self._fields.2.unwrap(),
            status: self._fields.3,
            time: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_sync_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("com.atproto.sync.subscribeRepos"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("account"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Represents a change to an account's status on a host (eg, PDS or Relay). The semantics of this event are that the status is at the host which emitted the event, not necessarily that at the currently active PDS. Eg, a Relay takedown would emit a takedown with active=false, even if the PDS is still active.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("seq"), SmolStr::new_static("did"),
                            SmolStr::new_static("time"), SmolStr::new_static("active")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("active"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("seq"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("status"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "If active=false, this optional field indicates a reason for why the account is not active.",
                                    ),
                                ),
                                ..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("commit"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Represents an update of repository state. Note that empty commits are allowed, which include no repo data changes, but an update to rev and signature.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("seq"), SmolStr::new_static("rebase"),
                            SmolStr::new_static("tooBig"), SmolStr::new_static("repo"),
                            SmolStr::new_static("commit"), SmolStr::new_static("rev"),
                            SmolStr::new_static("since"), SmolStr::new_static("blocks"),
                            SmolStr::new_static("ops"), SmolStr::new_static("blobs"),
                            SmolStr::new_static("time")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("blobs"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::CidLink(LexCidLink {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("blocks"),
                            LexObjectProperty::Bytes(LexBytes {
                                max_length: Some(2000000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("commit"),
                            LexObjectProperty::CidLink(LexCidLink {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("ops"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#repoOp"),
                                    ..Default::default()
                                }),
                                max_length: Some(200usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("prevData"),
                            LexObjectProperty::CidLink(LexCidLink {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rebase"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("repo"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The repo this event comes from. Note that all other message types name this field 'did'.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rev"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The rev of the emitted commit. Note that this information is also in the commit object included in blocks, unless this is a tooBig event.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Tid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("seq"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("since"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The rev of the last emitted commit from this repo (if any).",
                                    ),
                                ),
                                format: Some(LexStringFormat::Tid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("time"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Timestamp of when this message was originally broadcast.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("tooBig"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("identity"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Represents a change to an account's identity. Could be an updated handle, signing key, or pds hosting endpoint. Serves as a prod to all downstream services to refresh their identity cache.",
                        ),
                    ),
                    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 {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The current handle for the account, or 'handle.invalid' if validation fails. This field is optional, might have been validated or passed-through from an upstream source. Semantics and behaviors for PDS vs Relay may evolve in the future; see atproto specs for more details.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Handle),
                                ..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("info"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("name")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("message"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString { ..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.insert(
                SmolStr::new_static("repoOp"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A repo operation, ie a mutation of a single record.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("action"), SmolStr::new_static("path"),
                            SmolStr::new_static("cid")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("action"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::CidLink(LexCidLink {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("path"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("prev"),
                            LexObjectProperty::CidLink(LexCidLink {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("sync"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Updates the repo to a new state, without necessarily including that state on the firehose. Used to recover from broken commit streams, data loss incidents, or in situations where upstream host does not know recent state of the repository.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("seq"), SmolStr::new_static("did"),
                            SmolStr::new_static("blocks"), SmolStr::new_static("rev"),
                            SmolStr::new_static("time")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("blocks"),
                            LexObjectProperty::Bytes(LexBytes {
                                max_length: Some(10000usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The account this repo event corresponds to. Must match that in the commit object.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rev"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The rev of the commit. This value must match that in the commit object.",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("seq"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("time"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Timestamp of when this message was originally broadcast.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod commit_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 Blobs;
        type Blocks;
        type Commit;
        type Ops;
        type Rebase;
        type Repo;
        type Rev;
        type Seq;
        type Time;
        type TooBig;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Blobs = Unset;
        type Blocks = Unset;
        type Commit = Unset;
        type Ops = Unset;
        type Rebase = Unset;
        type Repo = Unset;
        type Rev = Unset;
        type Seq = Unset;
        type Time = Unset;
        type TooBig = Unset;
    }
    ///State transition - sets the `blobs` field to Set
    pub struct SetBlobs<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBlobs<St> {}
    impl<St: State> State for SetBlobs<St> {
        type Blobs = Set<members::blobs>;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///State transition - sets the `blocks` field to Set
    pub struct SetBlocks<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBlocks<St> {}
    impl<St: State> State for SetBlocks<St> {
        type Blobs = St::Blobs;
        type Blocks = Set<members::blocks>;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///State transition - sets the `commit` field to Set
    pub struct SetCommit<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCommit<St> {}
    impl<St: State> State for SetCommit<St> {
        type Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = Set<members::commit>;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///State transition - sets the `ops` field to Set
    pub struct SetOps<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetOps<St> {}
    impl<St: State> State for SetOps<St> {
        type Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = Set<members::ops>;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///State transition - sets the `rebase` field to Set
    pub struct SetRebase<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRebase<St> {}
    impl<St: State> State for SetRebase<St> {
        type Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = Set<members::rebase>;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///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 Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = Set<members::repo>;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///State transition - sets the `rev` field to Set
    pub struct SetRev<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRev<St> {}
    impl<St: State> State for SetRev<St> {
        type Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = Set<members::rev>;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///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 Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = Set<members::seq>;
        type Time = St::Time;
        type TooBig = St::TooBig;
    }
    ///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 Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = Set<members::time>;
        type TooBig = St::TooBig;
    }
    ///State transition - sets the `too_big` field to Set
    pub struct SetTooBig<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTooBig<St> {}
    impl<St: State> State for SetTooBig<St> {
        type Blobs = St::Blobs;
        type Blocks = St::Blocks;
        type Commit = St::Commit;
        type Ops = St::Ops;
        type Rebase = St::Rebase;
        type Repo = St::Repo;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
        type TooBig = Set<members::too_big>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `blobs` field
        pub struct blobs(());
        ///Marker type for the `blocks` field
        pub struct blocks(());
        ///Marker type for the `commit` field
        pub struct commit(());
        ///Marker type for the `ops` field
        pub struct ops(());
        ///Marker type for the `rebase` field
        pub struct rebase(());
        ///Marker type for the `repo` field
        pub struct repo(());
        ///Marker type for the `rev` field
        pub struct rev(());
        ///Marker type for the `seq` field
        pub struct seq(());
        ///Marker type for the `time` field
        pub struct time(());
        ///Marker type for the `too_big` field
        pub struct too_big(());
    }
}

/// Builder for constructing an instance of this type.
pub struct CommitBuilder<St: commit_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<CidLink<S>>>,
        Option<Bytes>,
        Option<CidLink<S>>,
        Option<Vec<subscribe_repos::RepoOp<S>>>,
        Option<CidLink<S>>,
        Option<bool>,
        Option<Did<S>>,
        Option<Tid>,
        Option<i64>,
        Option<Tid>,
        Option<Datetime>,
        Option<bool>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Commit<S> {
    /// Create a new builder for this type
    pub fn builder() -> CommitBuilder<commit_state::Empty, S> {
        CommitBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::Blobs: commit_state::IsUnset,
{
    /// Set the `blobs` field (required)
    pub fn blobs(
        mut self,
        value: impl Into<Vec<CidLink<S>>>,
    ) -> CommitBuilder<commit_state::SetBlobs<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::Blocks: commit_state::IsUnset,
{
    /// Set the `blocks` field (required)
    pub fn blocks(
        mut self,
        value: impl Into<Bytes>,
    ) -> CommitBuilder<commit_state::SetBlocks<St>, S> {
        self._fields.1 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::Commit: commit_state::IsUnset,
{
    /// Set the `commit` field (required)
    pub fn commit(
        mut self,
        value: impl Into<CidLink<S>>,
    ) -> CommitBuilder<commit_state::SetCommit<St>, S> {
        self._fields.2 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::Ops: commit_state::IsUnset,
{
    /// Set the `ops` field (required)
    pub fn ops(
        mut self,
        value: impl Into<Vec<subscribe_repos::RepoOp<S>>>,
    ) -> CommitBuilder<commit_state::SetOps<St>, S> {
        self._fields.3 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: commit_state::State, S: BosStr> CommitBuilder<St, S> {
    /// Set the `prevData` field (optional)
    pub fn prev_data(mut self, value: impl Into<Option<CidLink<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `prevData` field to an Option value (optional)
    pub fn maybe_prev_data(mut self, value: Option<CidLink<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::Rebase: commit_state::IsUnset,
{
    /// Set the `rebase` field (required)
    pub fn rebase(
        mut self,
        value: impl Into<bool>,
    ) -> CommitBuilder<commit_state::SetRebase<St>, S> {
        self._fields.5 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::Rev: commit_state::IsUnset,
{
    /// Set the `rev` field (required)
    pub fn rev(
        mut self,
        value: impl Into<Tid>,
    ) -> CommitBuilder<commit_state::SetRev<St>, S> {
        self._fields.7 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St: commit_state::State, S: BosStr> CommitBuilder<St, S> {
    /// Set the `since` field (optional)
    pub fn since(mut self, value: impl Into<Option<Tid>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `since` field to an Option value (optional)
    pub fn maybe_since(mut self, value: Option<Tid>) -> Self {
        self._fields.9 = value;
        self
    }
}

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

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::TooBig: commit_state::IsUnset,
{
    /// Set the `tooBig` field (required)
    pub fn too_big(
        mut self,
        value: impl Into<bool>,
    ) -> CommitBuilder<commit_state::SetTooBig<St>, S> {
        self._fields.11 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CommitBuilder<St, S>
where
    St: commit_state::State,
    St::Blobs: commit_state::IsSet,
    St::Blocks: commit_state::IsSet,
    St::Commit: commit_state::IsSet,
    St::Ops: commit_state::IsSet,
    St::Rebase: commit_state::IsSet,
    St::Repo: commit_state::IsSet,
    St::Rev: commit_state::IsSet,
    St::Seq: commit_state::IsSet,
    St::Time: commit_state::IsSet,
    St::TooBig: commit_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Commit<S> {
        Commit {
            blobs: self._fields.0.unwrap(),
            blocks: self._fields.1.unwrap(),
            commit: self._fields.2.unwrap(),
            ops: self._fields.3.unwrap(),
            prev_data: self._fields.4,
            rebase: self._fields.5.unwrap(),
            repo: self._fields.6.unwrap(),
            rev: self._fields.7.unwrap(),
            seq: self._fields.8.unwrap(),
            since: self._fields.9,
            time: self._fields.10.unwrap(),
            too_big: self._fields.11.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>>) -> Commit<S> {
        Commit {
            blobs: self._fields.0.unwrap(),
            blocks: self._fields.1.unwrap(),
            commit: self._fields.2.unwrap(),
            ops: self._fields.3.unwrap(),
            prev_data: self._fields.4,
            rebase: self._fields.5.unwrap(),
            repo: self._fields.6.unwrap(),
            rev: self._fields.7.unwrap(),
            seq: self._fields.8.unwrap(),
            since: self._fields.9,
            time: self._fields.10.unwrap(),
            too_big: self._fields.11.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<Handle<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, 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, 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: identity_state::State, S: BosStr> IdentityBuilder<St, S> {
    /// Set the `handle` field (optional)
    pub fn handle(mut self, value: impl Into<Option<Handle<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `handle` field to an Option value (optional)
    pub fn maybe_handle(mut self, value: Option<Handle<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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.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::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.3 = 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(),
            handle: self._fields.1,
            seq: self._fields.2.unwrap(),
            time: self._fields.3.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(),
            handle: self._fields.1,
            seq: self._fields.2.unwrap(),
            time: self._fields.3.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,
        }
    }
}

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

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

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

impl<S: BosStr> RepoOp<S> {
    /// Create a new builder for this type
    pub fn builder() -> RepoOpBuilder<repo_op_state::Empty, S> {
        RepoOpBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> RepoOpBuilder<St, S>
where
    St: repo_op_state::State,
    St::Action: repo_op_state::IsUnset,
{
    /// Set the `action` field (required)
    pub fn action(
        mut self,
        value: impl Into<RepoOpAction<S>>,
    ) -> RepoOpBuilder<repo_op_state::SetAction<St>, S> {
        self._fields.0 = Option::Some(value.into());
        RepoOpBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: repo_op_state::State, S: BosStr> RepoOpBuilder<St, S> {
    /// Set the `cid` field (optional)
    pub fn cid(mut self, value: impl Into<Option<CidLink<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `cid` field to an Option value (optional)
    pub fn maybe_cid(mut self, value: Option<CidLink<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> RepoOpBuilder<St, S>
where
    St: repo_op_state::State,
    St::Path: repo_op_state::IsUnset,
{
    /// Set the `path` field (required)
    pub fn path(
        mut self,
        value: impl Into<S>,
    ) -> RepoOpBuilder<repo_op_state::SetPath<St>, S> {
        self._fields.2 = Option::Some(value.into());
        RepoOpBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: repo_op_state::State, S: BosStr> RepoOpBuilder<St, S> {
    /// Set the `prev` field (optional)
    pub fn prev(mut self, value: impl Into<Option<CidLink<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `prev` field to an Option value (optional)
    pub fn maybe_prev(mut self, value: Option<CidLink<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> RepoOpBuilder<St, S>
where
    St: repo_op_state::State,
    St::Action: repo_op_state::IsSet,
    St::Path: repo_op_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> RepoOp<S> {
        RepoOp {
            action: self._fields.0.unwrap(),
            cid: self._fields.1,
            path: self._fields.2.unwrap(),
            prev: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> RepoOp<S> {
        RepoOp {
            action: self._fields.0.unwrap(),
            cid: self._fields.1,
            path: self._fields.2.unwrap(),
            prev: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

pub mod sync_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 Blocks;
        type Did;
        type Rev;
        type Seq;
        type Time;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Blocks = Unset;
        type Did = Unset;
        type Rev = Unset;
        type Seq = Unset;
        type Time = Unset;
    }
    ///State transition - sets the `blocks` field to Set
    pub struct SetBlocks<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetBlocks<St> {}
    impl<St: State> State for SetBlocks<St> {
        type Blocks = Set<members::blocks>;
        type Did = St::Did;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
    }
    ///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 Blocks = St::Blocks;
        type Did = Set<members::did>;
        type Rev = St::Rev;
        type Seq = St::Seq;
        type Time = St::Time;
    }
    ///State transition - sets the `rev` field to Set
    pub struct SetRev<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRev<St> {}
    impl<St: State> State for SetRev<St> {
        type Blocks = St::Blocks;
        type Did = St::Did;
        type Rev = Set<members::rev>;
        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 Blocks = St::Blocks;
        type Did = St::Did;
        type Rev = St::Rev;
        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 Blocks = St::Blocks;
        type Did = St::Did;
        type Rev = St::Rev;
        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 `blocks` field
        pub struct blocks(());
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `rev` field
        pub struct rev(());
        ///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 SyncBuilder<St: sync_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Bytes>, Option<Did<S>>, Option<S>, Option<i64>, Option<Datetime>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Sync<S> {
    /// Create a new builder for this type
    pub fn builder() -> SyncBuilder<sync_state::Empty, S> {
        SyncBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> SyncBuilder<St, S>
where
    St: sync_state::State,
    St::Blocks: sync_state::IsUnset,
{
    /// Set the `blocks` field (required)
    pub fn blocks(
        mut self,
        value: impl Into<Bytes>,
    ) -> SyncBuilder<sync_state::SetBlocks<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SyncBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> SyncBuilder<St, S>
where
    St: sync_state::State,
    St::Rev: sync_state::IsUnset,
{
    /// Set the `rev` field (required)
    pub fn rev(mut self, value: impl Into<S>) -> SyncBuilder<sync_state::SetRev<St>, S> {
        self._fields.2 = Option::Some(value.into());
        SyncBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St, S: BosStr> SyncBuilder<St, S>
where
    St: sync_state::State,
    St::Blocks: sync_state::IsSet,
    St::Did: sync_state::IsSet,
    St::Rev: sync_state::IsSet,
    St::Seq: sync_state::IsSet,
    St::Time: sync_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Sync<S> {
        Sync {
            blocks: self._fields.0.unwrap(),
            did: self._fields.1.unwrap(),
            rev: self._fields.2.unwrap(),
            seq: self._fields.3.unwrap(),
            time: self._fields.4.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>>) -> Sync<S> {
        Sync {
            blocks: self._fields.0.unwrap(),
            did: self._fields.1.unwrap(),
            rev: self._fields.2.unwrap(),
            seq: self._fields.3.unwrap(),
            time: self._fields.4.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}