// @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::CowStr;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::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};
/// The sync status for a record used to help sync between your ATProto record and local record.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct SyncStatus<'a> {
    pub created_at: Datetime,
    ///A XXH3 hash of the record to tell if anything has changed
    #[serde(borrow)]
    pub hash: CowStr<'a>,
    ///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,
}

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

/// Builder for constructing an instance of this type
pub struct SyncStatusBuilder<'a, S: sync_status_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Datetime>, Option<CowStr<'a>>, Option<bool>, 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, None, None),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> SyncStatusBuilder<'a, S>
where
    S: sync_status_state::State,
    S::CreatedAt: sync_status_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SyncStatusBuilder<'a, sync_status_state::SetCreatedAt<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::Hash: sync_status_state::IsUnset,
{
    /// Set the `hash` field (required)
    pub fn hash(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> SyncStatusBuilder<'a, sync_status_state::SetHash<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::SyncedWithAtRepo: sync_status_state::IsUnset,
{
    /// Set the `syncedWithATRepo` field (required)
    pub fn synced_with_at_repo(
        mut self,
        value: impl Into<bool>,
    ) -> SyncStatusBuilder<'a, sync_status_state::SetSyncedWithAtRepo<S>> {
        self._fields.2 = 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::UpdatedAt: sync_status_state::IsUnset,
{
    /// Set the `updatedAt` field (required)
    pub fn updated_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> SyncStatusBuilder<'a, sync_status_state::SetUpdatedAt<S>> {
        self._fields.3 = 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::SyncedWithAtRepo: sync_status_state::IsSet,
    S::UpdatedAt: sync_status_state::IsSet,
    S::Hash: sync_status_state::IsSet,
    S::CreatedAt: sync_status_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> SyncStatus<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> SyncStatus<'a> {
        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> {
    #[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("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()
    }
}