// @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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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, 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::repo::CommitMeta;
use crate::com_atproto::repo::apply_writes;
/// Operation which creates a new record.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Create<'a> {
    #[serde(borrow)]
    pub collection: Nsid<'a>,
    ///NOTE: maxLength is redundant with record-key format. Keeping it temporarily to ensure backwards compatibility.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub rkey: Option<RecordKey<Rkey<'a>>>,
    #[serde(borrow)]
    pub value: Data<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CreateResult<'a> {
    #[serde(borrow)]
    pub cid: Cid<'a>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub validation_status: Option<CreateResultValidationStatus<'a>>,
}


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

impl<'a> CreateResultValidationStatus<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Valid => "valid",
            Self::Unknown => "unknown",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for CreateResultValidationStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "valid" => Self::Valid,
            "unknown" => Self::Unknown,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for CreateResultValidationStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "valid" => Self::Valid,
            "unknown" => Self::Unknown,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Delete<'a> {
    #[serde(borrow)]
    pub collection: Nsid<'a>,
    #[serde(borrow)]
    pub rkey: RecordKey<Rkey<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct DeleteResult<'a> {}

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ApplyWrites<'a> {
    ///The handle or DID of the repo (aka, current account).
    #[serde(borrow)]
    pub repo: AtIdentifier<'a>,
    ///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")]
    #[serde(borrow)]
    pub swap_commit: Option<Cid<'a>>,
    ///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>,
    #[serde(borrow)]
    pub writes: Vec<ApplyWritesWritesItem<'a>>,
}


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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ApplyWritesOutput<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub commit: Option<CommitMeta<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub results: Option<Vec<ApplyWritesOutputResultsItem<'a>>>,
}


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


#[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 ApplyWritesError<'a> {
    /// Indicates that the 'swapCommit' parameter did not match current commit.
    #[serde(rename = "InvalidSwap")]
    InvalidSwap(Option<CowStr<'a>>),
}

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

/// Operation which updates an existing record.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Update<'a> {
    #[serde(borrow)]
    pub collection: Nsid<'a>,
    #[serde(borrow)]
    pub rkey: RecordKey<Rkey<'a>>,
    #[serde(borrow)]
    pub value: Data<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UpdateResult<'a> {
    #[serde(borrow)]
    pub cid: Cid<'a>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub validation_status: Option<UpdateResultValidationStatus<'a>>,
}


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

impl<'a> UpdateResultValidationStatus<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Valid => "valid",
            Self::Unknown => "unknown",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for UpdateResultValidationStatus<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "valid" => Self::Valid,
            "unknown" => Self::Unknown,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for UpdateResultValidationStatus<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "valid" => Self::Valid,
            "unknown" => Self::Unknown,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

