#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, 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, open_union};
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::com_atproto::repo::strong_ref::StrongRef;
use crate::games_gamesgamesgamesgames::actor::game;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GameRef<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub external_id: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub platform: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uri: Option<AtUri<S>>,
#[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 = "games.gamesgamesgamesgames.actor.game",
tag = "$type",
bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Game<S: BosStr = DefaultStr> {
pub created_at: Datetime,
pub game: game::GameRef<S>,
pub platform: GamePlatform<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signatures: Option<Vec<GameSignaturesItem<S>>>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GamePlatform<S: BosStr = DefaultStr> {
Steam,
Gog,
Epic,
Playstation,
Xbox,
Nintendo,
Itchio,
Humble,
Other(S),
}
impl<S: BosStr> GamePlatform<S> {
pub fn as_str(&self) -> &str {
match self {
Self::Steam => "steam",
Self::Gog => "gog",
Self::Epic => "epic",
Self::Playstation => "playstation",
Self::Xbox => "xbox",
Self::Nintendo => "nintendo",
Self::Itchio => "itchio",
Self::Humble => "humble",
Self::Other(s) => s.as_ref(),
}
}
pub fn from_value(s: S) -> Self {
match s.as_ref() {
"steam" => Self::Steam,
"gog" => Self::Gog,
"epic" => Self::Epic,
"playstation" => Self::Playstation,
"xbox" => Self::Xbox,
"nintendo" => Self::Nintendo,
"itchio" => Self::Itchio,
"humble" => Self::Humble,
_ => Self::Other(s),
}
}
}
impl<S: BosStr> core::fmt::Display for GamePlatform<S> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<S: BosStr> AsRef<str> for GamePlatform<S> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<S: BosStr> Serialize for GamePlatform<S> {
fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
where
Ser: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de> for GamePlatform<S> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = S::deserialize(deserializer)?;
Ok(Self::from_value(s))
}
}
impl<S: BosStr + Default> Default for GamePlatform<S> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl<S: BosStr> jacquard_common::IntoStatic for GamePlatform<S>
where
S: BosStr + jacquard_common::IntoStatic,
S::Output: BosStr,
{
type Output = GamePlatform<S::Output>;
fn into_static(self) -> Self::Output {
match self {
GamePlatform::Steam => GamePlatform::Steam,
GamePlatform::Gog => GamePlatform::Gog,
GamePlatform::Epic => GamePlatform::Epic,
GamePlatform::Playstation => GamePlatform::Playstation,
GamePlatform::Xbox => GamePlatform::Xbox,
GamePlatform::Nintendo => GamePlatform::Nintendo,
GamePlatform::Itchio => GamePlatform::Itchio,
GamePlatform::Humble => GamePlatform::Humble,
GamePlatform::Other(v) => GamePlatform::Other(v.into_static()),
}
}
}
#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum GameSignaturesItem<S: BosStr = DefaultStr> {
#[serde(rename = "com.atproto.repo.strongRef")]
StrongRef(Box<StrongRef<S>>),
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GameGetRecordOutput<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
pub cid: Option<Cid<S>>,
pub uri: AtUri<S>,
pub value: Game<S>,
}
impl<S: BosStr> Game<S> {
pub fn uri(uri: S) -> Result<RecordUri<S, GameRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new(uri)?)
}
}
impl<S: BosStr> LexiconSchema for GameRef<S> {
fn nsid() -> &'static str {
"games.gamesgamesgamesgames.actor.game"
}
fn def_name() -> &'static str {
"gameRef"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_games_gamesgamesgamesgames_actor_game()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GameRecord;
impl XrpcResp for GameRecord {
const NSID: &'static str = "games.gamesgamesgamesgames.actor.game";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = GameGetRecordOutput<S>;
type Err = RecordError;
}
impl<S: BosStr> From<GameGetRecordOutput<S>> for Game<S> {
fn from(output: GameGetRecordOutput<S>) -> Self {
output.value
}
}
impl<S: BosStr> Collection for Game<S> {
const NSID: &'static str = "games.gamesgamesgamesgames.actor.game";
type Record = GameRecord;
}
impl Collection for GameRecord {
const NSID: &'static str = "games.gamesgamesgamesgames.actor.game";
type Record = GameRecord;
}
impl<S: BosStr> LexiconSchema for Game<S> {
fn nsid() -> &'static str {
"games.gamesgamesgamesgames.actor.game"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_games_gamesgamesgamesgames_actor_game()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
fn lexicon_doc_games_gamesgamesgamesgames_actor_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("games.gamesgamesgamesgames.actor.game"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("gameRef"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Reference to a game, either by AT URI or external platform ID.",
),
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("externalId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("External platform's ID for the game."),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("platform"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("External platform for ID lookup."),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("uri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("AT URI of the game record."),
),
format: Some(LexStringFormat::AtUri),
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"A record indicating the actor owns a game on a specific platform. May include attestation signatures proving ownership was verified by an external service.",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("game"),
SmolStr::new_static("platform"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("game"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#gameRef"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("platform"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"The platform where ownership was verified.",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("signatures"),
LexObjectProperty::Array(LexArray {
description: Some(
CowStr::new_static(
"Attestation signatures proving ownership was verified. Can be inline signatures or strongRefs to remote proof records.",
),
),
items: LexArrayItem::Union(LexRefUnion {
refs: vec![
CowStr::new_static("games.gamesgamesgamesgames.defs#signature"),
CowStr::new_static("com.atproto.repo.strongRef")
],
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map
},
..Default::default()
}
}
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 Platform;
type Game;
type CreatedAt;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Platform = Unset;
type Game = Unset;
type CreatedAt = Unset;
}
pub struct SetPlatform<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetPlatform<St> {}
impl<St: State> State for SetPlatform<St> {
type Platform = Set<members::platform>;
type Game = St::Game;
type CreatedAt = St::CreatedAt;
}
pub struct SetGame<St: State = Empty>(PhantomData<fn() -> St>);
impl<St: State> sealed::Sealed for SetGame<St> {}
impl<St: State> State for SetGame<St> {
type Platform = St::Platform;
type Game = Set<members::game>;
type CreatedAt = St::CreatedAt;
}
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 Platform = St::Platform;
type Game = St::Game;
type CreatedAt = Set<members::created_at>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct platform(());
pub struct game(());
pub struct created_at(());
}
}
pub struct GameBuilder<S: BosStr, St: game_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<Datetime>,
Option<game::GameRef<S>>,
Option<GamePlatform<S>>,
Option<Vec<GameSignaturesItem<S>>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> Game<S> {
pub fn new() -> GameBuilder<S, game_state::Empty> {
GameBuilder::new()
}
}
impl<S: BosStr> GameBuilder<S, game_state::Empty> {
pub fn new() -> Self {
GameBuilder {
_state: PhantomData,
_fields: (None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GameBuilder<S, St>
where
St: game_state::State,
St::CreatedAt: game_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> GameBuilder<S, game_state::SetCreatedAt<St>> {
self._fields.0 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GameBuilder<S, St>
where
St: game_state::State,
St::Game: game_state::IsUnset,
{
pub fn game(
mut self,
value: impl Into<game::GameRef<S>>,
) -> GameBuilder<S, game_state::SetGame<St>> {
self._fields.1 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> GameBuilder<S, St>
where
St: game_state::State,
St::Platform: game_state::IsUnset,
{
pub fn platform(
mut self,
value: impl Into<GamePlatform<S>>,
) -> GameBuilder<S, game_state::SetPlatform<St>> {
self._fields.2 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: game_state::State> GameBuilder<S, St> {
pub fn signatures(
mut self,
value: impl Into<Option<Vec<GameSignaturesItem<S>>>>,
) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_signatures(
mut self,
value: Option<Vec<GameSignaturesItem<S>>>,
) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St> GameBuilder<S, St>
where
St: game_state::State,
St::Platform: game_state::IsSet,
St::Game: game_state::IsSet,
St::CreatedAt: game_state::IsSet,
{
pub fn build(self) -> Game<S> {
Game {
created_at: self._fields.0.unwrap(),
game: self._fields.1.unwrap(),
platform: self._fields.2.unwrap(),
signatures: self._fields.3,
extra_data: Default::default(),
}
}
pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Game<S> {
Game {
created_at: self._fields.0.unwrap(),
game: self._fields.1.unwrap(),
platform: self._fields.2.unwrap(),
signatures: self._fields.3,
extra_data: Some(extra_data),
}
}
}