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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::Did;
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::create_invite_codes;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AccountCodes<'a> {
    #[serde(borrow)]
    pub account: CowStr<'a>,
    #[serde(borrow)]
    pub codes: Vec<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CreateInviteCodes<'a> {
    /// Defaults to `1`.
    #[serde(default = "_default_create_invite_codes_code_count")]
    pub code_count: i64,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub for_accounts: Option<Vec<Did<'a>>>,
    pub use_count: i64,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct CreateInviteCodesOutput<'a> {
    #[serde(borrow)]
    pub codes: Vec<create_invite_codes::AccountCodes<'a>>,
}

impl<'a> LexiconSchema for AccountCodes<'a> {
    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 type for com.atproto.server.createInviteCodes
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<'de> = CreateInviteCodesOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for CreateInviteCodes<'a> {
    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 type for com.atproto.server.createInviteCodes
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<'de> = CreateInviteCodes<'de>;
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAccount<S> {}
    impl<S: State> State for SetAccount<S> {
        type Account = Set<members::account>;
        type Codes = S::Codes;
    }
    ///State transition - sets the `codes` field to Set
    pub struct SetCodes<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCodes<S> {}
    impl<S: State> State for SetCodes<S> {
        type Account = S::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<'a, S: account_codes_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>, Option<Vec<CowStr<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> AccountCodesBuilder<'a, S>
where
    S: account_codes_state::State,
    S::Account: account_codes_state::IsSet,
    S::Codes: account_codes_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> AccountCodes<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> AccountCodes<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCodeCount<S> {}
    impl<S: State> State for SetCodeCount<S> {
        type CodeCount = Set<members::code_count>;
        type UseCount = S::UseCount;
    }
    ///State transition - sets the `use_count` field to Set
    pub struct SetUseCount<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUseCount<S> {}
    impl<S: State> State for SetUseCount<S> {
        type CodeCount = S::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<'a, S: create_invite_codes_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<i64>, Option<Vec<Did<'a>>>, Option<i64>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: create_invite_codes_state::State> CreateInviteCodesBuilder<'a, S> {
    /// Set the `forAccounts` field (optional)
    pub fn for_accounts(mut self, value: impl Into<Option<Vec<Did<'a>>>>) -> 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<'a>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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