#[jacquard_derive::lexicon]
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct Score<'a> {
pub created_at: jacquard_common::types::string::Datetime,
pub level: i64,
#[serde(skip_serializing_if = "std::option::Option::is_none")]
pub percentage: std::option::Option<i64>,
pub total_challenges: i64,
pub total_successes: i64,
}
pub mod score_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 TotalSuccesses;
type Level;
type TotalChallenges;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type TotalSuccesses = Unset;
type Level = Unset;
type TotalChallenges = Unset;
type CreatedAt = Unset;
}
pub struct SetTotalSuccesses<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTotalSuccesses<S> {}
impl<S: State> State for SetTotalSuccesses<S> {
type TotalSuccesses = Set<members::total_successes>;
type Level = S::Level;
type TotalChallenges = S::TotalChallenges;
type CreatedAt = S::CreatedAt;
}
pub struct SetLevel<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetLevel<S> {}
impl<S: State> State for SetLevel<S> {
type TotalSuccesses = S::TotalSuccesses;
type Level = Set<members::level>;
type TotalChallenges = S::TotalChallenges;
type CreatedAt = S::CreatedAt;
}
pub struct SetTotalChallenges<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetTotalChallenges<S> {}
impl<S: State> State for SetTotalChallenges<S> {
type TotalSuccesses = S::TotalSuccesses;
type Level = S::Level;
type TotalChallenges = Set<members::total_challenges>;
type CreatedAt = S::CreatedAt;
}
pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
impl<S: State> State for SetCreatedAt<S> {
type TotalSuccesses = S::TotalSuccesses;
type Level = S::Level;
type TotalChallenges = S::TotalChallenges;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct total_successes(());
pub struct level(());
pub struct total_challenges(());
pub struct created_at(());
}
}
pub struct ScoreBuilder<'a, S: score_state::State> {
_phantom_state: ::core::marker::PhantomData<fn() -> S>,
__unsafe_private_named: (
::core::option::Option<jacquard_common::types::string::Datetime>,
::core::option::Option<i64>,
::core::option::Option<i64>,
::core::option::Option<i64>,
::core::option::Option<i64>,
),
_phantom: ::core::marker::PhantomData<&'a ()>,
}
impl<'a> Score<'a> {
pub fn new() -> ScoreBuilder<'a, score_state::Empty> {
ScoreBuilder::new()
}
}
impl<'a> ScoreBuilder<'a, score_state::Empty> {
pub fn new() -> Self {
ScoreBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: (None, None, None, None, None),
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::CreatedAt: score_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<jacquard_common::types::string::Datetime>,
) -> ScoreBuilder<'a, score_state::SetCreatedAt<S>> {
self.__unsafe_private_named.0 = ::core::option::Option::Some(value.into());
ScoreBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::Level: score_state::IsUnset,
{
pub fn level(
mut self,
value: impl Into<i64>,
) -> ScoreBuilder<'a, score_state::SetLevel<S>> {
self.__unsafe_private_named.1 = ::core::option::Option::Some(value.into());
ScoreBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S: score_state::State> ScoreBuilder<'a, S> {
pub fn percentage(mut self, value: impl Into<Option<i64>>) -> Self {
self.__unsafe_private_named.2 = value.into();
self
}
pub fn maybe_percentage(mut self, value: Option<i64>) -> Self {
self.__unsafe_private_named.2 = value;
self
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::TotalChallenges: score_state::IsUnset,
{
pub fn total_challenges(
mut self,
value: impl Into<i64>,
) -> ScoreBuilder<'a, score_state::SetTotalChallenges<S>> {
self.__unsafe_private_named.3 = ::core::option::Option::Some(value.into());
ScoreBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::TotalSuccesses: score_state::IsUnset,
{
pub fn total_successes(
mut self,
value: impl Into<i64>,
) -> ScoreBuilder<'a, score_state::SetTotalSuccesses<S>> {
self.__unsafe_private_named.4 = ::core::option::Option::Some(value.into());
ScoreBuilder {
_phantom_state: ::core::marker::PhantomData,
__unsafe_private_named: self.__unsafe_private_named,
_phantom: ::core::marker::PhantomData,
}
}
}
impl<'a, S> ScoreBuilder<'a, S>
where
S: score_state::State,
S::TotalSuccesses: score_state::IsSet,
S::Level: score_state::IsSet,
S::TotalChallenges: score_state::IsSet,
S::CreatedAt: score_state::IsSet,
{
pub fn build(self) -> Score<'a> {
Score {
created_at: self.__unsafe_private_named.0.unwrap(),
level: self.__unsafe_private_named.1.unwrap(),
percentage: self.__unsafe_private_named.2,
total_challenges: self.__unsafe_private_named.3.unwrap(),
total_successes: self.__unsafe_private_named.4.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: std::collections::BTreeMap<
jacquard_common::deps::smol_str::SmolStr,
jacquard_common::types::value::Data<'a>,
>,
) -> Score<'a> {
Score {
created_at: self.__unsafe_private_named.0.unwrap(),
level: self.__unsafe_private_named.1.unwrap(),
percentage: self.__unsafe_private_named.2,
total_challenges: self.__unsafe_private_named.3.unwrap(),
total_successes: self.__unsafe_private_named.4.unwrap(),
extra_data: Some(extra_data),
}
}
}
impl<'a> Score<'a> {
pub fn uri(
uri: impl Into<jacquard_common::CowStr<'a>>,
) -> Result<
jacquard_common::types::uri::RecordUri<'a, ScoreRecord>,
jacquard_common::types::uri::UriError,
> {
jacquard_common::types::uri::RecordUri::try_from_uri(
jacquard_common::types::string::AtUri::new_cow(uri.into())?,
)
}
}
#[derive(
serde::Serialize,
serde::Deserialize,
Debug,
Clone,
PartialEq,
Eq,
jacquard_derive::IntoStatic
)]
#[serde(rename_all = "camelCase")]
pub struct ScoreGetRecordOutput<'a> {
#[serde(skip_serializing_if = "std::option::Option::is_none")]
#[serde(borrow)]
pub cid: std::option::Option<jacquard_common::types::string::Cid<'a>>,
#[serde(borrow)]
pub uri: jacquard_common::types::string::AtUri<'a>,
#[serde(borrow)]
pub value: Score<'a>,
}
impl From<ScoreGetRecordOutput<'_>> for Score<'_> {
fn from(output: ScoreGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl jacquard_common::types::collection::Collection for Score<'_> {
const NSID: &'static str = "app.mathr.score";
type Record = ScoreRecord;
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct ScoreRecord;
impl jacquard_common::xrpc::XrpcResp for ScoreRecord {
const NSID: &'static str = "app.mathr.score";
const ENCODING: &'static str = "application/json";
type Output<'de> = ScoreGetRecordOutput<'de>;
type Err<'de> = jacquard_common::types::collection::RecordError<'de>;
}
impl jacquard_common::types::collection::Collection for ScoreRecord {
const NSID: &'static str = "app.mathr.score";
type Record = ScoreRecord;
}
impl<'a> ::jacquard_lexicon::schema::LexiconSchema for Score<'a> {
fn nsid() -> &'static str {
"app.mathr.score"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
lexicon_doc_app_mathr_score()
}
fn validate(
&self,
) -> ::core::result::Result<(), ::jacquard_lexicon::validation::ConstraintError> {
{
let value = &self.level;
if *value < 1i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Minimum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"level",
),
min: 1i64,
actual: *value,
});
}
}
if let Some(ref value) = self.percentage {
if *value > 100i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Maximum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"percentage",
),
max: 100i64,
actual: *value,
});
}
}
if let Some(ref value) = self.percentage {
if *value < 0i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Minimum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"percentage",
),
min: 0i64,
actual: *value,
});
}
}
{
let value = &self.total_challenges;
if *value < 1i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Minimum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"total_challenges",
),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.total_successes;
if *value < 0i64 {
return Err(::jacquard_lexicon::validation::ConstraintError::Minimum {
path: ::jacquard_lexicon::validation::ValidationPath::from_field(
"total_successes",
),
min: 0i64,
actual: *value,
});
}
}
Ok(())
}
}
fn lexicon_doc_app_mathr_score() -> ::jacquard_lexicon::lexicon::LexiconDoc<'static> {
::jacquard_lexicon::lexicon::LexiconDoc {
lexicon: ::jacquard_lexicon::lexicon::Lexicon::Lexicon1,
id: ::jacquard_common::CowStr::new_static("app.mathr.score"),
revision: None,
description: None,
defs: {
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static("main"),
::jacquard_lexicon::lexicon::LexUserType::Record(::jacquard_lexicon::lexicon::LexRecord {
description: Some(
::jacquard_common::CowStr::new_static(
"A player's score record stored in their own PDS for personal backup",
),
),
key: Some(::jacquard_common::CowStr::new_static("tid")),
record: ::jacquard_lexicon::lexicon::LexRecordRecord::Object(::jacquard_lexicon::lexicon::LexObject {
description: None,
required: Some(
vec![
::jacquard_common::deps::smol_str::SmolStr::new_static("level"),
::jacquard_common::deps::smol_str::SmolStr::new_static("totalSuccesses"),
::jacquard_common::deps::smol_str::SmolStr::new_static("totalChallenges"),
::jacquard_common::deps::smol_str::SmolStr::new_static("createdAt")
],
),
nullable: None,
properties: {
#[allow(unused_mut)]
let mut map = ::alloc::collections::BTreeMap::new();
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"createdAt",
),
::jacquard_lexicon::lexicon::LexObjectProperty::String(::jacquard_lexicon::lexicon::LexString {
description: Some(
::jacquard_common::CowStr::new_static(
"Timestamp when the score was recorded",
),
),
format: Some(
::jacquard_lexicon::lexicon::LexStringFormat::Datetime,
),
default: None,
min_length: None,
max_length: None,
min_graphemes: None,
max_graphemes: None,
r#enum: None,
r#const: None,
known_values: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"level",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
description: None,
default: None,
minimum: Some(1i64),
maximum: None,
r#enum: None,
r#const: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"percentage",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
description: None,
default: None,
minimum: Some(0i64),
maximum: Some(100i64),
r#enum: None,
r#const: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"totalChallenges",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
description: None,
default: None,
minimum: Some(1i64),
maximum: None,
r#enum: None,
r#const: None,
}),
);
map.insert(
::jacquard_common::deps::smol_str::SmolStr::new_static(
"totalSuccesses",
),
::jacquard_lexicon::lexicon::LexObjectProperty::Integer(::jacquard_lexicon::lexicon::LexInteger {
description: None,
default: None,
minimum: Some(0i64),
maximum: None,
r#enum: None,
r#const: None,
}),
);
map
},
}),
}),
);
map
},
}
}