// @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.

//! Generated bindings for the `blue..2048` Lexicon namespace/module.
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, 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;
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.

#[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::{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 Hash;
        type SyncedWithAtRepo;
        type UpdatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Hash = Unset;
        type SyncedWithAtRepo = Unset;
        type UpdatedAt = 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 Hash = St::Hash;
        type SyncedWithAtRepo = St::SyncedWithAtRepo;
        type UpdatedAt = St::UpdatedAt;
    }
    ///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 CreatedAt = St::CreatedAt;
        type Hash = Set<members::hash>;
        type SyncedWithAtRepo = St::SyncedWithAtRepo;
        type UpdatedAt = St::UpdatedAt;
    }
    ///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 CreatedAt = St::CreatedAt;
        type Hash = St::Hash;
        type SyncedWithAtRepo = Set<members::synced_with_at_repo>;
        type UpdatedAt = St::UpdatedAt;
    }
    ///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 CreatedAt = St::CreatedAt;
        type Hash = St::Hash;
        type SyncedWithAtRepo = St::SyncedWithAtRepo;
        type UpdatedAt = Set<members::updated_at>;
    }
    /// 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 `hash` field
        pub struct hash(());
        ///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(());
    }
}

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

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

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

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

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

impl<St, S: BosStr> SyncStatusBuilder<St, S>
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<sync_status_state::SetCreatedAt<St>, S> {
        self._fields.0 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SyncStatusBuilder<St, S>
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<sync_status_state::SetHash<St>, S> {
        self._fields.1 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SyncStatusBuilder<St, S>
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<sync_status_state::SetSyncedWithAtRepo<St>, S> {
        self._fields.2 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SyncStatusBuilder<St, S>
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<sync_status_state::SetUpdatedAt<St>, S> {
        self._fields.3 = Option::Some(value.into());
        SyncStatusBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> SyncStatusBuilder<St, S>
where
    St: sync_status_state::State,
    St::CreatedAt: sync_status_state::IsSet,
    St::Hash: sync_status_state::IsSet,
    St::SyncedWithAtRepo: sync_status_state::IsSet,
    St::UpdatedAt: 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> {
    #[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()
    }
}