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

//! Generated bindings for the `social.clippr.actor` Lexicon namespace/module.
pub mod get_preferences;
pub mod get_profile;
pub mod profile;
pub mod put_preferences;
pub mod search_clips;
pub mod search_profiles;
pub mod search_tags;


#[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::{Did, Handle, Datetime, UriValue};
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
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_clippr::actor;

#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum PreferencesItem<S: BosStr = DefaultStr> {
    #[serde(rename = "social.clippr.actor.defs#publishingScopesPref")]
    PublishingScopesPref(Box<actor::PublishingScopesPref<S>>),
}

/// An array of refs to various preferences.
pub type Preferences<S = DefaultStr> = Vec<PreferencesItem<S>>;
/// A view of an actor's profile.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ProfileView<S: BosStr = DefaultStr> {
    ///A link to the profile's avatar
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<UriValue<S>>,
    ///When the profile record was first created
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    ///The biography associated to the profile
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///The DID of the profile
    pub did: Did<S>,
    ///The display name associated to the profile
    pub display_name: S,
    ///The handle of the profile
    pub handle: Handle<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Preferences for an user's publishing scopes.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct PublishingScopesPref<S: BosStr = DefaultStr> {
    ///What publishing scope to mark a clip as by default
    pub default_scope: PublishingScopesPrefDefaultScope<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// What publishing scope to mark a clip as by default

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum PublishingScopesPrefDefaultScope<S: BosStr = DefaultStr> {
    Public,
    Unlisted,
    Other(S),
}

impl<S: BosStr> PublishingScopesPrefDefaultScope<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Public => "public",
            Self::Unlisted => "unlisted",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "public" => Self::Public,
            "unlisted" => Self::Unlisted,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for PublishingScopesPrefDefaultScope<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for PublishingScopesPrefDefaultScope<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for PublishingScopesPrefDefaultScope<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
for PublishingScopesPrefDefaultScope<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for PublishingScopesPrefDefaultScope<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for PublishingScopesPrefDefaultScope<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = PublishingScopesPrefDefaultScope<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            PublishingScopesPrefDefaultScope::Public => {
                PublishingScopesPrefDefaultScope::Public
            }
            PublishingScopesPrefDefaultScope::Unlisted => {
                PublishingScopesPrefDefaultScope::Unlisted
            }
            PublishingScopesPrefDefaultScope::Other(v) => {
                PublishingScopesPrefDefaultScope::Other(v.into_static())
            }
        }
    }
}

impl<S: BosStr> LexiconSchema for ProfileView<S> {
    fn nsid() -> &'static str {
        "social.clippr.actor.defs"
    }
    fn def_name() -> &'static str {
        "profileView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_social_clippr_actor_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 5000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 5000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.description {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 500usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("description"),
                        max: 500usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.display_name;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 640usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("display_name"),
                    max: 640usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.display_name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("display_name"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for PublishingScopesPref<S> {
    fn nsid() -> &'static str {
        "social.clippr.actor.defs"
    }
    fn def_name() -> &'static str {
        "publishingScopesPref"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_social_clippr_actor_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod profile_view_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 Did;
        type DisplayName;
        type Handle;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Did = Unset;
        type DisplayName = Unset;
        type Handle = Unset;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDid<St> {}
    impl<St: State> State for SetDid<St> {
        type Did = Set<members::did>;
        type DisplayName = St::DisplayName;
        type Handle = St::Handle;
    }
    ///State transition - sets the `display_name` field to Set
    pub struct SetDisplayName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDisplayName<St> {}
    impl<St: State> State for SetDisplayName<St> {
        type Did = St::Did;
        type DisplayName = Set<members::display_name>;
        type Handle = St::Handle;
    }
    ///State transition - sets the `handle` field to Set
    pub struct SetHandle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetHandle<St> {}
    impl<St: State> State for SetHandle<St> {
        type Did = St::Did;
        type DisplayName = St::DisplayName;
        type Handle = Set<members::handle>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `display_name` field
        pub struct display_name(());
        ///Marker type for the `handle` field
        pub struct handle(());
    }
}

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

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

impl<S: BosStr> ProfileView<S> {
    /// Create a new builder for this type
    pub fn builder() -> ProfileViewBuilder<profile_view_state::Empty, S> {
        ProfileViewBuilder::builder()
    }
}

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

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

impl<St: profile_view_state::State, S: BosStr> ProfileViewBuilder<St, S> {
    /// Set the `avatar` field (optional)
    pub fn avatar(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `avatar` field to an Option value (optional)
    pub fn maybe_avatar(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: profile_view_state::State, S: BosStr> ProfileViewBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `createdAt` field to an Option value (optional)
    pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: profile_view_state::State, S: BosStr> ProfileViewBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<S>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> ProfileViewBuilder<St, S>
where
    St: profile_view_state::State,
    St::Did: profile_view_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> ProfileViewBuilder<profile_view_state::SetDid<St>, S> {
        self._fields.3 = Option::Some(value.into());
        ProfileViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ProfileViewBuilder<St, S>
where
    St: profile_view_state::State,
    St::DisplayName: profile_view_state::IsUnset,
{
    /// Set the `displayName` field (required)
    pub fn display_name(
        mut self,
        value: impl Into<S>,
    ) -> ProfileViewBuilder<profile_view_state::SetDisplayName<St>, S> {
        self._fields.4 = Option::Some(value.into());
        ProfileViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ProfileViewBuilder<St, S>
where
    St: profile_view_state::State,
    St::Handle: profile_view_state::IsUnset,
{
    /// Set the `handle` field (required)
    pub fn handle(
        mut self,
        value: impl Into<Handle<S>>,
    ) -> ProfileViewBuilder<profile_view_state::SetHandle<St>, S> {
        self._fields.5 = Option::Some(value.into());
        ProfileViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ProfileViewBuilder<St, S>
where
    St: profile_view_state::State,
    St::Did: profile_view_state::IsSet,
    St::DisplayName: profile_view_state::IsSet,
    St::Handle: profile_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ProfileView<S> {
        ProfileView {
            avatar: self._fields.0,
            created_at: self._fields.1,
            description: self._fields.2,
            did: self._fields.3.unwrap(),
            display_name: self._fields.4.unwrap(),
            handle: self._fields.5.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>>,
    ) -> ProfileView<S> {
        ProfileView {
            avatar: self._fields.0,
            created_at: self._fields.1,
            description: self._fields.2,
            did: self._fields.3.unwrap(),
            display_name: self._fields.4.unwrap(),
            handle: self._fields.5.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_social_clippr_actor_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("social.clippr.actor.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("preferences"),
                LexUserType::Array(LexArray {
                    items: LexArrayItem::Union(LexRefUnion {
                        refs: vec![CowStr::new_static("#publishingScopesPref")],
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("profileView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A view of an actor's profile."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("did"), SmolStr::new_static("handle"),
                            SmolStr::new_static("displayName")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("avatar"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("A link to the profile's avatar"),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "When the profile record was first created",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The biography associated to the profile",
                                    ),
                                ),
                                max_length: Some(5000usize),
                                max_graphemes: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The DID of the profile"),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("displayName"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The display name associated to the profile",
                                    ),
                                ),
                                max_length: Some(640usize),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The handle of the profile"),
                                ),
                                format: Some(LexStringFormat::Handle),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("publishingScopesPref"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Preferences for an user's publishing scopes.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("defaultScope")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("defaultScope"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "What publishing scope to mark a clip as by default",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}