jacquard-api 0.11.0

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: com.atproto.server.listAppPasswords
//
// 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::Datetime;
use jacquard_derive::{IntoStatic, lexicon, open_union};
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::list_app_passwords;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct AppPassword<'a> {
    pub created_at: Datetime,
    #[serde(borrow)]
    pub name: CowStr<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub privileged: Option<bool>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ListAppPasswordsOutput<'a> {
    #[serde(borrow)]
    pub passwords: Vec<list_app_passwords::AppPassword<'a>>,
}


#[open_union]
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    IntoStatic
)]

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum ListAppPasswordsError<'a> {
    #[serde(rename = "AccountTakedown")]
    AccountTakedown(Option<CowStr<'a>>),
}

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

impl<'a> LexiconSchema for AppPassword<'a> {
    fn nsid() -> &'static str {
        "com.atproto.server.listAppPasswords"
    }
    fn def_name() -> &'static str {
        "appPassword"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_com_atproto_server_listAppPasswords()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

/// XRPC request marker type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
pub struct ListAppPasswords;
/// Response type for com.atproto.server.listAppPasswords
pub struct ListAppPasswordsResponse;
impl jacquard_common::xrpc::XrpcResp for ListAppPasswordsResponse {
    const NSID: &'static str = "com.atproto.server.listAppPasswords";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = ListAppPasswordsOutput<'de>;
    type Err<'de> = ListAppPasswordsError<'de>;
}

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

/// Endpoint type for com.atproto.server.listAppPasswords
pub struct ListAppPasswordsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ListAppPasswordsRequest {
    const PATH: &'static str = "/xrpc/com.atproto.server.listAppPasswords";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = ListAppPasswords;
    type Response = ListAppPasswordsResponse;
}

pub mod app_password_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 CreatedAt;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Name = Unset;
    }
    ///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 CreatedAt = Set<members::created_at>;
        type Name = S::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type CreatedAt = S::CreatedAt;
        type Name = Set<members::name>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `name` field
        pub struct name(());
    }
}

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

impl<'a> AppPassword<'a> {
    /// Create a new builder for this type
    pub fn new() -> AppPasswordBuilder<'a, app_password_state::Empty> {
        AppPasswordBuilder::new()
    }
}

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

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

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

impl<'a, S: app_password_state::State> AppPasswordBuilder<'a, S> {
    /// Set the `privileged` field (optional)
    pub fn privileged(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `privileged` field to an Option value (optional)
    pub fn maybe_privileged(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> AppPasswordBuilder<'a, S>
where
    S: app_password_state::State,
    S::CreatedAt: app_password_state::IsSet,
    S::Name: app_password_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> AppPassword<'a> {
        AppPassword {
            created_at: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            privileged: self._fields.2,
            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>,
        >,
    ) -> AppPassword<'a> {
        AppPassword {
            created_at: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            privileged: self._fields.2,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_com_atproto_server_listAppPasswords() -> 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.listAppPasswords"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("appPassword"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("name"), SmolStr::new_static("createdAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("privileged"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: None,
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}