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

//! Generated bindings for the `space.polymodel.actor` Lexicon namespace/module.
pub mod get_profile;
pub mod get_session;
pub mod profile;


#[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, Datetime, UriValue};
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};
use crate::app_bsky::actor::ProfileViewDetailed;
use crate::space_polymodel::actor;
/// Polymodel actor profile view (union variant). Hydrated from the space.polymodel.actor.profile record plus SQLite-derived stats (thingCount, totalLikes). Returned when the actor authored a polymodel profile record; otherwise getProfile returns the app.bsky.actor.defs#profileViewDetailed variant.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ProfileView<S: BosStr = DefaultStr> {
    ///Resolved avatar URL (CDN). Null until the app view resolves the polymodel profile avatar blob.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<UriValue<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default_license: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    pub did: Did<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_name: Option<S>,
    pub handle: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub indexed_at: Option<Datetime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub links: Option<Vec<UriValue<S>>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub printers: Option<Vec<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pronouns: Option<S>,
    ///The raw space.polymodel.actor.profile record.
    pub record: Data<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thing_count: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_likes: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

///Discriminates a polymodel-native actor (space.polymodel.actor.defs#profileView, hydrated from the local profile record + stats) from a bluesky-only actor (app.bsky.actor.defs#profileViewDetailed, fetched from the public AppView). Clients render based on $type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum ProfileViewUnion<S: BosStr = DefaultStr> {
    #[serde(rename = "space.polymodel.actor.defs#profileView")]
    ProfileView(Box<actor::ProfileView<S>>),
    #[serde(rename = "app.bsky.actor.defs#profileViewDetailed")]
    ProfileViewDetailed(Box<ProfileViewDetailed<S>>),
}

impl<S: BosStr> LexiconSchema for ProfileView<S> {
    fn nsid() -> &'static str {
        "space.polymodel.actor.defs"
    }
    fn def_name() -> &'static str {
        "profileView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_space_polymodel_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 Handle;
        type Record;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Did = Unset;
        type Handle = Unset;
        type Record = 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 Handle = St::Handle;
        type Record = St::Record;
    }
    ///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 Handle = Set<members::handle>;
        type Record = St::Record;
    }
    ///State transition - sets the `record` field to Set
    pub struct SetRecord<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRecord<St> {}
    impl<St: State> State for SetRecord<St> {
        type Did = St::Did;
        type Handle = St::Handle;
        type Record = Set<members::record>;
    }
    /// 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 `handle` field
        pub struct handle(());
        ///Marker type for the `record` field
        pub struct record(());
    }
}

/// 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<S>,
        Option<S>,
        Option<Did<S>>,
        Option<S>,
        Option<S>,
        Option<Datetime>,
        Option<Vec<UriValue<S>>>,
        Option<Vec<S>>,
        Option<S>,
        Option<Data<S>>,
        Option<i64>,
        Option<i64>,
    ),
    _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,
                None,
                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,
                None,
                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 `defaultLicense` field (optional)
    pub fn default_license(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `defaultLicense` field to an Option value (optional)
    pub fn maybe_default_license(mut self, value: Option<S>) -> 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: profile_view_state::State, S: BosStr> ProfileViewBuilder<St, S> {
    /// Set the `displayName` field (optional)
    pub fn display_name(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `displayName` field to an Option value (optional)
    pub fn maybe_display_name(mut self, value: Option<S>) -> Self {
        self._fields.4 = value;
        self
    }
}

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<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: profile_view_state::State, S: BosStr> ProfileViewBuilder<St, S> {
    /// Set the `indexedAt` field (optional)
    pub fn indexed_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `indexedAt` field to an Option value (optional)
    pub fn maybe_indexed_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

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

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

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

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

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

impl<St, S: BosStr> ProfileViewBuilder<St, S>
where
    St: profile_view_state::State,
    St::Did: profile_view_state::IsSet,
    St::Handle: profile_view_state::IsSet,
    St::Record: profile_view_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ProfileView<S> {
        ProfileView {
            avatar: self._fields.0,
            default_license: self._fields.1,
            description: self._fields.2,
            did: self._fields.3.unwrap(),
            display_name: self._fields.4,
            handle: self._fields.5.unwrap(),
            indexed_at: self._fields.6,
            links: self._fields.7,
            printers: self._fields.8,
            pronouns: self._fields.9,
            record: self._fields.10.unwrap(),
            thing_count: self._fields.11,
            total_likes: self._fields.12,
            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,
            default_license: self._fields.1,
            description: self._fields.2,
            did: self._fields.3.unwrap(),
            display_name: self._fields.4,
            handle: self._fields.5.unwrap(),
            indexed_at: self._fields.6,
            links: self._fields.7,
            printers: self._fields.8,
            pronouns: self._fields.9,
            record: self._fields.10.unwrap(),
            thing_count: self._fields.11,
            total_likes: self._fields.12,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_space_polymodel_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("space.polymodel.actor.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("profileView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Polymodel actor profile view (union variant). Hydrated from the space.polymodel.actor.profile record plus SQLite-derived stats (thingCount, totalLikes). Returned when the actor authored a polymodel profile record; otherwise getProfile returns the app.bsky.actor.defs#profileViewDetailed variant.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("did"), SmolStr::new_static("handle"),
                            SmolStr::new_static("record")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("avatar"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Resolved avatar URL (CDN). Null until the app view resolves the polymodel profile avatar blob.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("defaultLicense"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("displayName"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("indexedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("links"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::String(LexString {
                                    format: Some(LexStringFormat::Uri),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("printers"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("pronouns"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("record"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("thingCount"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("totalLikes"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("profileViewUnion"),
                LexUserType::Union(LexRefUnion {
                    refs: vec![
                        CowStr::new_static("space.polymodel.actor.defs#profileView"),
                        CowStr::new_static("app.bsky.actor.defs#profileViewDetailed")
                    ],
                    closed: Some(true),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}