// @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, 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::Datetime;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, 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;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct AppPassword<S: BosStr = DefaultStr> {
    pub created_at: Datetime,
    pub name: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub privileged: Option<bool>,
    #[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 ListAppPasswordsOutput<S: BosStr = DefaultStr> {
    pub passwords: Vec<list_app_passwords::AppPassword<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 ListAppPasswordsError {
    #[serde(rename = "AccountTakedown")]
    AccountTakedown(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other { error: SmolStr, message: Option<SmolStr> },
}

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::Other { error, message } => {
                write!(f, "{}", error)?;
                if let Some(msg) = message {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
        }
    }
}

impl<S: BosStr> LexiconSchema for AppPassword<S> {
    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(())
    }
}

/** Request marker for the `com.atproto.server.listAppPasswords` query.

This endpoint has no request parameters or input body; send this marker with `jacquard::Client`.*/

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Copy)]
pub struct ListAppPasswords;
/** Response marker for the `com.atproto.server.listAppPasswords` query.

Implements `jacquard_common::xrpc::XrpcResp`; successful bodies decode as `Self::Output<S>`, which is `ListAppPasswordsOutput<S>` for this endpoint.*/
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<S: BosStr> = ListAppPasswordsOutput<S>;
    type Err = ListAppPasswordsError;
}

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 marker for the `com.atproto.server.listAppPasswords` query.

Path: `/xrpc/com.atproto.server.listAppPasswords`. The request payload type is `ListAppPasswords`; use this marker with lower-level `XrpcEndpoint` APIs when you need endpoint metadata.*/
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<S: BosStr> = 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<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Name = St::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type CreatedAt = St::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<St: app_password_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Datetime>, Option<S>, Option<bool>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

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

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

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

impl<St: app_password_state::State, S: BosStr> AppPasswordBuilder<St, 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<St, S: BosStr> AppPasswordBuilder<St, S>
where
    St: app_password_state::State,
    St::CreatedAt: app_password_state::IsSet,
    St::Name: app_password_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> AppPassword<S> {
        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<SmolStr, Data<S>>,
    ) -> AppPassword<S> {
        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()
    }
}