// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.hosting.getAccountHistory
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

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

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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::{Did, Handle, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::tools_ozone::hosting::get_account_history;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct AccountCreated<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub email: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub handle: Option<Handle<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 EmailConfirmed<S: BosStr = DefaultStr> {
    pub email: 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 EmailUpdated<S: BosStr = DefaultStr> {
    pub email: 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 Event<S: BosStr = DefaultStr> {
    pub created_at: Datetime,
    pub created_by: S,
    pub details: EventDetails<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum EventDetails<S: BosStr = DefaultStr> {
    #[serde(rename = "tools.ozone.hosting.getAccountHistory#accountCreated")]
    AccountCreated(Box<get_account_history::AccountCreated<S>>),
    #[serde(rename = "tools.ozone.hosting.getAccountHistory#emailUpdated")]
    EmailUpdated(Box<get_account_history::EmailUpdated<S>>),
    #[serde(rename = "tools.ozone.hosting.getAccountHistory#emailConfirmed")]
    EmailConfirmed(Box<get_account_history::EmailConfirmed<S>>),
    #[serde(rename = "tools.ozone.hosting.getAccountHistory#passwordUpdated")]
    PasswordUpdated(Box<get_account_history::PasswordUpdated<S>>),
    #[serde(rename = "tools.ozone.hosting.getAccountHistory#handleUpdated")]
    HandleUpdated(Box<get_account_history::HandleUpdated<S>>),
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct HandleUpdated<S: BosStr = DefaultStr> {
    pub handle: Handle<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 GetAccountHistory<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub did: Did<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub events: Option<Vec<S>>,
    /// Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetAccountHistoryOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cursor: Option<S>,
    pub events: Vec<get_account_history::Event<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 PasswordUpdated<S: BosStr = DefaultStr> {
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for AccountCreated<S> {
    fn nsid() -> &'static str {
        "tools.ozone.hosting.getAccountHistory"
    }
    fn def_name() -> &'static str {
        "accountCreated"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_hosting_getAccountHistory()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for EmailConfirmed<S> {
    fn nsid() -> &'static str {
        "tools.ozone.hosting.getAccountHistory"
    }
    fn def_name() -> &'static str {
        "emailConfirmed"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_hosting_getAccountHistory()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for EmailUpdated<S> {
    fn nsid() -> &'static str {
        "tools.ozone.hosting.getAccountHistory"
    }
    fn def_name() -> &'static str {
        "emailUpdated"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_hosting_getAccountHistory()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Event<S> {
    fn nsid() -> &'static str {
        "tools.ozone.hosting.getAccountHistory"
    }
    fn def_name() -> &'static str {
        "event"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_hosting_getAccountHistory()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for HandleUpdated<S> {
    fn nsid() -> &'static str {
        "tools.ozone.hosting.getAccountHistory"
    }
    fn def_name() -> &'static str {
        "handleUpdated"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_hosting_getAccountHistory()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/** Response marker for the `tools.ozone.hosting.getAccountHistory` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `GetAccountHistoryOutput<S>` for this endpoint.*/
pub struct GetAccountHistoryResponse;
impl jacquard_common::xrpc::XrpcResp for GetAccountHistoryResponse {
    const NSID: &'static str = "tools.ozone.hosting.getAccountHistory";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = GetAccountHistoryOutput<S>;
    type Err = jacquard_common::xrpc::GenericError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for GetAccountHistory<S> {
    const NSID: &'static str = "tools.ozone.hosting.getAccountHistory";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetAccountHistoryResponse;
}

/** Endpoint marker for the `tools.ozone.hosting.getAccountHistory` query.

Path: `/xrpc/tools.ozone.hosting.getAccountHistory`. The request payload type is `GetAccountHistory<S>`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetAccountHistoryRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetAccountHistoryRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.hosting.getAccountHistory";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetAccountHistory<S>;
    type Response = GetAccountHistoryResponse;
}

impl<S: BosStr> LexiconSchema for PasswordUpdated<S> {
    fn nsid() -> &'static str {
        "tools.ozone.hosting.getAccountHistory"
    }
    fn def_name() -> &'static str {
        "passwordUpdated"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_hosting_getAccountHistory()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_tools_ozone_hosting_getAccountHistory() -> 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("tools.ozone.hosting.getAccountHistory"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("accountCreated"),
                LexUserType::Object(LexObject {
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("email"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Handle),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("emailConfirmed"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("email")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("email"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("emailUpdated"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("email")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("email"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("event"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("details"),
                            SmolStr::new_static("createdBy"),
                            SmolStr::new_static("createdAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdBy"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("details"),
                            LexObjectProperty::Union(LexRefUnion {
                                refs: vec![
                                    CowStr::new_static("#accountCreated"),
                                    CowStr::new_static("#emailUpdated"),
                                    CowStr::new_static("#emailConfirmed"),
                                    CowStr::new_static("#passwordUpdated"),
                                    CowStr::new_static("#handleUpdated")
                                ],
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("handleUpdated"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("handle")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Handle),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("did")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("did"),
                                    LexXrpcParametersProperty::String(LexString {
                                        format: Some(LexStringFormat::Did),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("events"),
                                    LexXrpcParametersProperty::Array(LexPrimitiveArray {
                                        items: LexPrimitiveArrayItem::String(LexString {
                                            ..Default::default()
                                        }),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("passwordUpdated"),
                LexUserType::Object(LexObject {
                    required: Some(vec![]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod event_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 CreatedAt;
        type CreatedBy;
        type Details;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type CreatedBy = Unset;
        type Details = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type CreatedBy = St::CreatedBy;
        type Details = St::Details;
    }
    ///State transition - sets the `created_by` field to Set
    pub struct SetCreatedBy<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedBy<St> {}
    impl<St: State> State for SetCreatedBy<St> {
        type CreatedAt = St::CreatedAt;
        type CreatedBy = Set<members::created_by>;
        type Details = St::Details;
    }
    ///State transition - sets the `details` field to Set
    pub struct SetDetails<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDetails<St> {}
    impl<St: State> State for SetDetails<St> {
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Details = Set<members::details>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `created_by` field
        pub struct created_by(());
        ///Marker type for the `details` field
        pub struct details(());
    }
}

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

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

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

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

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

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::CreatedAt: event_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> EventBuilder<event_state::SetCreatedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::CreatedBy: event_state::IsUnset,
{
    /// Set the `createdBy` field (required)
    pub fn created_by(
        mut self,
        value: impl Into<S>,
    ) -> EventBuilder<event_state::SetCreatedBy<St>, S> {
        self._fields.1 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::Details: event_state::IsUnset,
{
    /// Set the `details` field (required)
    pub fn details(
        mut self,
        value: impl Into<EventDetails<S>>,
    ) -> EventBuilder<event_state::SetDetails<St>, S> {
        self._fields.2 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::CreatedAt: event_state::IsSet,
    St::CreatedBy: event_state::IsSet,
    St::Details: event_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Event<S> {
        Event {
            created_at: self._fields.0.unwrap(),
            created_by: self._fields.1.unwrap(),
            details: 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>>) -> Event<S> {
        Event {
            created_at: self._fields.0.unwrap(),
            created_by: self._fields.1.unwrap(),
            details: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

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

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

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

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

impl<St, S: BosStr> HandleUpdatedBuilder<St, S>
where
    St: handle_updated_state::State,
    St::Handle: handle_updated_state::IsUnset,
{
    /// Set the `handle` field (required)
    pub fn handle(
        mut self,
        value: impl Into<Handle<S>>,
    ) -> HandleUpdatedBuilder<handle_updated_state::SetHandle<St>, S> {
        self._fields.0 = Option::Some(value.into());
        HandleUpdatedBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> HandleUpdatedBuilder<St, S>
where
    St: handle_updated_state::State,
    St::Handle: handle_updated_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> HandleUpdated<S> {
        HandleUpdated {
            handle: self._fields.0.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>>,
    ) -> HandleUpdated<S> {
        HandleUpdated {
            handle: self._fields.0.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn _default_limit() -> Option<i64> {
    Some(50i64)
}

pub mod get_account_history_state {

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

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

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

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

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

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

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

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

impl<St: get_account_history_state::State, S: BosStr> GetAccountHistoryBuilder<St, S> {
    /// Set the `events` field (optional)
    pub fn events(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `events` field to an Option value (optional)
    pub fn maybe_events(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St: get_account_history_state::State, S: BosStr> GetAccountHistoryBuilder<St, S> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> GetAccountHistoryBuilder<St, S>
where
    St: get_account_history_state::State,
    St::Did: get_account_history_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> GetAccountHistory<S> {
        GetAccountHistory {
            cursor: self._fields.0,
            did: self._fields.1.unwrap(),
            events: self._fields.2,
            limit: self._fields.3,
        }
    }
}