jacquard-api 0.12.0-beta.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: blue.2048.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

pub mod game;
pub mod key;
pub mod player;
pub mod verification;

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

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, 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;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Deserialize, Serialize};
/// The sync status for a record used to help sync between your ATProto record and local record.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct SyncStatus<S: BosStr = DefaultStr> {
    pub created_at: Datetime,
    ///A XXH3 hash of the record to tell if anything has changed
    pub hash: S,
    ///A flag to know if it has been synced with the AT repo. Used mostly client side to filter what records need syncing  Defaults to `false`.
    #[serde(default = "_default_sync_status_synced_with_at_repo")]
    pub synced_with_at_repo: bool,
    pub updated_at: Datetime,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for SyncStatus<S> {
    fn nsid() -> &'static str {
        "blue.2048.defs"
    }
    fn def_name() -> &'static str {
        "syncStatus"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blue_2048_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_sync_status_synced_with_at_repo() -> bool {
    false
}

pub mod sync_status_state {

    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
    #[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 Hash;
        type UpdatedAt;
        type CreatedAt;
        type SyncedWithAtRepo;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Hash = Unset;
        type UpdatedAt = Unset;
        type CreatedAt = Unset;
        type SyncedWithAtRepo = Unset;
    }
    ///State transition - sets the `hash` field to Set
    pub struct SetHash<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHash<St> {}
    impl<St: State> State for SetHash<St> {
        type Hash = Set<members::hash>;
        type UpdatedAt = St::UpdatedAt;
        type CreatedAt = St::CreatedAt;
        type SyncedWithAtRepo = St::SyncedWithAtRepo;
    }
    ///State transition - sets the `updated_at` field to Set
    pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
    impl<St: State> State for SetUpdatedAt<St> {
        type Hash = St::Hash;
        type UpdatedAt = Set<members::updated_at>;
        type CreatedAt = St::CreatedAt;
        type SyncedWithAtRepo = St::SyncedWithAtRepo;
    }
    ///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 Hash = St::Hash;
        type UpdatedAt = St::UpdatedAt;
        type CreatedAt = Set<members::created_at>;
        type SyncedWithAtRepo = St::SyncedWithAtRepo;
    }
    ///State transition - sets the `synced_with_at_repo` field to Set
    pub struct SetSyncedWithAtRepo<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSyncedWithAtRepo<St> {}
    impl<St: State> State for SetSyncedWithAtRepo<St> {
        type Hash = St::Hash;
        type UpdatedAt = St::UpdatedAt;
        type CreatedAt = St::CreatedAt;
        type SyncedWithAtRepo = Set<members::synced_with_at_repo>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `hash` field
        pub struct hash(());
        ///Marker type for the `updated_at` field
        pub struct updated_at(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `synced_with_at_repo` field
        pub struct synced_with_at_repo(());
    }
}

/// Builder for constructing an instance of this type.
pub struct SyncStatusBuilder<S: BosStr, St: sync_status_state::State> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Datetime>, Option<S>, Option<bool>, Option<Datetime>),
    _type: PhantomData<fn() -> S>,
}

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

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

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

impl<S: BosStr, St> SyncStatusBuilder<S, St>
where
    St: sync_status_state::State,
    St::Hash: sync_status_state::IsUnset,
{
    /// Set the `hash` field (required)
    pub fn hash(
        mut self,
        value: impl Into<S>,
    ) -> SyncStatusBuilder<S, sync_status_state::SetHash<St>> {
        self._fields.1 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> SyncStatusBuilder<S, St>
where
    St: sync_status_state::State,
    St::SyncedWithAtRepo: sync_status_state::IsUnset,
{
    /// Set the `syncedWithATRepo` field (required)
    pub fn synced_with_at_repo(
        mut self,
        value: impl Into<bool>,
    ) -> SyncStatusBuilder<S, sync_status_state::SetSyncedWithAtRepo<St>> {
        self._fields.2 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> SyncStatusBuilder<S, St>
where
    St: sync_status_state::State,
    St::UpdatedAt: sync_status_state::IsUnset,
{
    /// Set the `updatedAt` field (required)
    pub fn updated_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SyncStatusBuilder<S, sync_status_state::SetUpdatedAt<St>> {
        self._fields.3 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St> SyncStatusBuilder<S, St>
where
    St: sync_status_state::State,
    St::Hash: sync_status_state::IsSet,
    St::UpdatedAt: sync_status_state::IsSet,
    St::CreatedAt: sync_status_state::IsSet,
    St::SyncedWithAtRepo: sync_status_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> SyncStatus<S> {
        SyncStatus {
            created_at: self._fields.0.unwrap(),
            hash: self._fields.1.unwrap(),
            synced_with_at_repo: self._fields.2.unwrap(),
            updated_at: self._fields.3.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> SyncStatus<S> {
        SyncStatus {
            created_at: self._fields.0.unwrap(),
            hash: self._fields.1.unwrap(),
            synced_with_at_repo: self._fields.2.unwrap(),
            updated_at: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_blue_2048_defs() -> LexiconDoc<'static> {
    use alloc::collections::BTreeMap;
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("blue.2048.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("syncStatus"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "The sync status for a record used to help sync between your ATProto record and local record.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("hash"),
                            SmolStr::new_static("updatedAt"),
                            SmolStr::new_static("createdAt"),
                            SmolStr::new_static("syncedWithATRepo")
                        ],
                    ),
                    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("hash"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "A XXH3 hash of the record to tell if anything has changed",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("syncedWithATRepo"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("updatedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}