#[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::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;
use crate::net_anisota::chronicle::progress;
#[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 ChronicleSignature<S: BosStr = DefaultStr> {
pub alg: S,
pub kid: S,
pub nonce: S,
pub sig: S,
pub signed_at: Datetime,
pub version: i64,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "net.anisota.chronicle.progress",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Progress<S: BosStr = DefaultStr> {
pub created_at: Datetime,
pub level: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub progress_percentage: Option<S>,
pub signature: progress::ChronicleSignature<S>,
pub total_xp: i64,
#[serde(skip_serializing_if = "Option::is_none")]
pub trigger_source: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub updated_at: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
pub xp_gained_since_last_sign: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub xp_to_next_level: Option<i64>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct ProgressGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Progress<S>,
}
impl<S: BosStr> Progress<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, ProgressRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for ChronicleSignature<S> {
fn nsid() -> &'static str {
"net.anisota.chronicle.progress"
}
fn def_name() -> &'static str {
"chronicleSignature"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_chronicle_progress()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ProgressRecord;
impl XrpcResp for ProgressRecord {
const NSID: &'static str = "net.anisota.chronicle.progress";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = ProgressGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<ProgressGetRecordOutput<S>> for Progress<S> {
fn from(output: ProgressGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Progress<S> {
const NSID: &'static str = "net.anisota.chronicle.progress";
type Record = ProgressRecord;
}
impl Collection for ProgressRecord {
const NSID: &'static str = "net.anisota.chronicle.progress";
type Record = ProgressRecord;
}
impl<S: BosStr> LexiconSchema for Progress<S> {
fn nsid() -> &'static str {
"net.anisota.chronicle.progress"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_chronicle_progress()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.level;
if *value > 99i64 {
return Err(ConstraintError::Maximum {
path: ValidationPath::from_field("level"),
max: 99i64,
actual: *value,
});
}
}
{
let value = &self.level;
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("level"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.total_xp;
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("total_xp"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.xp_gained_since_last_sign {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("xp_gained_since_last_sign"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.xp_to_next_level {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("xp_to_next_level"),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
pub mod chronicle_signature_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 Alg;
type Kid;
type Nonce;
type Sig;
type SignedAt;
type Version;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Alg = Unset;
type Kid = Unset;
type Nonce = Unset;
type Sig = Unset;
type SignedAt = Unset;
type Version = Unset;
}
pub struct SetAlg<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetAlg<St> {}
impl<St: State> State for SetAlg<St> {
type Alg = Set<members::alg>;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetKid<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetKid<St> {}
impl<St: State> State for SetKid<St> {
type Alg = St::Alg;
type Kid = Set<members::kid>;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetNonce<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetNonce<St> {}
impl<St: State> State for SetNonce<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = Set<members::nonce>;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetSig<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSig<St> {}
impl<St: State> State for SetSig<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = Set<members::sig>;
type SignedAt = St::SignedAt;
type Version = St::Version;
}
pub struct SetSignedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSignedAt<St> {}
impl<St: State> State for SetSignedAt<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = Set<members::signed_at>;
type Version = St::Version;
}
pub struct SetVersion<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetVersion<St> {}
impl<St: State> State for SetVersion<St> {
type Alg = St::Alg;
type Kid = St::Kid;
type Nonce = St::Nonce;
type Sig = St::Sig;
type SignedAt = St::SignedAt;
type Version = Set<members::version>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct alg(());
pub struct kid(());
pub struct nonce(());
pub struct sig(());
pub struct signed_at(());
pub struct version(());
}
}
pub struct ChronicleSignatureBuilder<St: chronicle_signature_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<S>,
Option<S>,
Option<S>,
Option<S>,
Option<Datetime>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl ChronicleSignature<DefaultStr> {
pub fn new() -> ChronicleSignatureBuilder<chronicle_signature_state::Empty, DefaultStr> {
ChronicleSignatureBuilder::new()
}
}
impl<S: BosStr> ChronicleSignature<S> {
pub fn builder() -> ChronicleSignatureBuilder<chronicle_signature_state::Empty, S> {
ChronicleSignatureBuilder::builder()
}
}
impl ChronicleSignatureBuilder<chronicle_signature_state::Empty, DefaultStr> {
pub fn new() -> Self {
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> ChronicleSignatureBuilder<chronicle_signature_state::Empty, S> {
pub fn builder() -> Self {
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Alg: chronicle_signature_state::IsUnset,
{
pub fn alg(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetAlg<St>, S> {
self._fields.0 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Kid: chronicle_signature_state::IsUnset,
{
pub fn kid(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetKid<St>, S> {
self._fields.1 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Nonce: chronicle_signature_state::IsUnset,
{
pub fn nonce(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetNonce<St>, S> {
self._fields.2 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Sig: chronicle_signature_state::IsUnset,
{
pub fn sig(
mut self,
value: impl Into<S>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetSig<St>, S> {
self._fields.3 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::SignedAt: chronicle_signature_state::IsUnset,
{
pub fn signed_at(
mut self,
value: impl Into<Datetime>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetSignedAt<St>, S> {
self._fields.4 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Version: chronicle_signature_state::IsUnset,
{
pub fn version(
mut self,
value: impl Into<i64>,
) -> ChronicleSignatureBuilder<chronicle_signature_state::SetVersion<St>, S> {
self._fields.5 = Option::Some(value.into());
ChronicleSignatureBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ChronicleSignatureBuilder<St, S>
where
St: chronicle_signature_state::State,
St::Alg: chronicle_signature_state::IsSet,
St::Kid: chronicle_signature_state::IsSet,
St::Nonce: chronicle_signature_state::IsSet,
St::Sig: chronicle_signature_state::IsSet,
St::SignedAt: chronicle_signature_state::IsSet,
St::Version: chronicle_signature_state::IsSet,
{
pub fn build(self) -> ChronicleSignature<S> {
ChronicleSignature {
alg: self._fields.0.unwrap(),
kid: self._fields.1.unwrap(),
nonce: self._fields.2.unwrap(),
sig: self._fields.3.unwrap(),
signed_at: self._fields.4.unwrap(),
version: self._fields.5.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> ChronicleSignature<S> {
ChronicleSignature {
alg: self._fields.0.unwrap(),
kid: self._fields.1.unwrap(),
nonce: self._fields.2.unwrap(),
sig: self._fields.3.unwrap(),
signed_at: self._fields.4.unwrap(),
version: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_chronicle_progress() -> 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("net.anisota.chronicle.progress"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("chronicleSignature"),
LexUserType::Object(LexObject {
description: Some(CowStr::new_static(
"ES256 cryptographic signature proving record authenticity",
)),
required: Some(vec![
SmolStr::new_static("sig"),
SmolStr::new_static("alg"),
SmolStr::new_static("kid"),
SmolStr::new_static("signedAt"),
SmolStr::new_static("nonce"),
SmolStr::new_static("version"),
]),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("alg"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("Signing algorithm (ES256)")),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("kid"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Key identifier for the signing key",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("nonce"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Unique random nonce to prevent replay",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sig"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static(
"Base64-encoded ES256 signature",
)),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signedAt"),
LexObjectProperty::String(LexString {
description: Some(CowStr::new_static("When the record was signed")),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("version"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Signed player progression state. Singleton (rkey: self), overwritten via putRecord. Backend validates XP claims before signing.",
),
),
key: Some(CowStr::new_static("any")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("totalXP"),
SmolStr::new_static("level"),
SmolStr::new_static("signature"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the record was first created"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("level"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
maximum: Some(99i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("progressPercentage"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Progress toward next level as decimal string",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signature"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#chronicleSignature"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("totalXP"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("triggerSource"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"What triggered this save (level_up, session_end, visibility_hidden, periodic, card_advance)",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("updatedAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the record was last updated"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("xpGainedSinceLastSign"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("xpToNextLevel"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
pub mod progress_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 CreatedAt;
type Level;
type Signature;
type TotalXp;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Level = Unset;
type Signature = Unset;
type TotalXp = Unset;
}
pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
impl<St: State> State for SetCreatedAt<St> {
type CreatedAt = Set<members::created_at>;
type Level = St::Level;
type Signature = St::Signature;
type TotalXp = St::TotalXp;
}
pub struct SetLevel<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetLevel<St> {}
impl<St: State> State for SetLevel<St> {
type CreatedAt = St::CreatedAt;
type Level = Set<members::level>;
type Signature = St::Signature;
type TotalXp = St::TotalXp;
}
pub struct SetSignature<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetSignature<St> {}
impl<St: State> State for SetSignature<St> {
type CreatedAt = St::CreatedAt;
type Level = St::Level;
type Signature = Set<members::signature>;
type TotalXp = St::TotalXp;
}
pub struct SetTotalXp<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetTotalXp<St> {}
impl<St: State> State for SetTotalXp<St> {
type CreatedAt = St::CreatedAt;
type Level = St::Level;
type Signature = St::Signature;
type TotalXp = Set<members::total_xp>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct level(());
pub struct signature(());
pub struct total_xp(());
}
}
pub struct ProgressBuilder<St: progress_state::State, S: BosStr = DefaultStr> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<i64>,
Option<S>,
Option<progress::ChronicleSignature<S>>,
Option<i64>,
Option<S>,
Option<Datetime>,
Option<i64>,
Option<i64>,
),
_type: PhantomData<fn() -> S>,
}
impl Progress<DefaultStr> {
pub fn new() -> ProgressBuilder<progress_state::Empty, DefaultStr> {
ProgressBuilder::new()
}
}
impl<S: BosStr> Progress<S> {
pub fn builder() -> ProgressBuilder<progress_state::Empty, S> {
ProgressBuilder::builder()
}
}
impl ProgressBuilder<progress_state::Empty, DefaultStr> {
pub fn new() -> Self {
ProgressBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr> ProgressBuilder<progress_state::Empty, S> {
pub fn builder() -> Self {
ProgressBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ProgressBuilder<St, S>
where
St: progress_state::State,
St::CreatedAt: progress_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> ProgressBuilder<progress_state::SetCreatedAt<St>, S> {
self._fields.0 = Option::Some(value.into());
ProgressBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ProgressBuilder<St, S>
where
St: progress_state::State,
St::Level: progress_state::IsUnset,
{
pub fn level(
mut self,
value: impl Into<i64>,
) -> ProgressBuilder<progress_state::SetLevel<St>, S> {
self._fields.1 = Option::Some(value.into());
ProgressBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: progress_state::State, S: BosStr> ProgressBuilder<St, S> {
pub fn progress_percentage(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.2 = value.into();
self
}
pub fn maybe_progress_percentage(mut self, value: Option<S>) -> Self {
self._fields.2 = value;
self
}
}
impl<St, S: BosStr> ProgressBuilder<St, S>
where
St: progress_state::State,
St::Signature: progress_state::IsUnset,
{
pub fn signature(
mut self,
value: impl Into<progress::ChronicleSignature<S>>,
) -> ProgressBuilder<progress_state::SetSignature<St>, S> {
self._fields.3 = Option::Some(value.into());
ProgressBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St, S: BosStr> ProgressBuilder<St, S>
where
St: progress_state::State,
St::TotalXp: progress_state::IsUnset,
{
pub fn total_xp(
mut self,
value: impl Into<i64>,
) -> ProgressBuilder<progress_state::SetTotalXp<St>, S> {
self._fields.4 = Option::Some(value.into());
ProgressBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<St: progress_state::State, S: BosStr> ProgressBuilder<St, S> {
pub fn trigger_source(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_trigger_source(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<St: progress_state::State, S: BosStr> ProgressBuilder<St, S> {
pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
self._fields.6 = value;
self
}
}
impl<St: progress_state::State, S: BosStr> ProgressBuilder<St, S> {
pub fn xp_gained_since_last_sign(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_xp_gained_since_last_sign(mut self, value: Option<i64>) -> Self {
self._fields.7 = value;
self
}
}
impl<St: progress_state::State, S: BosStr> ProgressBuilder<St, S> {
pub fn xp_to_next_level(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_xp_to_next_level(mut self, value: Option<i64>) -> Self {
self._fields.8 = value;
self
}
}
impl<St, S: BosStr> ProgressBuilder<St, S>
where
St: progress_state::State,
St::CreatedAt: progress_state::IsSet,
St::Level: progress_state::IsSet,
St::Signature: progress_state::IsSet,
St::TotalXp: progress_state::IsSet,
{
pub fn build(self) -> Progress<S> {
Progress {
created_at: self._fields.0.unwrap(),
level: self._fields.1.unwrap(),
progress_percentage: self._fields.2,
signature: self._fields.3.unwrap(),
total_xp: self._fields.4.unwrap(),
trigger_source: self._fields.5,
updated_at: self._fields.6,
xp_gained_since_last_sign: self._fields.7,
xp_to_next_level: self._fields.8,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Progress<S> {
Progress {
created_at: self._fields.0.unwrap(),
level: self._fields.1.unwrap(),
progress_percentage: self._fields.2,
signature: self._fields.3.unwrap(),
total_xp: self._fields.4.unwrap(),
trigger_source: self._fields.5,
updated_at: self._fields.6,
xp_gained_since_last_sign: self._fields.7,
xp_to_next_level: self._fields.8,
extra_data: Some(extra_data),
}
}
}