// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: social.showcase.profile.preferences
//
// 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, 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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
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::social_showcase::ActivitySettings;
use crate::social_showcase::DisplaySettings;
use crate::social_showcase::NotificationSettings;
use crate::social_showcase::PrivacySettings;
use crate::social_showcase::VisibilitySettings;
/// User preferences and settings

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "social.showcase.profile.preferences",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Preferences<S: BosStr = DefaultStr> {
    pub activity: ActivitySettings<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display: Option<DisplaySettings<S>>,
    pub notifications: NotificationSettings<S>,
    pub privacy: PrivacySettings<S>,
    ///Schema version for migrations (defaults to 1 if missing)  Defaults to `1`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_preferences_schema_version")]
    pub schema_version: Option<i64>,
    pub updated_at: Datetime,
    pub visibility: VisibilitySettings<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct PreferencesGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Preferences<S>,
}

impl<S: BosStr> Preferences<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, PreferencesRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct PreferencesRecord;
impl XrpcResp for PreferencesRecord {
    const NSID: &'static str = "social.showcase.profile.preferences";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = PreferencesGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<PreferencesGetRecordOutput<S>> for Preferences<S> {
    fn from(output: PreferencesGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Preferences<S> {
    const NSID: &'static str = "social.showcase.profile.preferences";
    type Record = PreferencesRecord;
}

impl Collection for PreferencesRecord {
    const NSID: &'static str = "social.showcase.profile.preferences";
    type Record = PreferencesRecord;
}

impl<S: BosStr> LexiconSchema for Preferences<S> {
    fn nsid() -> &'static str {
        "social.showcase.profile.preferences"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_social_showcase_profile_preferences()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn _default_preferences_schema_version() -> Option<i64> {
    Some(1i64)
}

pub mod preferences_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 Activity;
        type Notifications;
        type Privacy;
        type UpdatedAt;
        type Visibility;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Activity = Unset;
        type Notifications = Unset;
        type Privacy = Unset;
        type UpdatedAt = Unset;
        type Visibility = Unset;
    }
    ///State transition - sets the `activity` field to Set
    pub struct SetActivity<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetActivity<St> {}
    impl<St: State> State for SetActivity<St> {
        type Activity = Set<members::activity>;
        type Notifications = St::Notifications;
        type Privacy = St::Privacy;
        type UpdatedAt = St::UpdatedAt;
        type Visibility = St::Visibility;
    }
    ///State transition - sets the `notifications` field to Set
    pub struct SetNotifications<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetNotifications<St> {}
    impl<St: State> State for SetNotifications<St> {
        type Activity = St::Activity;
        type Notifications = Set<members::notifications>;
        type Privacy = St::Privacy;
        type UpdatedAt = St::UpdatedAt;
        type Visibility = St::Visibility;
    }
    ///State transition - sets the `privacy` field to Set
    pub struct SetPrivacy<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPrivacy<St> {}
    impl<St: State> State for SetPrivacy<St> {
        type Activity = St::Activity;
        type Notifications = St::Notifications;
        type Privacy = Set<members::privacy>;
        type UpdatedAt = St::UpdatedAt;
        type Visibility = St::Visibility;
    }
    ///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 Activity = St::Activity;
        type Notifications = St::Notifications;
        type Privacy = St::Privacy;
        type UpdatedAt = Set<members::updated_at>;
        type Visibility = St::Visibility;
    }
    ///State transition - sets the `visibility` field to Set
    pub struct SetVisibility<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetVisibility<St> {}
    impl<St: State> State for SetVisibility<St> {
        type Activity = St::Activity;
        type Notifications = St::Notifications;
        type Privacy = St::Privacy;
        type UpdatedAt = St::UpdatedAt;
        type Visibility = Set<members::visibility>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `activity` field
        pub struct activity(());
        ///Marker type for the `notifications` field
        pub struct notifications(());
        ///Marker type for the `privacy` field
        pub struct privacy(());
        ///Marker type for the `updated_at` field
        pub struct updated_at(());
        ///Marker type for the `visibility` field
        pub struct visibility(());
    }
}

