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

//! Generated bindings for the `blue.recipes.actor` Lexicon namespace/module.
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::blob::BlobRef;
use jacquard_common::types::string::{Did, Handle};
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};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ProfileViewBasic<S: BosStr = DefaultStr> {
    ///Small image to be displayed on the profile.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar: Option<BlobRef<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<S>,
    pub did: Did<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub display_name: Option<S>,
    pub handle: Handle<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pronouns: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for ProfileViewBasic<S> {
    fn nsid() -> &'static str {
        "blue.recipes.actor.defs"
    }
    fn def_name() -> &'static str {
        "profileViewBasic"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_blue_recipes_actor_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.avatar {
            {
                let size = value.blob().size;
                if size > 1000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("avatar"),
                        max: 1000000usize,
                        actual: size,
                    });
                }
            }
        }
        if let Some(ref value) = self.avatar {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &["image/png", "image/jpeg"];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("avatar"),
                        accepted: vec![
                            "image/png".to_string(), "image/jpeg".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        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_basic_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;
    }
    /// 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;
    }
    ///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;
    }
    ///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>;
    }
    /// 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(());
    }
}

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

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

impl<S: BosStr> ProfileViewBasic<S> {
    /// Create a new builder for this type
    pub fn builder() -> ProfileViewBasicBuilder<profile_view_basic_state::Empty, S> {
        ProfileViewBasicBuilder::builder()
    }
}

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

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

impl<St: profile_view_basic_state::State, S: BosStr> ProfileViewBasicBuilder<St, S> {
    /// Set the `avatar` field (optional)
    pub fn avatar(mut self, value: impl Into<Option<BlobRef<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<BlobRef<S>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: profile_view_basic_state::State, S: BosStr> ProfileViewBasicBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<S>>) -> 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<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<St: profile_view_basic_state::State, S: BosStr> ProfileViewBasicBuilder<St, S> {
    /// Set the `displayName` field (optional)
    pub fn display_name(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.3 = 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.3 = value;
        self
    }
}

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

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

impl<St, S: BosStr> ProfileViewBasicBuilder<St, S>
where
    St: profile_view_basic_state::State,
    St::Did: profile_view_basic_state::IsSet,
    St::Handle: profile_view_basic_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> ProfileViewBasic<S> {
        ProfileViewBasic {
            avatar: self._fields.0,
            created_at: self._fields.1,
            did: self._fields.2.unwrap(),
            display_name: self._fields.3,
            handle: self._fields.4.unwrap(),
            pronouns: self._fields.5,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> ProfileViewBasic<S> {
        ProfileViewBasic {
            avatar: self._fields.0,
            created_at: self._fields.1,
            did: self._fields.2.unwrap(),
            display_name: self._fields.3,
            handle: self._fields.4.unwrap(),
            pronouns: self._fields.5,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_blue_recipes_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("blue.recipes.actor.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("profileViewBasic"),
                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::Blob(LexBlob { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            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 {
                                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("pronouns"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}