// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.bsky.contact.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod dismiss_match;
pub mod get_matches;
pub mod get_sync_status;
pub mod import_contacts;
pub mod remove_data;
pub mod send_notification;
pub mod start_phone_verification;
pub mod verify_phone;


#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, Datetime};
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::app_bsky::actor::ProfileView;
/// Associates a profile with the positional index of the contact import input in the call to `app.bsky.contact.importContacts`, so clients can know which phone caused a particular match.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct MatchAndContactIndex<'a> {
    ///The index of this match in the import contact input.
    pub contact_index: i64,
    ///Profile of the matched user.
    #[serde(borrow)]
    pub r#match: ProfileView<'a>,
}

/// A stash object to be sent via bsync representing a notification to be created.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Notification<'a> {
    ///The DID of who this notification comes from.
    #[serde(borrow)]
    pub from: Did<'a>,
    ///The DID of who this notification should go to.
    #[serde(borrow)]
    pub to: Did<'a>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SyncStatus<'a> {
    ///Number of existing contact matches resulting of the user imports and of their imported contacts having imported the user. Matches stop being counted when the user either follows the matched contact or dismisses the match.
    pub matches_count: i64,
    ///Last date when contacts where imported.
    pub synced_at: Datetime,
}

impl<'a> LexiconSchema for MatchAndContactIndex<'a> {
    fn nsid() -> &'static str {
        "app.bsky.contact.defs"
    }
    fn def_name() -> &'static str {
        "matchAndContactIndex"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_contact_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.contact_index;
            if *value > 999i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("contact_index"),
                    max: 999i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.contact_index;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("contact_index"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for Notification<'a> {
    fn nsid() -> &'static str {
        "app.bsky.contact.defs"
    }
    fn def_name() -> &'static str {
        "notification"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_contact_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<'a> LexiconSchema for SyncStatus<'a> {
    fn nsid() -> &'static str {
        "app.bsky.contact.defs"
    }
    fn def_name() -> &'static str {
        "syncStatus"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_bsky_contact_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.matches_count;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("matches_count"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

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

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

impl<'a> MatchAndContactIndex<'a> {
    /// Create a new builder for this type
    pub fn new() -> MatchAndContactIndexBuilder<
        'a,
        match_and_contact_index_state::Empty,
    > {
        MatchAndContactIndexBuilder::new()
    }
}

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

impl<'a, S> MatchAndContactIndexBuilder<'a, S>
where
    S: match_and_contact_index_state::State,
    S::ContactIndex: match_and_contact_index_state::IsUnset,
{
    /// Set the `contactIndex` field (required)
    pub fn contact_index(
        mut self,
        value: impl Into<i64>,
    ) -> MatchAndContactIndexBuilder<
        'a,
        match_and_contact_index_state::SetContactIndex<S>,
    > {
        self._fields.0 = Option::Some(value.into());
        MatchAndContactIndexBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MatchAndContactIndexBuilder<'a, S>
where
    S: match_and_contact_index_state::State,
    S::Match: match_and_contact_index_state::IsUnset,
{
    /// Set the `match` field (required)
    pub fn r#match(
        mut self,
        value: impl Into<ProfileView<'a>>,
    ) -> MatchAndContactIndexBuilder<'a, match_and_contact_index_state::SetMatch<S>> {
        self._fields.1 = Option::Some(value.into());
        MatchAndContactIndexBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MatchAndContactIndexBuilder<'a, S>
where
    S: match_and_contact_index_state::State,
    S::ContactIndex: match_and_contact_index_state::IsSet,
    S::Match: match_and_contact_index_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> MatchAndContactIndex<'a> {
        MatchAndContactIndex {
            contact_index: self._fields.0.unwrap(),
            r#match: 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>,
        >,
    ) -> MatchAndContactIndex<'a> {
        MatchAndContactIndex {
            contact_index: self._fields.0.unwrap(),
            r#match: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_app_bsky_contact_defs() -> 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("app.bsky.contact.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("matchAndContactIndex"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Associates a profile with the positional index of the contact import input in the call to `app.bsky.contact.importContacts`, so clients can know which phone caused a particular match.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("match"),
                            SmolStr::new_static("contactIndex")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("contactIndex"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                maximum: Some(999i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("match"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.bsky.actor.defs#profileView",
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("notification"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A stash object to be sent via bsync representing a notification to be created.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("from"), SmolStr::new_static("to")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("from"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The DID of who this notification comes from.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("to"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The DID of who this notification should go to.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("syncStatus"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("syncedAt"),
                            SmolStr::new_static("matchesCount")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("matchesCount"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("syncedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Last date when contacts where imported.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

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

impl<'a> Notification<'a> {
    /// Create a new builder for this type
    pub fn new() -> NotificationBuilder<'a, notification_state::Empty> {
        NotificationBuilder::new()
    }
}

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

impl<'a, S> NotificationBuilder<'a, S>
where
    S: notification_state::State,
    S::From: notification_state::IsUnset,
{
    /// Set the `from` field (required)
    pub fn from(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> NotificationBuilder<'a, notification_state::SetFrom<S>> {
        self._fields.0 = Option::Some(value.into());
        NotificationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

impl<'a, S> NotificationBuilder<'a, S>
where
    S: notification_state::State,
    S::To: notification_state::IsSet,
    S::From: notification_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Notification<'a> {
        Notification {
            from: self._fields.0.unwrap(),
            to: 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>,
        >,
    ) -> Notification<'a> {
        Notification {
            from: self._fields.0.unwrap(),
            to: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

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

impl<'a> SyncStatus<'a> {
    /// Create a new builder for this type
    pub fn new() -> SyncStatusBuilder<'a, sync_status_state::Empty> {
        SyncStatusBuilder::new()
    }
}

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

impl<'a, S> SyncStatusBuilder<'a, S>
where
    S: sync_status_state::State,
    S::MatchesCount: sync_status_state::IsUnset,
{
    /// Set the `matchesCount` field (required)
    pub fn matches_count(
        mut self,
        value: impl Into<i64>,
    ) -> SyncStatusBuilder<'a, sync_status_state::SetMatchesCount<S>> {
        self._fields.0 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SyncStatusBuilder<'a, S>
where
    S: sync_status_state::State,
    S::SyncedAt: sync_status_state::IsUnset,
{
    /// Set the `syncedAt` field (required)
    pub fn synced_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SyncStatusBuilder<'a, sync_status_state::SetSyncedAt<S>> {
        self._fields.1 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SyncStatusBuilder<'a, S>
where
    S: sync_status_state::State,
    S::MatchesCount: sync_status_state::IsSet,
    S::SyncedAt: sync_status_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SyncStatus<'a> {
        SyncStatus {
            matches_count: self._fields.0.unwrap(),
            synced_at: 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>,
        >,
    ) -> SyncStatus<'a> {
        SyncStatus {
            matches_count: self._fields.0.unwrap(),
            synced_at: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}