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

//! Generated bindings for the `com.atproto.server` Lexicon namespace/module.
pub mod activate_account;
pub mod check_account_status;
pub mod confirm_email;
pub mod create_account;
pub mod create_app_password;
pub mod create_invite_code;
pub mod create_invite_codes;
pub mod create_session;
pub mod deactivate_account;
pub mod delete_account;
pub mod delete_session;
pub mod describe_server;
pub mod get_account_invite_codes;
pub mod get_service_auth;
pub mod get_session;
pub mod list_app_passwords;
pub mod refresh_session;
pub mod request_account_delete;
pub mod request_email_confirmation;
pub mod request_email_update;
pub mod request_password_reset;
pub mod reserve_signing_key;
pub mod reset_password;
pub mod revoke_app_password;
pub mod update_email;


#[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, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
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::server;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct InviteCode<S: BosStr = DefaultStr> {
    pub available: i64,
    pub code: S,
    pub created_at: Datetime,
    pub created_by: S,
    pub disabled: bool,
    pub for_account: S,
    pub uses: Vec<server::InviteCodeUse<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 InviteCodeUse<S: BosStr = DefaultStr> {
    pub used_at: Datetime,
    pub used_by: Did<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for InviteCode<S> {
    fn nsid() -> &'static str {
        "com.atproto.server.defs"
    }
    fn def_name() -> &'static str {
        "inviteCode"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_server_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for InviteCodeUse<S> {
    fn nsid() -> &'static str {
        "com.atproto.server.defs"
    }
    fn def_name() -> &'static str {
        "inviteCodeUse"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_server_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod invite_code_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 Available;
        type Code;
        type CreatedAt;
        type CreatedBy;
        type Disabled;
        type ForAccount;
        type Uses;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Available = Unset;
        type Code = Unset;
        type CreatedAt = Unset;
        type CreatedBy = Unset;
        type Disabled = Unset;
        type ForAccount = Unset;
        type Uses = Unset;
    }
    ///State transition - sets the `available` field to Set
    pub struct SetAvailable<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAvailable<St> {}
    impl<St: State> State for SetAvailable<St> {
        type Available = Set<members::available>;
        type Code = St::Code;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Disabled = St::Disabled;
        type ForAccount = St::ForAccount;
        type Uses = St::Uses;
    }
    ///State transition - sets the `code` field to Set
    pub struct SetCode<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCode<St> {}
    impl<St: State> State for SetCode<St> {
        type Available = St::Available;
        type Code = Set<members::code>;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Disabled = St::Disabled;
        type ForAccount = St::ForAccount;
        type Uses = St::Uses;
    }
    ///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 Available = St::Available;
        type Code = St::Code;
        type CreatedAt = Set<members::created_at>;
        type CreatedBy = St::CreatedBy;
        type Disabled = St::Disabled;
        type ForAccount = St::ForAccount;
        type Uses = St::Uses;
    }
    ///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 Available = St::Available;
        type Code = St::Code;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = Set<members::created_by>;
        type Disabled = St::Disabled;
        type ForAccount = St::ForAccount;
        type Uses = St::Uses;
    }
    ///State transition - sets the `disabled` field to Set
    pub struct SetDisabled<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDisabled<St> {}
    impl<St: State> State for SetDisabled<St> {
        type Available = St::Available;
        type Code = St::Code;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Disabled = Set<members::disabled>;
        type ForAccount = St::ForAccount;
        type Uses = St::Uses;
    }
    ///State transition - sets the `for_account` field to Set
    pub struct SetForAccount<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetForAccount<St> {}
    impl<St: State> State for SetForAccount<St> {
        type Available = St::Available;
        type Code = St::Code;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Disabled = St::Disabled;
        type ForAccount = Set<members::for_account>;
        type Uses = St::Uses;
    }
    ///State transition - sets the `uses` field to Set
    pub struct SetUses<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUses<St> {}
    impl<St: State> State for SetUses<St> {
        type Available = St::Available;
        type Code = St::Code;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Disabled = St::Disabled;
        type ForAccount = St::ForAccount;
        type Uses = Set<members::uses>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `available` field
        pub struct available(());
        ///Marker type for the `code` field
        pub struct code(());
        ///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 `disabled` field
        pub struct disabled(());
        ///Marker type for the `for_account` field
        pub struct for_account(());
        ///Marker type for the `uses` field
        pub struct uses(());
    }
}

/// Builder for constructing an instance of this type.
pub struct InviteCodeBuilder<St: invite_code_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<i64>,
        Option<S>,
        Option<Datetime>,
        Option<S>,
        Option<bool>,
        Option<S>,
        Option<Vec<server::InviteCodeUse<S>>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

