// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.server.createInviteCodes
//
// 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;
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::create_invite_codes;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct AccountCodes<S: BosStr = DefaultStr> {
    pub account: S,
    pub codes: Vec<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 CreateInviteCodes<S: BosStr = DefaultStr> {
    /// Defaults to `1`.
    #[serde(default = "_default_create_invite_codes_code_count")]
    pub code_count: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub for_accounts: Option<Vec<Did<S>>>,
    pub use_count: i64,
    #[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 CreateInviteCodesOutput<S: BosStr = DefaultStr> {
    pub codes: Vec<create_invite_codes::AccountCodes<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

/** Response marker for the `com.atproto.server.createInviteCodes` procedure.

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

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

/** Endpoint marker for the `com.atproto.server.createInviteCodes` procedure.

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

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

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

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

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

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

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

impl<St, S: BosStr> AccountCodesBuilder<St, S>
where
    St: account_codes_state::State,
    St::Account: account_codes_state::IsUnset,
{
    /// Set the `account` field (required)
    pub fn account(
        mut self,
        value: impl Into<S>,
    ) -> AccountCodesBuilder<account_codes_state::SetAccount<St>, S> {
        self._fields.0 = Option::Some(value.into());
        AccountCodesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AccountCodesBuilder<St, S>
where
    St: account_codes_state::State,
    St::Codes: account_codes_state::IsUnset,
{
    /// Set the `codes` field (required)
    pub fn codes(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> AccountCodesBuilder<account_codes_state::SetCodes<St>, S> {
        self._fields.1 = Option::Some(value.into());
        AccountCodesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> AccountCodesBuilder<St, S>
where
    St: account_codes_state::State,
    St::Account: account_codes_state::IsSet,
    St::Codes: account_codes_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> AccountCodes<S> {
        AccountCodes {
            account: self._fields.0.unwrap(),
            codes: 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>>,
    ) -> AccountCodes<S> {
        AccountCodes {
            account: self._fields.0.unwrap(),
            codes: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_server_createInviteCodes() -> 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.createInviteCodes"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("accountCodes"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("account"), SmolStr::new_static("codes")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("account"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("codes"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        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("codeCount"),
                                        SmolStr::new_static("useCount")
                                    ],
                                ),
                                properties: {
                                    #[allow(unused_mut)]
                                    let mut map = BTreeMap::new();
                                    map.insert(
                                        SmolStr::new_static("codeCount"),
                                        LexObjectProperty::Integer(LexInteger {
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("forAccounts"),
                                        LexObjectProperty::Array(LexArray {
                                            items: LexArrayItem::String(LexString {
                                                format: Some(LexStringFormat::Did),
                                                ..Default::default()
                                            }),
                                            ..Default::default()
                                        }),
                                    );
                                    map.insert(
                                        SmolStr::new_static("useCount"),
                                        LexObjectProperty::Integer(LexInteger {
                                            ..Default::default()
                                        }),
                                    );
                                    map
                                },
                                ..Default::default()
                            }),
                        ),
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_create_invite_codes_code_count() -> i64 {
    1i64
}

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

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

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

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

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

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

impl<St, S: BosStr> CreateInviteCodesBuilder<St, S>
where
    St: create_invite_codes_state::State,
    St::CodeCount: create_invite_codes_state::IsUnset,
{
    /// Set the `codeCount` field (required)
    pub fn code_count(
        mut self,
        value: impl Into<i64>,
    ) -> CreateInviteCodesBuilder<create_invite_codes_state::SetCodeCount<St>, S> {
        self._fields.0 = Option::Some(value.into());
        CreateInviteCodesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: create_invite_codes_state::State, S: BosStr> CreateInviteCodesBuilder<St, S> {
    /// Set the `forAccounts` field (optional)
    pub fn for_accounts(mut self, value: impl Into<Option<Vec<Did<S>>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `forAccounts` field to an Option value (optional)
    pub fn maybe_for_accounts(mut self, value: Option<Vec<Did<S>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> CreateInviteCodesBuilder<St, S>
where
    St: create_invite_codes_state::State,
    St::UseCount: create_invite_codes_state::IsUnset,
{
    /// Set the `useCount` field (required)
    pub fn use_count(
        mut self,
        value: impl Into<i64>,
    ) -> CreateInviteCodesBuilder<create_invite_codes_state::SetUseCount<St>, S> {
        self._fields.2 = Option::Some(value.into());
        CreateInviteCodesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> CreateInviteCodesBuilder<St, S>
where
    St: create_invite_codes_state::State,
    St::CodeCount: create_invite_codes_state::IsSet,
    St::UseCount: create_invite_codes_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> CreateInviteCodes<S> {
        CreateInviteCodes {
            code_count: self._fields.0.unwrap(),
            for_accounts: self._fields.1,
            use_count: 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>>,
    ) -> CreateInviteCodes<S> {
        CreateInviteCodes {
            code_count: self._fields.0.unwrap(),
            for_accounts: self._fields.1,
            use_count: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}