// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.server.getAccountInviteCodes
//
// 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};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::com_atproto::server::InviteCode;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetAccountInviteCodes {
    ///  Defaults to `true`.
    #[serde(default = "_default_create_available")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub create_available: Option<bool>,
    ///  Defaults to `true`.
    #[serde(default = "_default_include_used")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub include_used: Option<bool>,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GetAccountInviteCodesOutput<S: BosStr = DefaultStr> {
    pub codes: Vec<InviteCode<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,
    thiserror::Error,
    miette::Diagnostic
)]

#[serde(tag = "error", content = "message")]
pub enum GetAccountInviteCodesError {
    #[serde(rename = "DuplicateCreate")]
    DuplicateCreate(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

impl core::fmt::Display for GetAccountInviteCodesError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::DuplicateCreate(msg) => {
                write!(f, "DuplicateCreate")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

/** Response marker for the `com.atproto.server.getAccountInviteCodes` query.

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

impl jacquard_common::xrpc::XrpcRequest for GetAccountInviteCodes {
    const NSID: &'static str = "com.atproto.server.getAccountInviteCodes";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetAccountInviteCodesResponse;
}

/** Endpoint marker for the `com.atproto.server.getAccountInviteCodes` query.

Path: `/xrpc/com.atproto.server.getAccountInviteCodes`. The request payload type is `GetAccountInviteCodes`; send that request with `jacquard::Client` or use this marker through lower-level `XrpcEndpoint` APIs.*/
pub struct GetAccountInviteCodesRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetAccountInviteCodesRequest {
    const PATH: &'static str = "/xrpc/com.atproto.server.getAccountInviteCodes";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<S: BosStr> = GetAccountInviteCodes;
    type Response = GetAccountInviteCodesResponse;
}

fn _default_create_available() -> Option<bool> {
    Some(true)
}

fn _default_include_used() -> Option<bool> {
    Some(true)
}

pub mod get_account_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 {}
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {}
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {}
}

/// Builder for constructing an instance of this type.
pub struct GetAccountInviteCodesBuilder<St: get_account_invite_codes_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<bool>, Option<bool>),
}

impl GetAccountInviteCodes {
    /// Create a new builder for this type.
    pub fn new() -> GetAccountInviteCodesBuilder<get_account_invite_codes_state::Empty> {
        GetAccountInviteCodesBuilder::new()
    }
}

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

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

impl<St: get_account_invite_codes_state::State> GetAccountInviteCodesBuilder<St> {
    /// Set the `createAvailable` field (optional)
    pub fn create_available(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `createAvailable` field to an Option value (optional)
    pub fn maybe_create_available(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: get_account_invite_codes_state::State> GetAccountInviteCodesBuilder<St> {
    /// Set the `includeUsed` field (optional)
    pub fn include_used(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `includeUsed` field to an Option value (optional)
    pub fn maybe_include_used(mut self, value: Option<bool>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St> GetAccountInviteCodesBuilder<St>
where
    St: get_account_invite_codes_state::State,
{
    /// Build the final struct.
    pub fn build(self) -> GetAccountInviteCodes {
        GetAccountInviteCodes {
            create_available: self._fields.0,
            include_used: self._fields.1,
        }
    }
}