#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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::xrpc::XrpcResp;
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};
use crate::blue__2048::SyncStatus;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Game<'a> {
#[serde(default = "_default_game_completed")]
pub completed: bool,
pub created_at: Datetime,
#[serde(default = "_default_game_current_score")]
pub current_score: i64,
#[serde(borrow)]
pub seeded_recording: CowStr<'a>,
#[serde(borrow)]
pub sync_status: SyncStatus<'a>,
#[serde(default = "_default_game_won")]
pub won: bool,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GameGetRecordOutput<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub cid: Option<Cid<'a>>,
#[serde(borrow)]
pub uri: AtUri<'a>,
#[serde(borrow)]
pub value: Game<'a>,
}
impl<'a> Game<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, GameRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GameRecord;
impl XrpcResp for GameRecord {
const NSID: &'static str = "blue.2048.game";
const ENCODING: &'static str = "application/json";
type Output<'de> = GameGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<GameGetRecordOutput<'_>> for Game<'_> {
fn from(output: GameGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Game<'_> {
const NSID: &'static str = "blue.2048.game";
type Record = GameRecord;
}
impl Collection for GameRecord {
const NSID: &'static str = "blue.2048.game";
type Record = GameRecord;
}
impl<'a> LexiconSchema for Game<'a> {
fn nsid() -> &'static str {
"blue.2048.game"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_blue_2048_game()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
fn _default_game_completed() -> bool {
false
}
fn _default_game_current_score() -> i64 {
0i64
}
fn _default_game_won() -> bool {
false
}
pub mod game_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 Won;
type Completed;
type CurrentScore;
type CreatedAt;
type SeededRecording;
type SyncStatus;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Won = Unset;
type Completed = Unset;
type CurrentScore = Unset;
type CreatedAt = Unset;
type SeededRecording = Unset;
type SyncStatus = Unset;
}
pub struct SetWon<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetWon<S> {}
impl<S: State> State for SetWon<S> {
type Won = Set<members::won>;
type Completed = S::Completed;
type CurrentScore = S::CurrentScore;
type CreatedAt = S::CreatedAt;
type SeededRecording = S::SeededRecording;
type SyncStatus = S::SyncStatus;
}
pub struct SetCompleted<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCompleted<S> {}
impl<S: State> State for SetCompleted<S> {
type Won = S::Won;
type Completed = Set<members::completed>;
type CurrentScore = S::CurrentScore;
type CreatedAt = S::CreatedAt;
type SeededRecording = S::SeededRecording;
type SyncStatus = S::SyncStatus;
}
pub struct SetCurrentScore<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetCurrentScore<S> {}
impl<S: State> State for SetCurrentScore<S> {
type Won = S::Won;
type Completed = S::Completed;
type CurrentScore = Set<members::current_score>;
type CreatedAt = S::CreatedAt;
type SeededRecording = S::SeededRecording;
type SyncStatus = S::SyncStatus;
}
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 Won = S::Won;
type Completed = S::Completed;
type CurrentScore = S::CurrentScore;
type CreatedAt = Set<members::created_at>;
type SeededRecording = S::SeededRecording;
type SyncStatus = S::SyncStatus;
}
pub struct SetSeededRecording<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSeededRecording<S> {}
impl<S: State> State for SetSeededRecording<S> {
type Won = S::Won;
type Completed = S::Completed;
type CurrentScore = S::CurrentScore;
type CreatedAt = S::CreatedAt;
type SeededRecording = Set<members::seeded_recording>;
type SyncStatus = S::SyncStatus;
}
pub struct SetSyncStatus<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetSyncStatus<S> {}
impl<S: State> State for SetSyncStatus<S> {
type Won = S::Won;
type Completed = S::Completed;
type CurrentScore = S::CurrentScore;
type CreatedAt = S::CreatedAt;
type SeededRecording = S::SeededRecording;
type SyncStatus = Set<members::sync_status>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct won(());
pub struct completed(());
pub struct current_score(());
pub struct created_at(());
pub struct seeded_recording(());
pub struct sync_status(());
}
}
pub struct GameBuilder<'a, S: game_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<bool>,
Option<Datetime>,
Option<i64>,
Option<CowStr<'a>>,
Option<SyncStatus<'a>>,
Option<bool>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Game<'a> {
pub fn new() -> GameBuilder<'a, game_state::Empty> {
GameBuilder::new()
}
}
impl<'a> GameBuilder<'a, game_state::Empty> {
pub fn new() -> Self {
GameBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None),
_lifetime: PhantomData,
}
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::Completed: game_state::IsUnset,
{
pub fn completed(
mut self,
value: impl Into<bool>,
) -> GameBuilder<'a, game_state::SetCompleted<S>> {
self._fields.0 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::CreatedAt: game_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> GameBuilder<'a, game_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::CurrentScore: game_state::IsUnset,
{
pub fn current_score(
mut self,
value: impl Into<i64>,
) -> GameBuilder<'a, game_state::SetCurrentScore<S>> {
self._fields.2 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::SeededRecording: game_state::IsUnset,
{
pub fn seeded_recording(
mut self,
value: impl Into<CowStr<'a>>,
) -> GameBuilder<'a, game_state::SetSeededRecording<S>> {
self._fields.3 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::SyncStatus: game_state::IsUnset,
{
pub fn sync_status(
mut self,
value: impl Into<SyncStatus<'a>>,
) -> GameBuilder<'a, game_state::SetSyncStatus<S>> {
self._fields.4 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::Won: game_state::IsUnset,
{
pub fn won(
mut self,
value: impl Into<bool>,
) -> GameBuilder<'a, game_state::SetWon<S>> {
self._fields.5 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::Won: game_state::IsSet,
S::Completed: game_state::IsSet,
S::CurrentScore: game_state::IsSet,
S::CreatedAt: game_state::IsSet,
S::SeededRecording: game_state::IsSet,
S::SyncStatus: game_state::IsSet,
{
pub fn build(self) -> Game<'a> {
Game {
completed: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
current_score: self._fields.2.unwrap(),
seeded_recording: self._fields.3.unwrap(),
sync_status: self._fields.4.unwrap(),
won: self._fields.5.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>,
>,
) -> Game<'a> {
Game {
completed: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
current_score: self._fields.2.unwrap(),
seeded_recording: self._fields.3.unwrap(),
sync_status: self._fields.4.unwrap(),
won: self._fields.5.unwrap(),
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_blue_2048_game() -> 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.2048.game"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A declaration of an instance of a at://2048 game",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("currentScore"),
SmolStr::new_static("won"),
SmolStr::new_static("completed"),
SmolStr::new_static("seededRecording"),
SmolStr::new_static("syncStatus"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("completed"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("currentScore"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("seededRecording"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"This is the recording of the game. Like chess notation, but for 2048",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("syncStatus"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("blue.2048.defs#syncStatus"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("won"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}