#[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::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;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct GameRef<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub external_id: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub platform: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub uri: Option<AtUri<'a>>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
rename_all = "camelCase",
rename = "games.gamesgamesgamesgames.actor.game",
tag = "$type"
)]
pub struct Game<'a> {
pub created_at: Datetime,
#[serde(borrow)]
pub game: game::GameRef<'a>,
#[serde(borrow)]
pub platform: GamePlatform<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub signatures: Option<Vec<GameSignaturesItem<'a>>>,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum GamePlatform<'a> {
Steam,
Gog,
Epic,
Playstation,
Xbox,
Nintendo,
Itchio,
Humble,
Other(CowStr<'a>),
}
impl<'a> GamePlatform<'a> {
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(),
}
}
}
impl<'a> From<&'a str> for GamePlatform<'a> {
fn from(s: &'a str) -> Self {
match s {
"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(CowStr::from(s)),
}
}
}
impl<'a> From<String> for GamePlatform<'a> {
fn from(s: String) -> Self {
match s.as_str() {
"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(CowStr::from(s)),
}
}
}
impl<'a> core::fmt::Display for GamePlatform<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}", self.as_str())
}
}
impl<'a> AsRef<str> for GamePlatform<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl<'a> serde::Serialize for GamePlatform<'a> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}
impl<'de, 'a> serde::Deserialize<'de> for GamePlatform<'a>
where
'de: 'a,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
{
let s = <&'de str>::deserialize(deserializer)?;
Ok(Self::from(s))
}
}
impl<'a> Default for GamePlatform<'a> {
fn default() -> Self {
Self::Other(Default::default())
}
}
impl jacquard_common::IntoStatic for GamePlatform<'_> {
type Output = GamePlatform<'static>;
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 = "'de: 'a"))]
pub enum GameSignaturesItem<'a> {
#[serde(rename = "com.atproto.repo.strongRef")]
StrongRef(Box<StrongRef<'a>>),
}
#[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())?)
}
}
impl<'a> LexiconSchema for GameRef<'a> {
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<'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 = "games.gamesgamesgamesgames.actor.game";
type Record = GameRecord;
}
impl Collection for GameRecord {
const NSID: &'static str = "games.gamesgamesgamesgames.actor.game";
type Record = GameRecord;
}
impl<'a> LexiconSchema for Game<'a> {
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 CreatedAt;
type Game;
type Platform;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type CreatedAt = Unset;
type Game = Unset;
type Platform = Unset;
}
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 CreatedAt = Set<members::created_at>;
type Game = S::Game;
type Platform = S::Platform;
}
pub struct SetGame<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetGame<S> {}
impl<S: State> State for SetGame<S> {
type CreatedAt = S::CreatedAt;
type Game = Set<members::game>;
type Platform = S::Platform;
}
pub struct SetPlatform<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetPlatform<S> {}
impl<S: State> State for SetPlatform<S> {
type CreatedAt = S::CreatedAt;
type Game = S::Game;
type Platform = Set<members::platform>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct created_at(());
pub struct game(());
pub struct platform(());
}
}
pub struct GameBuilder<'a, S: game_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<game::GameRef<'a>>,
Option<GamePlatform<'a>>,
Option<Vec<GameSignaturesItem<'a>>>,
),
_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),
_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.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::Game: game_state::IsUnset,
{
pub fn game(
mut self,
value: impl Into<game::GameRef<'a>>,
) -> GameBuilder<'a, game_state::SetGame<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::Platform: game_state::IsUnset,
{
pub fn platform(
mut self,
value: impl Into<GamePlatform<'a>>,
) -> GameBuilder<'a, game_state::SetPlatform<S>> {
self._fields.2 = Option::Some(value.into());
GameBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: game_state::State> GameBuilder<'a, S> {
pub fn signatures(
mut self,
value: impl Into<Option<Vec<GameSignaturesItem<'a>>>>,
) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_signatures(
mut self,
value: Option<Vec<GameSignaturesItem<'a>>>,
) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S> GameBuilder<'a, S>
where
S: game_state::State,
S::CreatedAt: game_state::IsSet,
S::Game: game_state::IsSet,
S::Platform: game_state::IsSet,
{
pub fn build(self) -> Game<'a> {
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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Game<'a> {
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),
}
}
}