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

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;

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct InviteCode<'a> {
    pub available: i64,
    #[serde(borrow)]
    pub code: CowStr<'a>,
    pub created_at: Datetime,
    #[serde(borrow)]
    pub created_by: CowStr<'a>,
    pub disabled: bool,
    #[serde(borrow)]
    pub for_account: CowStr<'a>,
    #[serde(borrow)]
    pub uses: Vec<server::InviteCodeUse<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct InviteCodeUse<'a> {
    pub used_at: Datetime,
    #[serde(borrow)]
    pub used_by: Did<'a>,
}

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

/// Builder for constructing an instance of this type
pub struct InviteCodeBuilder<'a, S: invite_code_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<i64>,
        Option<CowStr<'a>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<bool>,
        Option<CowStr<'a>>,
        Option<Vec<server::InviteCodeUse<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

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

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

impl<'a, S> InviteCodeBuilder<'a, S>
where
    S: invite_code_state::State,
    S::ForAccount: invite_code_state::IsSet,
    S::Disabled: invite_code_state::IsSet,
    S::Code: invite_code_state::IsSet,
    S::Uses: invite_code_state::IsSet,
    S::CreatedAt: invite_code_state::IsSet,
    S::Available: invite_code_state::IsSet,
    S::CreatedBy: invite_code_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> InviteCode<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> InviteCode<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUsedAt<S> {}
    impl<S: State> State for SetUsedAt<S> {
        type UsedAt = Set<members::used_at>;
        type UsedBy = S::UsedBy;
    }
    ///State transition - sets the `used_by` field to Set
    pub struct SetUsedBy<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUsedBy<S> {}
    impl<S: State> State for SetUsedBy<S> {
        type UsedAt = S::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<'a, S: invite_code_use_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Datetime>, Option<Did<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> InviteCodeUseBuilder<'a, S>
where
    S: invite_code_use_state::State,
    S::UsedAt: invite_code_use_state::IsSet,
    S::UsedBy: invite_code_use_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> InviteCodeUse<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> InviteCodeUse<'a> {
        InviteCodeUse {
            used_at: self._fields.0.unwrap(),
            used_by: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}