#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::deps::bytes::Bytes;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::Datetime;
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};
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Attestation<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
pub attested_at: Option<Datetime>,
#[serde(borrow)]
pub key: CowStr<'a>,
#[serde(with = "jacquard_common::serde_bytes_helper")]
pub signature: Bytes,
}
impl<'a> LexiconSchema for Attestation<'a> {
fn nsid() -> &'static str {
"blue.atplay.score.defs"
}
fn def_name() -> &'static str {
"attestation"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_blue_atplay_score_defs()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.key;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 512usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("key"),
max: 512usize,
actual: <str>::len(value.as_ref()),
});
}
}
Ok(())
}
}
pub mod attestation_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Signature;
type Key;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Signature = Unset;
type Key = Unset;
}
pub struct SetSignature<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSignature<S> {}
impl<S: State> State for SetSignature<S> {
type Signature = Set<members::signature>;
type Key = S::Key;
}
pub struct SetKey<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetKey<S> {}
impl<S: State> State for SetKey<S> {
type Signature = S::Signature;
type Key = Set<members::key>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct signature(());
pub struct key(());
}
}
pub struct AttestationBuilder<'a, S: attestation_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (Option<Datetime>, Option<CowStr<'a>>, Option<Bytes>),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Attestation<'a> {
pub fn new() -> AttestationBuilder<'a, attestation_state::Empty> {
AttestationBuilder::new()
}
}
impl<'a> AttestationBuilder<'a, attestation_state::Empty> {
pub fn new() -> Self {
AttestationBuilder {
_state: PhantomData,
_fields: (None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S: attestation_state::State> AttestationBuilder<'a, S> {
pub fn attested_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_attested_at(mut self, value: Option<Datetime>) -> Self {
self._fields.0 = value;
self
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::Key: attestation_state::IsUnset,
{
pub fn key(
mut self,
value: impl Into<CowStr<'a>>,
) -> AttestationBuilder<'a, attestation_state::SetKey<S>> {
self._fields.1 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::Signature: attestation_state::IsUnset,
{
pub fn signature(
mut self,
value: impl Into<Bytes>,
) -> AttestationBuilder<'a, attestation_state::SetSignature<S>> {
self._fields.2 = Option::Some(value.into());
AttestationBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> AttestationBuilder<'a, S>
where
S: attestation_state::State,
S::Signature: attestation_state::IsSet,
S::Key: attestation_state::IsSet,
{
pub fn build(self) -> Attestation<'a> {
Attestation {
attested_at: self._fields.0,
key: self._fields.1.unwrap(),
signature: self._fields.2.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Attestation<'a> {
Attestation {
attested_at: self._fields.0,
key: self._fields.1.unwrap(),
signature: self._fields.2.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_blue_atplay_score_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.atplay.score.defs"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attestation"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Attestation signature proving a score was submitted through ATPlay SDK",
),
),
required: Some(
vec![
SmolStr::new_static("key"), SmolStr::new_static("signature")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("attestedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Timestamp when the attestation was created (optional)",
),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("key"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"DID key reference for verifying the signature",
),
),
max_length: Some(512usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signature"),
LexObjectProperty::Bytes(LexBytes {
max_length: Some(8192usize),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}