jacquard-api 0.11.0

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: blue.atplay.score.defs
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[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};
/// Attestation signature proving a score was submitted through ATPlay SDK

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Attestation<'a> {
    ///Timestamp when the attestation was created (optional)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attested_at: Option<Datetime>,
    ///DID key reference for verifying the signature
    #[serde(borrow)]
    pub key: CowStr<'a>,
    ///ES256 signature over the score record CID
    #[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 {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type Signature;
        type Key;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Signature = Unset;
        type Key = Unset;
    }
    ///State transition - sets the `signature` field to Set
    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;
    }
    ///State transition - sets the `key` field to Set
    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>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `signature` field
        pub struct signature(());
        ///Marker type for the `key` field
        pub struct key(());
    }
}

/// Builder for constructing an instance of this type
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> {
    /// Create a new builder for this type
    pub fn new() -> AttestationBuilder<'a, attestation_state::Empty> {
        AttestationBuilder::new()
    }
}

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

impl<'a, S: attestation_state::State> AttestationBuilder<'a, S> {
    /// Set the `attestedAt` field (optional)
    pub fn attested_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `attestedAt` field to an Option value (optional)
    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,
{
    /// Set the `key` field (required)
    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,
{
    /// Set the `signature` field (required)
    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,
{
    /// Build the final struct
    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(),
        }
    }
    /// 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>,
        >,
    ) -> 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()
    }
}