// @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;
use jacquard_common::deps::bytes::Bytes;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::cid::CidLink;
use jacquard_common::types::string::{Did, Handle, Tid, Datetime};
use jacquard_derive::{IntoStatic, lexicon, 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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Account<'a> {
    ///Indicates that the account has a repository which can be fetched from the host that emitted this event.
    pub active: bool,
    #[serde(borrow)]
    pub did: Did<'a>,
    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")]
    #[serde(borrow)]
    pub status: Option<AccountStatus<'a>>,
    pub time: Datetime,
}

/// 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<'a> {
    Takendown,
    Suspended,
    Deleted,
    Deactivated,
    Desynchronized,
    Throttled,
    Other(CowStr<'a>),
}

impl<'a> AccountStatus<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for AccountStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for AccountStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "takendown" => Self::Takendown,
            "suspended" => Self::Suspended,
            "deleted" => Self::Deleted,
            "deactivated" => Self::Deactivated,
            "desynchronized" => Self::Desynchronized,
            "throttled" => Self::Throttled,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for AccountStatus<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for AccountStatus<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for AccountStatus<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for AccountStatus<'_> {
    type Output = AccountStatus<'static>;
    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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Commit<'a> {
    #[serde(borrow)]
    pub blobs: Vec<CidLink<'a>>,
    ///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.
    #[serde(borrow)]
    pub commit: CidLink<'a>,
    #[serde(borrow)]
    pub ops: Vec<subscribe_repos::RepoOp<'a>>,
    ///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")]
    #[serde(borrow)]
    pub prev_data: Option<CidLink<'a>>,
    ///DEPRECATED -- unused
    pub rebase: bool,
    ///The repo this event comes from. Note that all other message types name this field 'did'.
    #[serde(borrow)]
    pub repo: Did<'a>,
    ///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,
}

/// 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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Identity<'a> {
    #[serde(borrow)]
    pub did: Did<'a>,
    ///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")]
    #[serde(borrow)]
    pub handle: Option<Handle<'a>>,
    pub seq: i64,
    pub time: Datetime,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct Info<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub message: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub name: InfoName<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum InfoName<'a> {
    OutdatedCursor,
    Other(CowStr<'a>),
}

impl<'a> InfoName<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::OutdatedCursor => "OutdatedCursor",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for InfoName<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "OutdatedCursor" => Self::OutdatedCursor,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for InfoName<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "OutdatedCursor" => Self::OutdatedCursor,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for InfoName<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for InfoName<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for InfoName<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for InfoName<'_> {
    type Output = InfoName<'static>;
    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")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum SubscribeReposMessage<'a> {
    #[serde(rename = "#commit")]
    Commit(Box<subscribe_repos::Commit<'a>>),
    #[serde(rename = "#sync")]
    Sync(Box<subscribe_repos::Sync<'a>>),
    #[serde(rename = "#identity")]
    Identity(Box<subscribe_repos::Identity<'a>>),
    #[serde(rename = "#account")]
    Account(Box<subscribe_repos::Account<'a>>),
    #[serde(rename = "#info")]
    Info(Box<subscribe_repos::Info<'a>>),
}

impl<'a> SubscribeReposMessage<'a> {
    /// Decode a framed DAG-CBOR message (header + body).
    pub fn decode_framed<'de: 'a>(
        bytes: &'de [u8],
    ) -> Result<SubscribeReposMessage<'a>, jacquard_common::error::DecodeError> {
        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()),
                )
            }
        }
    }
}


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

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum SubscribeReposError<'a> {
    #[serde(rename = "FutureCursor")]
    FutureCursor(Option<CowStr<'a>>),
    /// 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<CowStr<'a>>),
}

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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RepoOp<'a> {
    #[serde(borrow)]
    pub action: RepoOpAction<'a>,
    ///For creates and updates, the new record CID. For deletions, null.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<CidLink<'a>>,
    #[serde(borrow)]
    pub path: CowStr<'a>,
    ///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")]
    #[serde(borrow)]
    pub prev: Option<CidLink<'a>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RepoOpAction<'a> {
    Create,
    Update,
    Delete,
    Other(CowStr<'a>),
}

impl<'a> RepoOpAction<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Create => "create",
            Self::Update => "update",
            Self::Delete => "delete",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for RepoOpAction<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "create" => Self::Create,
            "update" => Self::Update,
            "delete" => Self::Delete,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for RepoOpAction<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "create" => Self::Create,
            "update" => Self::Update,
            "delete" => Self::Delete,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for RepoOpAction<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for RepoOpAction<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for RepoOpAction<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for RepoOpAction<'_> {
    type Output = RepoOpAction<'static>;
    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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Sync<'a> {
    ///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.
    #[serde(borrow)]
    pub did: Did<'a>,
    ///The rev of the commit. This value must match that in the commit object.
    #[serde(borrow)]
    pub rev: CowStr<'a>,
    ///The stream sequence number of this message.
    pub seq: i64,
    ///Timestamp of when this message was originally broadcast.
    pub time: Datetime,
}