/// Builder for constructing an instance of this type.
pub struct PreferencesBuilder<St: preferences_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<ActivitySettings<S>>,
        Option<DisplaySettings<S>>,
        Option<NotificationSettings<S>>,
        Option<PrivacySettings<S>>,
        Option<i64>,
        Option<Datetime>,
        Option<VisibilitySettings<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Preferences<S> {
    /// Create a new builder for this type
    pub fn builder() -> PreferencesBuilder<preferences_state::Empty, S> {
        PreferencesBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> PreferencesBuilder<St, S>
where
    St: preferences_state::State,
    St::Activity: preferences_state::IsUnset,
{
    /// Set the `activity` field (required)
    pub fn activity(
        mut self,
        value: impl Into<ActivitySettings<S>>,
    ) -> PreferencesBuilder<preferences_state::SetActivity<St>, S> {
        self._fields.0 = Option::Some(value.into());
        PreferencesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: preferences_state::State, S: BosStr> PreferencesBuilder<St, S> {
    /// Set the `display` field (optional)
    pub fn display(mut self, value: impl Into<Option<DisplaySettings<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `display` field to an Option value (optional)
    pub fn maybe_display(mut self, value: Option<DisplaySettings<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> PreferencesBuilder<St, S>
where
    St: preferences_state::State,
    St::Notifications: preferences_state::IsUnset,
{
    /// Set the `notifications` field (required)
    pub fn notifications(
        mut self,
        value: impl Into<NotificationSettings<S>>,
    ) -> PreferencesBuilder<preferences_state::SetNotifications<St>, S> {
        self._fields.2 = Option::Some(value.into());
        PreferencesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PreferencesBuilder<St, S>
where
    St: preferences_state::State,
    St::Privacy: preferences_state::IsUnset,
{
    /// Set the `privacy` field (required)
    pub fn privacy(
        mut self,
        value: impl Into<PrivacySettings<S>>,
    ) -> PreferencesBuilder<preferences_state::SetPrivacy<St>, S> {
        self._fields.3 = Option::Some(value.into());
        PreferencesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: preferences_state::State, S: BosStr> PreferencesBuilder<St, S> {
    /// Set the `schemaVersion` field (optional)
    pub fn schema_version(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `schemaVersion` field to an Option value (optional)
    pub fn maybe_schema_version(mut self, value: Option<i64>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<St, S: BosStr> PreferencesBuilder<St, S>
where
    St: preferences_state::State,
    St::Visibility: preferences_state::IsUnset,
{
    /// Set the `visibility` field (required)
    pub fn visibility(
        mut self,
        value: impl Into<VisibilitySettings<S>>,
    ) -> PreferencesBuilder<preferences_state::SetVisibility<St>, S> {
        self._fields.6 = Option::Some(value.into());
        PreferencesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PreferencesBuilder<St, S>
where
    St: preferences_state::State,
    St::Activity: preferences_state::IsSet,
    St::Notifications: preferences_state::IsSet,
    St::Privacy: preferences_state::IsSet,
    St::UpdatedAt: preferences_state::IsSet,
    St::Visibility: preferences_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Preferences<S> {
        Preferences {
            activity: self._fields.0.unwrap(),
            display: self._fields.1,
            notifications: self._fields.2.unwrap(),
            privacy: self._fields.3.unwrap(),
            schema_version: self._fields.4.or_else(|| Some(1i64)),
            updated_at: self._fields.5.unwrap(),
            visibility: self._fields.6.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>>,
    ) -> Preferences<S> {
        Preferences {
            activity: self._fields.0.unwrap(),
            display: self._fields.1,
            notifications: self._fields.2.unwrap(),
            privacy: self._fields.3.unwrap(),
            schema_version: self._fields.4.or_else(|| Some(1i64)),
            updated_at: self._fields.5.unwrap(),
            visibility: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_social_showcase_profile_preferences() -> 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("social.showcase.profile.preferences"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static("User preferences and settings"),
                    ),
                    key: Some(CowStr::new_static("literal:self")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("visibility"),
                                SmolStr::new_static("activity"),
                                SmolStr::new_static("notifications"),
                                SmolStr::new_static("privacy"),
                                SmolStr::new_static("updatedAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("activity"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "social.showcase.defs#activitySettings",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("display"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "social.showcase.defs#displaySettings",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("notifications"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "social.showcase.defs#notificationSettings",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("privacy"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "social.showcase.defs#privacySettings",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("schemaVersion"),
                                LexObjectProperty::Integer(LexInteger {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("updatedAt"),
                                LexObjectProperty::String(LexString {
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("visibility"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static(
                                        "social.showcase.defs#visibilitySettings",
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}