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

pub mod profile;


#[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::{Did, Handle, Datetime, UriValue};
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::com_atproto::label::Label;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ProfileView<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub avatar: Option<UriValue<'a>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub did: Did<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub display_name: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub handle: Handle<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub labels: Option<Vec<Label<'a>>>,
}

impl<'a> LexiconSchema for ProfileView<'a> {
    fn nsid() -> &'static str {
        "social.grain.actor.defs"
    }
    fn def_name() -> &'static str {
        "profileView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_social_grain_actor_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 2560usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 2560usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.description {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 256usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("description"),
                        max: 256usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref 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()),
                });
            }
        }
        if let Some(ref 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(())
    }
}

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

/// Builder for constructing an instance of this type
pub struct ProfileViewBuilder<'a, S: profile_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<UriValue<'a>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
        Option<Did<'a>>,
        Option<CowStr<'a>>,
        Option<Handle<'a>>,
        Option<Vec<Label<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: profile_view_state::State> ProfileViewBuilder<'a, S> {
    /// Set the `avatar` field (optional)
    pub fn avatar(mut self, value: impl Into<Option<UriValue<'a>>>) -> 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<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: profile_view_state::State> ProfileViewBuilder<'a, 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<'a, S: profile_view_state::State> ProfileViewBuilder<'a, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.2 = value;
        self
    }
}

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

impl<'a, S: profile_view_state::State> ProfileViewBuilder<'a, S> {
    /// Set the `displayName` field (optional)
    pub fn display_name(mut self, value: impl Into<Option<CowStr<'a>>>) -> 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<CowStr<'a>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

impl<'a, S: profile_view_state::State> ProfileViewBuilder<'a, S> {
    /// Set the `labels` field (optional)
    pub fn labels(mut self, value: impl Into<Option<Vec<Label<'a>>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `labels` field to an Option value (optional)
    pub fn maybe_labels(mut self, value: Option<Vec<Label<'a>>>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

fn lexicon_doc_social_grain_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.grain.actor.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("profileView"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("did"), SmolStr::new_static("handle")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("avatar"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(2560usize),
                                max_graphemes: Some(256usize),
                                ..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 {
                                max_length: Some(640usize),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("handle"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Handle),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("labels"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.label.defs#label"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}