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

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::ident::AtIdentifier;
use jacquard_common::types::string::{AtUri, Nsid, Cid, RecordKey, Rkey};
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::repo::CommitMeta;
use crate::com_atproto::repo::apply_writes;
/// Operation which creates a new record.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Create<S: BosStr = DefaultStr> {
    pub collection: Nsid<S>,
    ///NOTE: maxLength is redundant with record-key format. Keeping it temporarily to ensure backwards compatibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rkey: Option<RecordKey<Rkey<S>>>,
    pub value: Data<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateResult<S: BosStr = DefaultStr> {
    pub cid: Cid<S>,
    pub uri: AtUri<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub validation_status: Option<CreateResultValidationStatus<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 CreateResultValidationStatus<S: BosStr = DefaultStr> {
    Valid,
    Unknown,
    Other(S),
}

impl<S: BosStr> CreateResultValidationStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Valid => "valid",
            Self::Unknown => "unknown",
            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() {
            "valid" => Self::Valid,
            "unknown" => Self::Unknown,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for CreateResultValidationStatus<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 CreateResultValidationStatus<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 CreateResultValidationStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

/// Operation which deletes an existing record.

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


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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ApplyWrites<S: BosStr = DefaultStr> {
    ///The handle or DID of the repo (aka, current account).
    pub repo: AtIdentifier<S>,
    ///If provided, the entire operation will fail if the current repo commit CID does not match this value. Used to prevent conflicting repo mutations.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub swap_commit: Option<Cid<S>>,
    ///Can be set to 'false' to skip Lexicon schema validation of record data across all operations, 'true' to require it, or leave unset to validate only for known Lexicons.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub validate: Option<bool>,
    pub writes: Vec<ApplyWritesWritesItem<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum ApplyWritesWritesItem<S: BosStr = DefaultStr> {
    #[serde(rename = "com.atproto.repo.applyWrites#create")]
    Create(Box<apply_writes::Create<S>>),
    #[serde(rename = "com.atproto.repo.applyWrites#update")]
    Update(Box<apply_writes::Update<S>>),
    #[serde(rename = "com.atproto.repo.applyWrites#delete")]
    Delete(Box<apply_writes::Delete<S>>),
}


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


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum ApplyWritesOutputResultsItem<S: BosStr = DefaultStr> {
    #[serde(rename = "com.atproto.repo.applyWrites#createResult")]
    CreateResult(Box<apply_writes::CreateResult<S>>),
    #[serde(rename = "com.atproto.repo.applyWrites#updateResult")]
    UpdateResult(Box<apply_writes::UpdateResult<S>>),
    #[serde(rename = "com.atproto.repo.applyWrites#deleteResult")]
    DeleteResult(Box<apply_writes::DeleteResult<S>>),
}


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

#[serde(tag = "error", content = "message")]
pub enum ApplyWritesError {
    /// Indicates that the 'swapCommit' parameter did not match current commit.
    #[serde(rename = "InvalidSwap")]
    InvalidSwap(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for ApplyWritesError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::InvalidSwap(msg) => {
                write!(f, "InvalidSwap")?;
                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(())
            }
        }
    }
}

/// Operation which updates an existing record.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Update<S: BosStr = DefaultStr> {
    pub collection: Nsid<S>,
    pub rkey: RecordKey<Rkey<S>>,
    pub value: Data<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UpdateResult<S: BosStr = DefaultStr> {
    pub cid: Cid<S>,
    pub uri: AtUri<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub validation_status: Option<UpdateResultValidationStatus<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 UpdateResultValidationStatus<S: BosStr = DefaultStr> {
    Valid,
    Unknown,
    Other(S),
}

impl<S: BosStr> UpdateResultValidationStatus<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Valid => "valid",
            Self::Unknown => "unknown",
            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() {
            "valid" => Self::Valid,
            "unknown" => Self::Unknown,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for UpdateResultValidationStatus<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 UpdateResultValidationStatus<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 UpdateResultValidationStatus<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

impl<S: BosStr> LexiconSchema for Create<S> {
    fn nsid() -> &'static str {
        "com.atproto.repo.applyWrites"
    }
    fn def_name() -> &'static str {
        "create"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_applyWrites()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.rkey {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 512usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("rkey"),
                    max: 512usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for CreateResult<S> {
    fn nsid() -> &'static str {
        "com.atproto.repo.applyWrites"
    }
    fn def_name() -> &'static str {
        "createResult"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_applyWrites()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Delete<S> {
    fn nsid() -> &'static str {
        "com.atproto.repo.applyWrites"
    }
    fn def_name() -> &'static str {
        "delete"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_applyWrites()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for DeleteResult<S> {
    fn nsid() -> &'static str {
        "com.atproto.repo.applyWrites"
    }
    fn def_name() -> &'static str {
        "deleteResult"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_applyWrites()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `com.atproto.repo.applyWrites` procedure.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ApplyWritesOutput<S>` for this endpoint.*/
pub struct ApplyWritesResponse;
impl jacquard_common::xrpc::XrpcResp for ApplyWritesResponse {
    const NSID: &'static str = "com.atproto.repo.applyWrites";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ApplyWritesOutput<S>;
    type Err = ApplyWritesError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for ApplyWrites<S> {
    const NSID: &'static str = "com.atproto.repo.applyWrites";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = ApplyWritesResponse;
}

/** Endpoint marker for the `com.atproto.repo.applyWrites` procedure.

Path: `/xrpc/com.atproto.repo.applyWrites`. The request payload type is `ApplyWrites<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct ApplyWritesRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ApplyWritesRequest {
    const PATH: &'static str = "/xrpc/com.atproto.repo.applyWrites";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<S: BosStr> = ApplyWrites<S>;
    type Response = ApplyWritesResponse;
}

impl<S: BosStr> LexiconSchema for Update<S> {
    fn nsid() -> &'static str {
        "com.atproto.repo.applyWrites"
    }
    fn def_name() -> &'static str {
        "update"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_applyWrites()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for UpdateResult<S> {
    fn nsid() -> &'static str {
        "com.atproto.repo.applyWrites"
    }
    fn def_name() -> &'static str {
        "updateResult"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_repo_applyWrites()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

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

/// Builder for constructing an instance of this type.
pub struct CreateBuilder<St: create_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Nsid<S>>, Option<RecordKey<Rkey<S>>>, Option<Data<S>>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St, S: BosStr> CreateBuilder<St, S>
where
    St: create_state::State,
    St::Collection: create_state::IsUnset,
{
    /// Set the `collection` field (required)
    pub fn collection(
        mut self,
        value: impl Into<Nsid<S>>,
    ) -> CreateBuilder<create_state::SetCollection<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CreateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: create_state::State, S: BosStr> CreateBuilder<St, S> {
    /// Set the `rkey` field (optional)
    pub fn rkey(mut self, value: impl Into<Option<RecordKey<Rkey<S>>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `rkey` field to an Option value (optional)
    pub fn maybe_rkey(mut self, value: Option<RecordKey<Rkey<S>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> CreateBuilder<St, S>
where
    St: create_state::State,
    St::Value: create_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<Data<S>>,
    ) -> CreateBuilder<create_state::SetValue<St>, S> {
        self._fields.2 = Option::Some(value.into());
        CreateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreateBuilder<St, S>
where
    St: create_state::State,
    St::Collection: create_state::IsSet,
    St::Value: create_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Create<S> {
        Create {
            collection: self._fields.0.unwrap(),
            rkey: self._fields.1,
            value: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Create<S> {
        Create {
            collection: self._fields.0.unwrap(),
            rkey: self._fields.1,
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_repo_applyWrites() -> 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.repo.applyWrites"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("create"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Operation which creates a new record."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("collection"),
                            SmolStr::new_static("value")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("collection"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rkey"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "NOTE: maxLength is redundant with record-key format. Keeping it temporarily to ensure backwards compatibility.",
                                    ),
                                ),
                                format: Some(LexStringFormat::RecordKey),
                                max_length: Some(512usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("createResult"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("cid")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("validationStatus"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("delete"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Operation which deletes an existing record."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("collection"),
                            SmolStr::new_static("rkey")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("collection"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rkey"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::RecordKey),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("deleteResult"),
                LexUserType::Object(LexObject {
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcProcedure(LexXrpcProcedure {
                    input: Some(LexXrpcBody {
                        encoding: CowStr::new_static("application/json"),
                        schema: Some(
                            LexXrpcBodySchema::Object(LexObject {
                                required: Some(
                                    vec![
                                        SmolStr::new_static("repo"), SmolStr::new_static("writes")
                                    ],
                                ),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("repo"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static(
                                                    "The handle or DID of the repo (aka, current account).",
                                                ),
                                            ),
                                            format: Some(LexStringFormat::AtIdentifier),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("swapCommit"),
                                        LexObjectProperty::String(LexString {
                                            description: Some(
                                                CowStr::new_static(
                                                    "If provided, the entire operation will fail if the current repo commit CID does not match this value. Used to prevent conflicting repo mutations.",
                                                ),
                                            ),
                                            format: Some(LexStringFormat::Cid),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("validate"),
                                        LexObjectProperty::Boolean(LexBoolean {
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("writes"),
                                        LexObjectProperty::Array(LexArray {
                                            items: LexArrayItem::Union(LexRefUnion {
                                                refs: vec![
                                                    CowStr::new_static("#create"),
                                                    CowStr::new_static("#update"), CowStr::new_static("#delete")
                                                ],
                                                closed: Some(true),
                                                ..Default::default()
                                            }),
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("update"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Operation which updates an existing record."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("collection"),
                            SmolStr::new_static("rkey"), SmolStr::new_static("value")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("collection"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rkey"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::RecordKey),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("updateResult"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("uri"), SmolStr::new_static("cid")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cid"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Cid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uri"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::AtUri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("validationStatus"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

impl<S: BosStr> CreateResult<S> {
    /// Create a new builder for this type
    pub fn builder() -> CreateResultBuilder<create_result_state::Empty, S> {
        CreateResultBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> CreateResultBuilder<St, S>
where
    St: create_result_state::State,
    St::Cid: create_result_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> CreateResultBuilder<create_result_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CreateResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreateResultBuilder<St, S>
where
    St: create_result_state::State,
    St::Uri: create_result_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> CreateResultBuilder<create_result_state::SetUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        CreateResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: create_result_state::State, S: BosStr> CreateResultBuilder<St, S> {
    /// Set the `validationStatus` field (optional)
    pub fn validation_status(
        mut self,
        value: impl Into<Option<CreateResultValidationStatus<S>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `validationStatus` field to an Option value (optional)
    pub fn maybe_validation_status(
        mut self,
        value: Option<CreateResultValidationStatus<S>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> CreateResultBuilder<St, S>
where
    St: create_result_state::State,
    St::Cid: create_result_state::IsSet,
    St::Uri: create_result_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CreateResult<S> {
        CreateResult {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            validation_status: self._fields.2,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> CreateResult<S> {
        CreateResult {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            validation_status: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> Delete<S> {
    /// Create a new builder for this type
    pub fn builder() -> DeleteBuilder<delete_state::Empty, S> {
        DeleteBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> DeleteBuilder<St, S>
where
    St: delete_state::State,
    St::Collection: delete_state::IsUnset,
{
    /// Set the `collection` field (required)
    pub fn collection(
        mut self,
        value: impl Into<Nsid<S>>,
    ) -> DeleteBuilder<delete_state::SetCollection<St>, S> {
        self._fields.0 = Option::Some(value.into());
        DeleteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DeleteBuilder<St, S>
where
    St: delete_state::State,
    St::Rkey: delete_state::IsUnset,
{
    /// Set the `rkey` field (required)
    pub fn rkey(
        mut self,
        value: impl Into<RecordKey<Rkey<S>>>,
    ) -> DeleteBuilder<delete_state::SetRkey<St>, S> {
        self._fields.1 = Option::Some(value.into());
        DeleteBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DeleteBuilder<St, S>
where
    St: delete_state::State,
    St::Collection: delete_state::IsSet,
    St::Rkey: delete_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Delete<S> {
        Delete {
            collection: self._fields.0.unwrap(),
            rkey: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Delete<S> {
        Delete {
            collection: self._fields.0.unwrap(),
            rkey: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod apply_writes_state {

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

/// Builder for constructing an instance of this type.
pub struct ApplyWritesBuilder<St: apply_writes_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<AtIdentifier<S>>,
        Option<Cid<S>>,
        Option<bool>,
        Option<Vec<ApplyWritesWritesItem<S>>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> ApplyWrites<S> {
    /// Create a new builder for this type
    pub fn builder() -> ApplyWritesBuilder<apply_writes_state::Empty, S> {
        ApplyWritesBuilder::builder()
    }
}

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

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

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

impl<St: apply_writes_state::State, S: BosStr> ApplyWritesBuilder<St, S> {
    /// Set the `swapCommit` field (optional)
    pub fn swap_commit(mut self, value: impl Into<Option<Cid<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `swapCommit` field to an Option value (optional)
    pub fn maybe_swap_commit(mut self, value: Option<Cid<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: apply_writes_state::State, S: BosStr> ApplyWritesBuilder<St, S> {
    /// Set the `validate` field (optional)
    pub fn validate(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `validate` field to an Option value (optional)
    pub fn maybe_validate(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> ApplyWritesBuilder<St, S>
where
    St: apply_writes_state::State,
    St::Writes: apply_writes_state::IsUnset,
{
    /// Set the `writes` field (required)
    pub fn writes(
        mut self,
        value: impl Into<Vec<ApplyWritesWritesItem<S>>>,
    ) -> ApplyWritesBuilder<apply_writes_state::SetWrites<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ApplyWritesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ApplyWritesBuilder<St, S>
where
    St: apply_writes_state::State,
    St::Repo: apply_writes_state::IsSet,
    St::Writes: apply_writes_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ApplyWrites<S> {
        ApplyWrites {
            repo: self._fields.0.unwrap(),
            swap_commit: self._fields.1,
            validate: self._fields.2,
            writes: 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>>,
    ) -> ApplyWrites<S> {
        ApplyWrites {
            repo: self._fields.0.unwrap(),
            swap_commit: self._fields.1,
            validate: self._fields.2,
            writes: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod update_state {

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

/// Builder for constructing an instance of this type.
pub struct UpdateBuilder<St: update_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Nsid<S>>, Option<RecordKey<Rkey<S>>>, Option<Data<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Update<S> {
    /// Create a new builder for this type
    pub fn builder() -> UpdateBuilder<update_state::Empty, S> {
        UpdateBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> UpdateBuilder<St, S>
where
    St: update_state::State,
    St::Collection: update_state::IsUnset,
{
    /// Set the `collection` field (required)
    pub fn collection(
        mut self,
        value: impl Into<Nsid<S>>,
    ) -> UpdateBuilder<update_state::SetCollection<St>, S> {
        self._fields.0 = Option::Some(value.into());
        UpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UpdateBuilder<St, S>
where
    St: update_state::State,
    St::Rkey: update_state::IsUnset,
{
    /// Set the `rkey` field (required)
    pub fn rkey(
        mut self,
        value: impl Into<RecordKey<Rkey<S>>>,
    ) -> UpdateBuilder<update_state::SetRkey<St>, S> {
        self._fields.1 = Option::Some(value.into());
        UpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UpdateBuilder<St, S>
where
    St: update_state::State,
    St::Value: update_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<Data<S>>,
    ) -> UpdateBuilder<update_state::SetValue<St>, S> {
        self._fields.2 = Option::Some(value.into());
        UpdateBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UpdateBuilder<St, S>
where
    St: update_state::State,
    St::Collection: update_state::IsSet,
    St::Rkey: update_state::IsSet,
    St::Value: update_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Update<S> {
        Update {
            collection: self._fields.0.unwrap(),
            rkey: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Update<S> {
        Update {
            collection: self._fields.0.unwrap(),
            rkey: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

impl<S: BosStr> UpdateResult<S> {
    /// Create a new builder for this type
    pub fn builder() -> UpdateResultBuilder<update_result_state::Empty, S> {
        UpdateResultBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> UpdateResultBuilder<St, S>
where
    St: update_result_state::State,
    St::Cid: update_result_state::IsUnset,
{
    /// Set the `cid` field (required)
    pub fn cid(
        mut self,
        value: impl Into<Cid<S>>,
    ) -> UpdateResultBuilder<update_result_state::SetCid<St>, S> {
        self._fields.0 = Option::Some(value.into());
        UpdateResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UpdateResultBuilder<St, S>
where
    St: update_result_state::State,
    St::Uri: update_result_state::IsUnset,
{
    /// Set the `uri` field (required)
    pub fn uri(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> UpdateResultBuilder<update_result_state::SetUri<St>, S> {
        self._fields.1 = Option::Some(value.into());
        UpdateResultBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: update_result_state::State, S: BosStr> UpdateResultBuilder<St, S> {
    /// Set the `validationStatus` field (optional)
    pub fn validation_status(
        mut self,
        value: impl Into<Option<UpdateResultValidationStatus<S>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `validationStatus` field to an Option value (optional)
    pub fn maybe_validation_status(
        mut self,
        value: Option<UpdateResultValidationStatus<S>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> UpdateResultBuilder<St, S>
where
    St: update_result_state::State,
    St::Cid: update_result_state::IsSet,
    St::Uri: update_result_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> UpdateResult<S> {
        UpdateResult {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            validation_status: self._fields.2,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> UpdateResult<S> {
        UpdateResult {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            validation_status: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}