// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.signature.findRelatedAccounts
//
// 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::admin::AccountView;
use crate::tools_ozone::signature::SigDetail;
use crate::tools_ozone::signature::find_related_accounts;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct FindRelatedAccounts<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub did: Did<'a>,
    ///Defaults to `50`. Min: 1. Max: 100.
    #[serde(default = "_default_limit")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct FindRelatedAccountsOutput<'a> {
    #[serde(borrow)]
    pub accounts: Vec<find_related_accounts::RelatedAccount<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cursor: Option<CowStr<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct RelatedAccount<'a> {
    #[serde(borrow)]
    pub account: AccountView<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub similarities: Option<Vec<SigDetail<'a>>>,
}

/// Response type for tools.ozone.signature.findRelatedAccounts
pub struct FindRelatedAccountsResponse;
impl jacquard_common::xrpc::XrpcResp for FindRelatedAccountsResponse {
    const NSID: &'static str = "tools.ozone.signature.findRelatedAccounts";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = FindRelatedAccountsOutput<'de>;
    type Err<'de> = jacquard_common::xrpc::GenericError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for FindRelatedAccounts<'a> {
    const NSID: &'static str = "tools.ozone.signature.findRelatedAccounts";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = FindRelatedAccountsResponse;
}

/// Endpoint type for tools.ozone.signature.findRelatedAccounts
pub struct FindRelatedAccountsRequest;
impl jacquard_common::xrpc::XrpcEndpoint for FindRelatedAccountsRequest {
    const PATH: &'static str = "/xrpc/tools.ozone.signature.findRelatedAccounts";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = FindRelatedAccounts<'de>;
    type Response = FindRelatedAccountsResponse;
}

impl<'a> LexiconSchema for RelatedAccount<'a> {
    fn nsid() -> &'static str {
        "tools.ozone.signature.findRelatedAccounts"
    }
    fn def_name() -> &'static str {
        "relatedAccount"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_signature_findRelatedAccounts()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_limit() -> Option<i64> {
    Some(50i64)
}

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

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

impl<'a> FindRelatedAccounts<'a> {
    /// Create a new builder for this type
    pub fn new() -> FindRelatedAccountsBuilder<'a, find_related_accounts_state::Empty> {
        FindRelatedAccountsBuilder::new()
    }
}

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

impl<'a, S: find_related_accounts_state::State> FindRelatedAccountsBuilder<'a, S> {
    /// Set the `cursor` field (optional)
    pub fn cursor(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `cursor` field to an Option value (optional)
    pub fn maybe_cursor(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S> FindRelatedAccountsBuilder<'a, S>
where
    S: find_related_accounts_state::State,
    S::Did: find_related_accounts_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> FindRelatedAccountsBuilder<'a, find_related_accounts_state::SetDid<S>> {
        self._fields.1 = Option::Some(value.into());
        FindRelatedAccountsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: find_related_accounts_state::State> FindRelatedAccountsBuilder<'a, S> {
    /// Set the `limit` field (optional)
    pub fn limit(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `limit` field to an Option value (optional)
    pub fn maybe_limit(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S> FindRelatedAccountsBuilder<'a, S>
where
    S: find_related_accounts_state::State,
    S::Did: find_related_accounts_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> FindRelatedAccounts<'a> {
        FindRelatedAccounts {
            cursor: self._fields.0,
            did: self._fields.1.unwrap(),
            limit: self._fields.2,
        }
    }
}

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

/// Builder for constructing an instance of this type
pub struct RelatedAccountBuilder<'a, S: related_account_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<AccountView<'a>>, Option<Vec<SigDetail<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> RelatedAccount<'a> {
    /// Create a new builder for this type
    pub fn new() -> RelatedAccountBuilder<'a, related_account_state::Empty> {
        RelatedAccountBuilder::new()
    }
}

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

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

impl<'a, S: related_account_state::State> RelatedAccountBuilder<'a, S> {
    /// Set the `similarities` field (optional)
    pub fn similarities(mut self, value: impl Into<Option<Vec<SigDetail<'a>>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `similarities` field to an Option value (optional)
    pub fn maybe_similarities(mut self, value: Option<Vec<SigDetail<'a>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<'a, S> RelatedAccountBuilder<'a, S>
where
    S: related_account_state::State,
    S::Account: related_account_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> RelatedAccount<'a> {
        RelatedAccount {
            account: self._fields.0.unwrap(),
            similarities: self._fields.1,
            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>,
        >,
    ) -> RelatedAccount<'a> {
        RelatedAccount {
            account: self._fields.0.unwrap(),
            similarities: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_tools_ozone_signature_findRelatedAccounts() -> 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("tools.ozone.signature.findRelatedAccounts"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::XrpcQuery(LexXrpcQuery {
                    parameters: Some(
                        LexXrpcQueryParameter::Params(LexXrpcParameters {
                            required: Some(vec![SmolStr::new_static("did")]),
                            properties: {
                                #[allow(unused_mut)]
                                let mut map = BTreeMap::new();
                                map.insert(
                                    SmolStr::new_static("cursor"),
                                    LexXrpcParametersProperty::String(LexString {
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("did"),
                                    LexXrpcParametersProperty::String(LexString {
                                        format: Some(LexStringFormat::Did),
                                        ..Default::default()
                                    }),
                                );
                                map.insert(
                                    SmolStr::new_static("limit"),
                                    LexXrpcParametersProperty::Integer(LexInteger {
                                        ..Default::default()
                                    }),
                                );
                                map
                            },
                            ..Default::default()
                        }),
                    ),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("relatedAccount"),
                LexUserType::Object(LexObject {
                    required: Some(vec![SmolStr::new_static("account")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("account"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "com.atproto.admin.defs#accountView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("similarities"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "tools.ozone.signature.defs#sigDetail",
                                    ),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}