impl<'a> LexiconSchema for Account<'a> {
    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<'a> LexiconSchema for Commit<'a> {
    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<'a> LexiconSchema for Identity<'a> {
    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<'a> LexiconSchema for Info<'a> {
    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<'de> = SubscribeReposMessage<'de>;
    type Error<'de> = SubscribeReposError<'de>;
    fn decode_message<'de>(
        bytes: &'de [u8],
    ) -> Result<Self::Message<'de>, jacquard_common::error::DecodeError> {
        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<'de> = SubscribeRepos;
    type Stream = SubscribeReposStream;
}

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

/// Builder for constructing an instance of this type
pub struct AccountBuilder<'a, S: account_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<bool>,
        Option<Did<'a>>,
        Option<i64>,
        Option<AccountStatus<'a>>,
        Option<Datetime>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S: account_state::State> AccountBuilder<'a, S> {
    /// Set the `status` field (optional)
    pub fn status(mut self, value: impl Into<Option<AccountStatus<'a>>>) -> 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<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<'a, S> AccountBuilder<'a, S>
where
    S: account_state::State,
    S::Time: account_state::IsSet,
    S::Active: account_state::IsSet,
    S::Seq: account_state::IsSet,
    S::Did: account_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Account<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Account<'a> {
        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 Seq;
        type Ops;
        type TooBig;
        type Rev;
        type Repo;
        type Time;
        type Rebase;
        type Blobs;
        type Commit;
        type Blocks;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Seq = Unset;
        type Ops = Unset;
        type TooBig = Unset;
        type Rev = Unset;
        type Repo = Unset;
        type Time = Unset;
        type Rebase = Unset;
        type Blobs = Unset;
        type Commit = Unset;
        type Blocks = Unset;
    }
    ///State transition - sets the `seq` field to Set
    pub struct SetSeq<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSeq<S> {}
    impl<S: State> State for SetSeq<S> {
        type Seq = Set<members::seq>;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `ops` field to Set
    pub struct SetOps<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetOps<S> {}
    impl<S: State> State for SetOps<S> {
        type Seq = S::Seq;
        type Ops = Set<members::ops>;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `too_big` field to Set
    pub struct SetTooBig<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTooBig<S> {}
    impl<S: State> State for SetTooBig<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = Set<members::too_big>;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `rev` field to Set
    pub struct SetRev<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRev<S> {}
    impl<S: State> State for SetRev<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = Set<members::rev>;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `repo` field to Set
    pub struct SetRepo<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRepo<S> {}
    impl<S: State> State for SetRepo<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = Set<members::repo>;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `time` field to Set
    pub struct SetTime<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTime<S> {}
    impl<S: State> State for SetTime<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = Set<members::time>;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `rebase` field to Set
    pub struct SetRebase<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRebase<S> {}
    impl<S: State> State for SetRebase<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = Set<members::rebase>;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `blobs` field to Set
    pub struct SetBlobs<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBlobs<S> {}
    impl<S: State> State for SetBlobs<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = Set<members::blobs>;
        type Commit = S::Commit;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `commit` field to Set
    pub struct SetCommit<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCommit<S> {}
    impl<S: State> State for SetCommit<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = Set<members::commit>;
        type Blocks = S::Blocks;
    }
    ///State transition - sets the `blocks` field to Set
    pub struct SetBlocks<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBlocks<S> {}
    impl<S: State> State for SetBlocks<S> {
        type Seq = S::Seq;
        type Ops = S::Ops;
        type TooBig = S::TooBig;
        type Rev = S::Rev;
        type Repo = S::Repo;
        type Time = S::Time;
        type Rebase = S::Rebase;
        type Blobs = S::Blobs;
        type Commit = S::Commit;
        type Blocks = Set<members::blocks>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `seq` field
        pub struct seq(());
        ///Marker type for the `ops` field
        pub struct ops(());
        ///Marker type for the `too_big` field
        pub struct too_big(());
        ///Marker type for the `rev` field
        pub struct rev(());
        ///Marker type for the `repo` field
        pub struct repo(());
        ///Marker type for the `time` field
        pub struct time(());
        ///Marker type for the `rebase` field
        pub struct rebase(());
        ///Marker type for the `blobs` field
        pub struct blobs(());
        ///Marker type for the `commit` field
        pub struct commit(());
        ///Marker type for the `blocks` field
        pub struct blocks(());
    }
}

/// Builder for constructing an instance of this type
pub struct CommitBuilder<'a, S: commit_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<CidLink<'a>>>,
        Option<Bytes>,
        Option<CidLink<'a>>,
        Option<Vec<subscribe_repos::RepoOp<'a>>>,
        Option<CidLink<'a>>,
        Option<bool>,
        Option<Did<'a>>,
        Option<Tid>,
        Option<i64>,
        Option<Tid>,
        Option<Datetime>,
        Option<bool>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

impl<'a, S: commit_state::State> CommitBuilder<'a, S> {
    /// Set the `prevData` field (optional)
    pub fn prev_data(mut self, value: impl Into<Option<CidLink<'a>>>) -> 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<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

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

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

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

impl<'a, S: commit_state::State> CommitBuilder<'a, 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<'a, S> CommitBuilder<'a, S>
where
    S: commit_state::State,
    S::Time: commit_state::IsUnset,
{
    /// Set the `time` field (required)
    pub fn time(
        mut self,
        value: impl Into<Datetime>,
    ) -> CommitBuilder<'a, commit_state::SetTime<S>> {
        self._fields.10 = Option::Some(value.into());
        CommitBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> CommitBuilder<'a, S>
where
    S: commit_state::State,
    S::Seq: commit_state::IsSet,
    S::Ops: commit_state::IsSet,
    S::TooBig: commit_state::IsSet,
    S::Rev: commit_state::IsSet,
    S::Repo: commit_state::IsSet,
    S::Time: commit_state::IsSet,
    S::Rebase: commit_state::IsSet,
    S::Blobs: commit_state::IsSet,
    S::Commit: commit_state::IsSet,
    S::Blocks: commit_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Commit<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Commit<'a> {
        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 Time;
        type Did;
        type Seq;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Time = Unset;
        type Did = Unset;
        type Seq = Unset;
    }
    ///State transition - sets the `time` field to Set
    pub struct SetTime<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTime<S> {}
    impl<S: State> State for SetTime<S> {
        type Time = Set<members::time>;
        type Did = S::Did;
        type Seq = S::Seq;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDid<S> {}
    impl<S: State> State for SetDid<S> {
        type Time = S::Time;
        type Did = Set<members::did>;
        type Seq = S::Seq;
    }
    ///State transition - sets the `seq` field to Set
    pub struct SetSeq<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSeq<S> {}
    impl<S: State> State for SetSeq<S> {
        type Time = S::Time;
        type Did = S::Did;
        type Seq = Set<members::seq>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `time` field
        pub struct time(());
        ///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 IdentityBuilder<'a, S: identity_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Did<'a>>, Option<Handle<'a>>, Option<i64>, Option<Datetime>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: identity_state::State> IdentityBuilder<'a, S> {
    /// Set the `handle` field (optional)
    pub fn handle(mut self, value: impl Into<Option<Handle<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<'a, S> IdentityBuilder<'a, S>
where
    S: identity_state::State,
    S::Time: identity_state::IsSet,
    S::Did: identity_state::IsSet,
    S::Seq: identity_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Identity<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Identity<'a> {
        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<S: subscribe_repos_state::State> {
    _state: PhantomData<fn() -> S>,
    _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
    pub fn new() -> Self {
        SubscribeReposBuilder {
            _state: PhantomData,
            _fields: (None,),
        }
    }
}

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

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

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

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

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

impl<'a, S: repo_op_state::State> RepoOpBuilder<'a, S> {
    /// Set the `cid` field (optional)
    pub fn cid(mut self, value: impl Into<Option<CidLink<'a>>>) -> 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<'a>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<'a, S: repo_op_state::State> RepoOpBuilder<'a, S> {
    /// Set the `prev` field (optional)
    pub fn prev(mut self, value: impl Into<Option<CidLink<'a>>>) -> 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<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> RepoOpBuilder<'a, S>
where
    S: repo_op_state::State,
    S::Path: repo_op_state::IsSet,
    S::Action: repo_op_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RepoOp<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> RepoOp<'a> {
        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 Did;
        type Seq;
        type Blocks;
        type Rev;
        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 Blocks = Unset;
        type Rev = Unset;
        type Time = Unset;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDid<S> {}
    impl<S: State> State for SetDid<S> {
        type Did = Set<members::did>;
        type Seq = S::Seq;
        type Blocks = S::Blocks;
        type Rev = S::Rev;
        type Time = S::Time;
    }
    ///State transition - sets the `seq` field to Set
    pub struct SetSeq<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetSeq<S> {}
    impl<S: State> State for SetSeq<S> {
        type Did = S::Did;
        type Seq = Set<members::seq>;
        type Blocks = S::Blocks;
        type Rev = S::Rev;
        type Time = S::Time;
    }
    ///State transition - sets the `blocks` field to Set
    pub struct SetBlocks<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBlocks<S> {}
    impl<S: State> State for SetBlocks<S> {
        type Did = S::Did;
        type Seq = S::Seq;
        type Blocks = Set<members::blocks>;
        type Rev = S::Rev;
        type Time = S::Time;
    }
    ///State transition - sets the `rev` field to Set
    pub struct SetRev<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRev<S> {}
    impl<S: State> State for SetRev<S> {
        type Did = S::Did;
        type Seq = S::Seq;
        type Blocks = S::Blocks;
        type Rev = Set<members::rev>;
        type Time = S::Time;
    }
    ///State transition - sets the `time` field to Set
    pub struct SetTime<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetTime<S> {}
    impl<S: State> State for SetTime<S> {
        type Did = S::Did;
        type Seq = S::Seq;
        type Blocks = S::Blocks;
        type Rev = S::Rev;
        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 `blocks` field
        pub struct blocks(());
        ///Marker type for the `rev` field
        pub struct rev(());
        ///Marker type for the `time` field
        pub struct time(());
    }
}

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

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

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

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

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

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

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

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

impl<'a, S> SyncBuilder<'a, S>
where
    S: sync_state::State,
    S::Did: sync_state::IsSet,
    S::Seq: sync_state::IsSet,
    S::Blocks: sync_state::IsSet,
    S::Rev: sync_state::IsSet,
    S::Time: sync_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Sync<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Sync<'a> {
        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),
        }
    }
}