impl<St, S: BosStr> InviteCodeBuilder<St, S>
where
    St: invite_code_state::State,
    St::Available: invite_code_state::IsUnset,
{
    /// Set the `available` field (required)
    pub fn available(
        mut self,
        value: impl Into<i64>,
    ) -> InviteCodeBuilder<invite_code_state::SetAvailable<St>, S> {
        self._fields.0 = Option::Some(value.into());
        InviteCodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> InviteCodeBuilder<St, S>
where
    St: invite_code_state::State,
    St::Code: invite_code_state::IsUnset,
{
    /// Set the `code` field (required)
    pub fn code(
        mut self,
        value: impl Into<S>,
    ) -> InviteCodeBuilder<invite_code_state::SetCode<St>, S> {
        self._fields.1 = Option::Some(value.into());
        InviteCodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St, S: BosStr> InviteCodeBuilder<St, S>
where
    St: invite_code_state::State,
    St::Disabled: invite_code_state::IsUnset,
{
    /// Set the `disabled` field (required)
    pub fn disabled(
        mut self,
        value: impl Into<bool>,
    ) -> InviteCodeBuilder<invite_code_state::SetDisabled<St>, S> {
        self._fields.4 = Option::Some(value.into());
        InviteCodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> InviteCodeBuilder<St, S>
where
    St: invite_code_state::State,
    St::ForAccount: invite_code_state::IsUnset,
{
    /// Set the `forAccount` field (required)
    pub fn for_account(
        mut self,
        value: impl Into<S>,
    ) -> InviteCodeBuilder<invite_code_state::SetForAccount<St>, S> {
        self._fields.5 = Option::Some(value.into());
        InviteCodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> InviteCodeBuilder<St, S>
where
    St: invite_code_state::State,
    St::Uses: invite_code_state::IsUnset,
{
    /// Set the `uses` field (required)
    pub fn uses(
        mut self,
        value: impl Into<Vec<server::InviteCodeUse<S>>>,
    ) -> InviteCodeBuilder<invite_code_state::SetUses<St>, S> {
        self._fields.6 = Option::Some(value.into());
        InviteCodeBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> InviteCodeBuilder<St, S>
where
    St: invite_code_state::State,
    St::Available: invite_code_state::IsSet,
    St::Code: invite_code_state::IsSet,
    St::CreatedAt: invite_code_state::IsSet,
    St::CreatedBy: invite_code_state::IsSet,
    St::Disabled: invite_code_state::IsSet,
    St::ForAccount: invite_code_state::IsSet,
    St::Uses: invite_code_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> InviteCode<S> {
        InviteCode {
            available: self._fields.0.unwrap(),
            code: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            created_by: self._fields.3.unwrap(),
            disabled: self._fields.4.unwrap(),
            for_account: self._fields.5.unwrap(),
            uses: self._fields.6.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>>,
    ) -> InviteCode<S> {
        InviteCode {
            available: self._fields.0.unwrap(),
            code: self._fields.1.unwrap(),
            created_at: self._fields.2.unwrap(),
            created_by: self._fields.3.unwrap(),
            disabled: self._fields.4.unwrap(),
            for_account: self._fields.5.unwrap(),
            uses: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_server_defs() -> 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.server.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("inviteCode"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("code"),
                            SmolStr::new_static("available"),
                            SmolStr::new_static("disabled"),
                            SmolStr::new_static("forAccount"),
                            SmolStr::new_static("createdBy"),
                            SmolStr::new_static("createdAt"), SmolStr::new_static("uses")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("available"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("code"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        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("disabled"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("forAccount"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("uses"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#inviteCodeUse"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("inviteCodeUse"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("usedBy"), SmolStr::new_static("usedAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("usedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("usedBy"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

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

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

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

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

impl<St, S: BosStr> InviteCodeUseBuilder<St, S>
where
    St: invite_code_use_state::State,
    St::UsedAt: invite_code_use_state::IsUnset,
{
    /// Set the `usedAt` field (required)
    pub fn used_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> InviteCodeUseBuilder<invite_code_use_state::SetUsedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        InviteCodeUseBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> InviteCodeUseBuilder<St, S>
where
    St: invite_code_use_state::State,
    St::UsedAt: invite_code_use_state::IsSet,
    St::UsedBy: invite_code_use_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> InviteCodeUse<S> {
        InviteCodeUse {
            used_at: self._fields.0.unwrap(),
            used_by: 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>>,
    ) -> InviteCodeUse<S> {
        InviteCodeUse {
            used_at: self._fields.0.unwrap(),
            used_by: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}