pub mod get_valid_badges;
#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{BosStr, CowStr, 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;
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::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct BadgeView<S: BosStr = DefaultStr> {
pub badge_type: BadgeViewBadgeType<S>,
pub issuer: Did<S>,
pub recipient: Did<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signature: Option<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum BadgeViewBadgeType<S: BosStr = DefaultStr> {
Mod,
Streamer,
Other(S),
}
impl<S: BosStr> BadgeViewBadgeType<S> {
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(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"place.stream.badge.defs#mod" => Self::Mod,
"place.stream.badge.defs#streamer" => Self::Streamer,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for BadgeViewBadgeType<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for BadgeViewBadgeType<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for BadgeViewBadgeType<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 BadgeViewBadgeType<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 BadgeViewBadgeType<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for BadgeViewBadgeType<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = BadgeViewBadgeType<S::Output>;
fn into_static(self) -> Self::Output {
match self {
BadgeViewBadgeType::Mod => BadgeViewBadgeType::Mod,
BadgeViewBadgeType::Streamer => BadgeViewBadgeType::Streamer,
BadgeViewBadgeType::Other(v) => BadgeViewBadgeType::Other(v.into_static()),
}
}
}
#[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")
}
}
#[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")
}
}
#[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<S: BosStr> LexiconSchema for BadgeView<S> {
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::{IsSet, IsUnset, Set, Unset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Recipient;
type Issuer;
type BadgeType;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Recipient = Unset;
type Issuer = Unset;
type BadgeType = Unset;
}
pub struct SetRecipient<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetRecipient<St> {}
impl<St: State> State for SetRecipient<St> {
type Recipient = Set<members::recipient>;
type Issuer = St::Issuer;
type BadgeType = St::BadgeType;
}
pub struct SetIssuer<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetIssuer<St> {}
impl<St: State> State for SetIssuer<St> {
type Recipient = St::Recipient;
type Issuer = Set<members::issuer>;
type BadgeType = St::BadgeType;
}
pub struct SetBadgeType<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetBadgeType<St> {}
impl<St: State> State for SetBadgeType<St> {
type Recipient = St::Recipient;
type Issuer = St::Issuer;
type BadgeType = Set<members::badge_type>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct recipient(());
pub struct issuer(());
pub struct badge_type(());
}
}
pub struct BadgeViewBuilder<S: BosStr, St: badge_view_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<BadgeViewBadgeType<S>>,
Option<Did<S>>,
Option<Did<S>>,
Option<S>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> BadgeView<S> {
pub fn new() -> BadgeViewBuilder<S, badge_view_state::Empty> {
BadgeViewBuilder::new()
}
}
impl<S: BosStr> BadgeViewBuilder<S, badge_view_state::Empty> {
pub fn new() -> Self {
BadgeViewBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BadgeViewBuilder<S, St>
where
St: badge_view_state::State,
St::BadgeType: badge_view_state::IsUnset,
{
pub fn badge_type(
mut self,
value: impl Into<BadgeViewBadgeType<S>>,
) -> BadgeViewBuilder<S, badge_view_state::SetBadgeType<St>> {
self._fields.0 = Option::Some(value.into());
BadgeViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BadgeViewBuilder<S, St>
where
St: badge_view_state::State,
St::Issuer: badge_view_state::IsUnset,
{
pub fn issuer(
mut self,
value: impl Into<Did<S>>,
) -> BadgeViewBuilder<S, badge_view_state::SetIssuer<St>> {
self._fields.1 = Option::Some(value.into());
BadgeViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> BadgeViewBuilder<S, St>
where
St: badge_view_state::State,
St::Recipient: badge_view_state::IsUnset,
{
pub fn recipient(
mut self,
value: impl Into<Did<S>>,
) -> BadgeViewBuilder<S, badge_view_state::SetRecipient<St>> {
self._fields.2 = Option::Some(value.into());
BadgeViewBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: badge_view_state::State> BadgeViewBuilder<S, St> {
pub fn signature(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_signature(mut self, value: Option<S>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> BadgeViewBuilder<S, St>
where
St: badge_view_state::State,
St::Recipient: badge_view_state::IsSet,
St::Issuer: badge_view_state::IsSet,
St::BadgeType: badge_view_state::IsSet,
{
pub fn build(self) -> BadgeView<S> {
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(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> BadgeView<S> {
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> {
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
use jacquard_lexicon::lexicon::*;
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()
}
}