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

pub mod get_valid_badges;


#[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;
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};
/// View of a badge record, with fields resolved for display. If the DID in issuer is not the current streamplace node, the signature field shall be required.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct BadgeView<'a> {
    #[serde(borrow)]
    pub badge_type: BadgeViewBadgeType<'a>,
    ///DID of the badge issuer.
    #[serde(borrow)]
    pub issuer: Did<'a>,
    ///DID of the badge recipient.
    #[serde(borrow)]
    pub recipient: Did<'a>,
    ///TODO: Cryptographic signature of the badge (of a place.stream.key).
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub signature: Option<CowStr<'a>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BadgeViewBadgeType<'a> {
    Mod,
    Streamer,
    Other(CowStr<'a>),
}

impl<'a> BadgeViewBadgeType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Mod => "place.stream.badge.defs#mod",
            Self::Streamer => "place.stream.badge.defs#streamer",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for BadgeViewBadgeType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "place.stream.badge.defs#mod" => Self::Mod,
            "place.stream.badge.defs#streamer" => Self::Streamer,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for BadgeViewBadgeType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "place.stream.badge.defs#mod" => Self::Mod,
            "place.stream.badge.defs#streamer" => Self::Streamer,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for BadgeViewBadgeType<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for BadgeViewBadgeType<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for BadgeViewBadgeType<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for BadgeViewBadgeType<'_> {
    type Output = BadgeViewBadgeType<'static>;
    fn into_static(self) -> Self::Output {
        match self {
            BadgeViewBadgeType::Mod => BadgeViewBadgeType::Mod,
            BadgeViewBadgeType::Streamer => BadgeViewBadgeType::Streamer,
            BadgeViewBadgeType::Other(v) => BadgeViewBadgeType::Other(v.into_static()),
        }
    }
}

/// This user is a moderator. Displayed with a sword icon.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Mod;
impl core::fmt::Display for Mod {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "mod")
    }
}

/// This user is the streamer. Displayed with a star icon.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Streamer;
impl core::fmt::Display for Streamer {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "streamer")
    }
}

/// This user is a very important person.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Hash)]
pub struct Vip;
impl core::fmt::Display for Vip {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "vip")
    }
}

impl<'a> LexiconSchema for BadgeView<'a> {
    fn nsid() -> &'static str {
        "place.stream.badge.defs"
    }
    fn def_name() -> &'static str {
        "badgeView"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_badge_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod badge_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 BadgeType;
        type Issuer;
        type Recipient;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type BadgeType = Unset;
        type Issuer = Unset;
        type Recipient = Unset;
    }
    ///State transition - sets the `badge_type` field to Set
    pub struct SetBadgeType<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetBadgeType<S> {}
    impl<S: State> State for SetBadgeType<S> {
        type BadgeType = Set<members::badge_type>;
        type Issuer = S::Issuer;
        type Recipient = S::Recipient;
    }
    ///State transition - sets the `issuer` field to Set
    pub struct SetIssuer<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetIssuer<S> {}
    impl<S: State> State for SetIssuer<S> {
        type BadgeType = S::BadgeType;
        type Issuer = Set<members::issuer>;
        type Recipient = S::Recipient;
    }
    ///State transition - sets the `recipient` field to Set
    pub struct SetRecipient<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRecipient<S> {}
    impl<S: State> State for SetRecipient<S> {
        type BadgeType = S::BadgeType;
        type Issuer = S::Issuer;
        type Recipient = Set<members::recipient>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `badge_type` field
        pub struct badge_type(());
        ///Marker type for the `issuer` field
        pub struct issuer(());
        ///Marker type for the `recipient` field
        pub struct recipient(());
    }
}

/// Builder for constructing an instance of this type
pub struct BadgeViewBuilder<'a, S: badge_view_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<BadgeViewBadgeType<'a>>,
        Option<Did<'a>>,
        Option<Did<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> BadgeView<'a> {
    /// Create a new builder for this type
    pub fn new() -> BadgeViewBuilder<'a, badge_view_state::Empty> {
        BadgeViewBuilder::new()
    }
}

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

impl<'a, S> BadgeViewBuilder<'a, S>
where
    S: badge_view_state::State,
    S::BadgeType: badge_view_state::IsUnset,
{
    /// Set the `badgeType` field (required)
    pub fn badge_type(
        mut self,
        value: impl Into<BadgeViewBadgeType<'a>>,
    ) -> BadgeViewBuilder<'a, badge_view_state::SetBadgeType<S>> {
        self._fields.0 = Option::Some(value.into());
        BadgeViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> BadgeViewBuilder<'a, S>
where
    S: badge_view_state::State,
    S::Issuer: badge_view_state::IsUnset,
{
    /// Set the `issuer` field (required)
    pub fn issuer(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> BadgeViewBuilder<'a, badge_view_state::SetIssuer<S>> {
        self._fields.1 = Option::Some(value.into());
        BadgeViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> BadgeViewBuilder<'a, S>
where
    S: badge_view_state::State,
    S::Recipient: badge_view_state::IsUnset,
{
    /// Set the `recipient` field (required)
    pub fn recipient(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> BadgeViewBuilder<'a, badge_view_state::SetRecipient<S>> {
        self._fields.2 = Option::Some(value.into());
        BadgeViewBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: badge_view_state::State> BadgeViewBuilder<'a, S> {
    /// Set the `signature` field (optional)
    pub fn signature(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `signature` field to an Option value (optional)
    pub fn maybe_signature(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> BadgeViewBuilder<'a, S>
where
    S: badge_view_state::State,
    S::BadgeType: badge_view_state::IsSet,
    S::Issuer: badge_view_state::IsSet,
    S::Recipient: badge_view_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> BadgeView<'a> {
        BadgeView {
            badge_type: self._fields.0.unwrap(),
            issuer: self._fields.1.unwrap(),
            recipient: self._fields.2.unwrap(),
            signature: self._fields.3,
            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>,
        >,
    ) -> BadgeView<'a> {
        BadgeView {
            badge_type: self._fields.0.unwrap(),
            issuer: self._fields.1.unwrap(),
            recipient: self._fields.2.unwrap(),
            signature: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_place_stream_badge_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("place.stream.badge.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("badgeView"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "View of a badge record, with fields resolved for display. If the DID in issuer is not the current streamplace node, the signature field shall be required.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("badgeType"),
                            SmolStr::new_static("issuer"),
                            SmolStr::new_static("recipient")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("badgeType"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("issuer"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("DID of the badge issuer."),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("recipient"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("DID of the badge recipient."),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("signature"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "TODO: Cryptographic signature of the badge (of a place.stream.key).",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("mod"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("streamer"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("vip"),
                LexUserType::Token(LexToken { ..Default::default() }),
            );
            map
        },
        ..Default::default()
    }
}