impl jacquard_common::IntoStatic for UpdateResultValidationStatus<'_> {
    type Output = UpdateResultValidationStatus<'static>;
    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<'a> LexiconSchema for Create<'a> {
    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<'a> LexiconSchema for CreateResult<'a> {
    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<'a> LexiconSchema for Delete<'a> {
    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<'a> LexiconSchema for DeleteResult<'a> {
    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 type for com.atproto.repo.applyWrites
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<'de> = ApplyWritesOutput<'de>;
    type Err<'de> = ApplyWritesError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for ApplyWrites<'a> {
    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 type for com.atproto.repo.applyWrites
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<'de> = ApplyWrites<'de>;
    type Response = ApplyWritesResponse;
}

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

/// Builder for constructing an instance of this type
pub struct CreateBuilder<'a, S: create_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Nsid<'a>>, Option<RecordKey<Rkey<'a>>>, Option<Data<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> CreateBuilder<'a, S>
where
    S: create_state::State,
    S::Value: create_state::IsSet,
    S::Collection: create_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Create<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Create<'a> {
        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 Uri;
        type Cid;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
        type Cid = Unset;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Uri = Set<members::uri>;
        type Cid = S::Cid;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCid<S> {}
    impl<S: State> State for SetCid<S> {
        type Uri = S::Uri;
        type Cid = Set<members::cid>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `cid` field
        pub struct cid(());
    }
}

/// Builder for constructing an instance of this type
pub struct CreateResultBuilder<'a, S: create_result_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Cid<'a>>,
        Option<AtUri<'a>>,
        Option<CreateResultValidationStatus<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: create_result_state::State> CreateResultBuilder<'a, S> {
    /// Set the `validationStatus` field (optional)
    pub fn validation_status(
        mut self,
        value: impl Into<Option<CreateResultValidationStatus<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> CreateResultBuilder<'a, S>
where
    S: create_result_state::State,
    S::Uri: create_result_state::IsSet,
    S::Cid: create_result_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> CreateResult<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> CreateResult<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCollection<S> {}
    impl<S: State> State for SetCollection<S> {
        type Collection = Set<members::collection>;
        type Rkey = S::Rkey;
    }
    ///State transition - sets the `rkey` field to Set
    pub struct SetRkey<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRkey<S> {}
    impl<S: State> State for SetRkey<S> {
        type Collection = S::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<'a, S: delete_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Nsid<'a>>, Option<RecordKey<Rkey<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> DeleteBuilder<'a, S>
where
    S: delete_state::State,
    S::Collection: delete_state::IsSet,
    S::Rkey: delete_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Delete<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Delete<'a> {
        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 Writes;
        type Repo;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Writes = Unset;
        type Repo = Unset;
    }
    ///State transition - sets the `writes` field to Set
    pub struct SetWrites<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetWrites<S> {}
    impl<S: State> State for SetWrites<S> {
        type Writes = Set<members::writes>;
        type Repo = S::Repo;
    }
    ///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 Writes = S::Writes;
        type Repo = Set<members::repo>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `writes` field
        pub struct writes(());
        ///Marker type for the `repo` field
        pub struct repo(());
    }
}

/// Builder for constructing an instance of this type
pub struct ApplyWritesBuilder<'a, S: apply_writes_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<AtIdentifier<'a>>,
        Option<Cid<'a>>,
        Option<bool>,
        Option<Vec<ApplyWritesWritesItem<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: apply_writes_state::State> ApplyWritesBuilder<'a, 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<'a, S> ApplyWritesBuilder<'a, S>
where
    S: apply_writes_state::State,
    S::Writes: apply_writes_state::IsUnset,
{
    /// Set the `writes` field (required)
    pub fn writes(
        mut self,
        value: impl Into<Vec<ApplyWritesWritesItem<'a>>>,
    ) -> ApplyWritesBuilder<'a, apply_writes_state::SetWrites<S>> {
        self._fields.3 = Option::Some(value.into());
        ApplyWritesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> ApplyWritesBuilder<'a, S>
where
    S: apply_writes_state::State,
    S::Writes: apply_writes_state::IsSet,
    S::Repo: apply_writes_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> ApplyWrites<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> ApplyWrites<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCollection<S> {}
    impl<S: State> State for SetCollection<S> {
        type Collection = Set<members::collection>;
        type Rkey = S::Rkey;
        type Value = S::Value;
    }
    ///State transition - sets the `rkey` field to Set
    pub struct SetRkey<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRkey<S> {}
    impl<S: State> State for SetRkey<S> {
        type Collection = S::Collection;
        type Rkey = Set<members::rkey>;
        type Value = S::Value;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetValue<S> {}
    impl<S: State> State for SetValue<S> {
        type Collection = S::Collection;
        type Rkey = S::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<'a, S: update_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Nsid<'a>>, Option<RecordKey<Rkey<'a>>>, Option<Data<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> UpdateBuilder<'a, S>
where
    S: update_state::State,
    S::Collection: update_state::IsSet,
    S::Rkey: update_state::IsSet,
    S::Value: update_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Update<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Update<'a> {
        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 Uri;
        type Cid;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Uri = Unset;
        type Cid = Unset;
    }
    ///State transition - sets the `uri` field to Set
    pub struct SetUri<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUri<S> {}
    impl<S: State> State for SetUri<S> {
        type Uri = Set<members::uri>;
        type Cid = S::Cid;
    }
    ///State transition - sets the `cid` field to Set
    pub struct SetCid<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCid<S> {}
    impl<S: State> State for SetCid<S> {
        type Uri = S::Uri;
        type Cid = Set<members::cid>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `uri` field
        pub struct uri(());
        ///Marker type for the `cid` field
        pub struct cid(());
    }
}

/// Builder for constructing an instance of this type
pub struct UpdateResultBuilder<'a, S: update_result_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Cid<'a>>,
        Option<AtUri<'a>>,
        Option<UpdateResultValidationStatus<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S: update_result_state::State> UpdateResultBuilder<'a, S> {
    /// Set the `validationStatus` field (optional)
    pub fn validation_status(
        mut self,
        value: impl Into<Option<UpdateResultValidationStatus<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> UpdateResultBuilder<'a, S>
where
    S: update_result_state::State,
    S::Uri: update_result_state::IsSet,
    S::Cid: update_result_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> UpdateResult<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> UpdateResult<'a> {
        UpdateResult {
            cid: self._fields.0.unwrap(),
            uri: self._fields.1.unwrap(),
            validation_status: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}