#[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};
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::net_anisota::beta::game::inventory;
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Inventory<'a> {
pub acquired_at: Datetime,
pub created_at: Datetime,
#[serde(borrow)]
pub item_id: CowStr<'a>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub item_name: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub item_type: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub item_value: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_modified: Option<Datetime>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub log_record_uri: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub max_stack: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub metadata: Option<Data<'a>>,
pub quantity: i64,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub rarity: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub source: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub source_details: Option<inventory::SourceDetails<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub stackable: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct InventoryGetRecordOutput<'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: Inventory<'a>,
}
#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct SourceDetails<'a> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub game_card_uri: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(borrow)]
pub quest_id: Option<CowStr<'a>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub reward_streak: Option<i64>,
}
impl<'a> Inventory<'a> {
pub fn uri(
uri: impl Into<CowStr<'a>>,
) -> Result<RecordUri<'a, InventoryRecord>, UriError> {
RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct InventoryRecord;
impl XrpcResp for InventoryRecord {
const NSID: &'static str = "net.anisota.beta.game.inventory";
const ENCODING: &'static str = "application/json";
type Output<'de> = InventoryGetRecordOutput<'de>;
type Err<'de> = RecordError<'de>;
}
impl From<InventoryGetRecordOutput<'_>> for Inventory<'_> {
fn from(output: InventoryGetRecordOutput<'_>) -> Self {
use jacquard_common::IntoStatic;
output.value.into_static()
}
}
impl Collection for Inventory<'_> {
const NSID: &'static str = "net.anisota.beta.game.inventory";
type Record = InventoryRecord;
}
impl Collection for InventoryRecord {
const NSID: &'static str = "net.anisota.beta.game.inventory";
type Record = InventoryRecord;
}
impl<'a> LexiconSchema for Inventory<'a> {
fn nsid() -> &'static str {
"net.anisota.beta.game.inventory"
}
fn def_name() -> &'static str {
"main"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_beta_game_inventory()
}
fn validate(&self) -> Result<(), ConstraintError> {
{
let value = &self.item_id;
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 100usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("item_id"),
max: 100usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.item_name {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 200usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("item_name"),
max: 200usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.item_type {
#[allow(unused_comparisons)]
if <str>::len(value.as_ref()) > 50usize {
return Err(ConstraintError::MaxLength {
path: ValidationPath::from_field("item_type"),
max: 50usize,
actual: <str>::len(value.as_ref()),
});
}
}
if let Some(ref value) = self.item_value {
if *value < 0i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("item_value"),
min: 0i64,
actual: *value,
});
}
}
if let Some(ref value) = self.max_stack {
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("max_stack"),
min: 1i64,
actual: *value,
});
}
}
{
let value = &self.quantity;
if *value < 1i64 {
return Err(ConstraintError::Minimum {
path: ValidationPath::from_field("quantity"),
min: 1i64,
actual: *value,
});
}
}
Ok(())
}
}
impl<'a> LexiconSchema for SourceDetails<'a> {
fn nsid() -> &'static str {
"net.anisota.beta.game.inventory"
}
fn def_name() -> &'static str {
"sourceDetails"
}
fn lexicon_doc() -> LexiconDoc<'static> {
lexicon_doc_net_anisota_beta_game_inventory()
}
fn validate(&self) -> Result<(), ConstraintError> {
Ok(())
}
}
pub mod inventory_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 AcquiredAt;
type CreatedAt;
type ItemId;
type Quantity;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type AcquiredAt = Unset;
type CreatedAt = Unset;
type ItemId = Unset;
type Quantity = Unset;
}
pub struct SetAcquiredAt<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetAcquiredAt<S> {}
impl<S: State> State for SetAcquiredAt<S> {
type AcquiredAt = Set<members::acquired_at>;
type CreatedAt = S::CreatedAt;
type ItemId = S::ItemId;
type Quantity = S::Quantity;
}
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 AcquiredAt = S::AcquiredAt;
type CreatedAt = Set<members::created_at>;
type ItemId = S::ItemId;
type Quantity = S::Quantity;
}
pub struct SetItemId<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetItemId<S> {}
impl<S: State> State for SetItemId<S> {
type AcquiredAt = S::AcquiredAt;
type CreatedAt = S::CreatedAt;
type ItemId = Set<members::item_id>;
type Quantity = S::Quantity;
}
pub struct SetQuantity<S: State = Empty>(PhantomData<fn() -> S>);
impl<S: State> sealed::Sealed for SetQuantity<S> {}
impl<S: State> State for SetQuantity<S> {
type AcquiredAt = S::AcquiredAt;
type CreatedAt = S::CreatedAt;
type ItemId = S::ItemId;
type Quantity = Set<members::quantity>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct acquired_at(());
pub struct created_at(());
pub struct item_id(());
pub struct quantity(());
}
}
pub struct InventoryBuilder<'a, S: inventory_state::State> {
_state: PhantomData<fn() -> S>,
_fields: (
Option<Datetime>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<i64>,
Option<Datetime>,
Option<CowStr<'a>>,
Option<i64>,
Option<Data<'a>>,
Option<i64>,
Option<CowStr<'a>>,
Option<CowStr<'a>>,
Option<inventory::SourceDetails<'a>>,
Option<bool>,
),
_lifetime: PhantomData<&'a ()>,
}
impl<'a> Inventory<'a> {
pub fn new() -> InventoryBuilder<'a, inventory_state::Empty> {
InventoryBuilder::new()
}
}
impl<'a> InventoryBuilder<'a, inventory_state::Empty> {
pub fn new() -> Self {
InventoryBuilder {
_state: PhantomData,
_fields: (
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
),
_lifetime: PhantomData,
}
}
}
impl<'a, S> InventoryBuilder<'a, S>
where
S: inventory_state::State,
S::AcquiredAt: inventory_state::IsUnset,
{
pub fn acquired_at(
mut self,
value: impl Into<Datetime>,
) -> InventoryBuilder<'a, inventory_state::SetAcquiredAt<S>> {
self._fields.0 = Option::Some(value.into());
InventoryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> InventoryBuilder<'a, S>
where
S: inventory_state::State,
S::CreatedAt: inventory_state::IsUnset,
{
pub fn created_at(
mut self,
value: impl Into<Datetime>,
) -> InventoryBuilder<'a, inventory_state::SetCreatedAt<S>> {
self._fields.1 = Option::Some(value.into());
InventoryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S> InventoryBuilder<'a, S>
where
S: inventory_state::State,
S::ItemId: inventory_state::IsUnset,
{
pub fn item_id(
mut self,
value: impl Into<CowStr<'a>>,
) -> InventoryBuilder<'a, inventory_state::SetItemId<S>> {
self._fields.2 = Option::Some(value.into());
InventoryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn item_name(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_item_name(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.3 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn item_type(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_item_type(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.4 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn item_value(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_item_value(mut self, value: Option<i64>) -> Self {
self._fields.5 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn last_modified(mut self, value: impl Into<Option<Datetime>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_last_modified(mut self, value: Option<Datetime>) -> Self {
self._fields.6 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn log_record_uri(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_log_record_uri(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.7 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn max_stack(mut self, value: impl Into<Option<i64>>) -> Self {
self._fields.8 = value.into();
self
}
pub fn maybe_max_stack(mut self, value: Option<i64>) -> Self {
self._fields.8 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn metadata(mut self, value: impl Into<Option<Data<'a>>>) -> Self {
self._fields.9 = value.into();
self
}
pub fn maybe_metadata(mut self, value: Option<Data<'a>>) -> Self {
self._fields.9 = value;
self
}
}
impl<'a, S> InventoryBuilder<'a, S>
where
S: inventory_state::State,
S::Quantity: inventory_state::IsUnset,
{
pub fn quantity(
mut self,
value: impl Into<i64>,
) -> InventoryBuilder<'a, inventory_state::SetQuantity<S>> {
self._fields.10 = Option::Some(value.into());
InventoryBuilder {
_state: PhantomData,
_fields: self._fields,
_lifetime: PhantomData,
}
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn rarity(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.11 = value.into();
self
}
pub fn maybe_rarity(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.11 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn source(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
self._fields.12 = value.into();
self
}
pub fn maybe_source(mut self, value: Option<CowStr<'a>>) -> Self {
self._fields.12 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn source_details(
mut self,
value: impl Into<Option<inventory::SourceDetails<'a>>>,
) -> Self {
self._fields.13 = value.into();
self
}
pub fn maybe_source_details(
mut self,
value: Option<inventory::SourceDetails<'a>>,
) -> Self {
self._fields.13 = value;
self
}
}
impl<'a, S: inventory_state::State> InventoryBuilder<'a, S> {
pub fn stackable(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.14 = value.into();
self
}
pub fn maybe_stackable(mut self, value: Option<bool>) -> Self {
self._fields.14 = value;
self
}
}
impl<'a, S> InventoryBuilder<'a, S>
where
S: inventory_state::State,
S::AcquiredAt: inventory_state::IsSet,
S::CreatedAt: inventory_state::IsSet,
S::ItemId: inventory_state::IsSet,
S::Quantity: inventory_state::IsSet,
{
pub fn build(self) -> Inventory<'a> {
Inventory {
acquired_at: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
item_id: self._fields.2.unwrap(),
item_name: self._fields.3,
item_type: self._fields.4,
item_value: self._fields.5,
last_modified: self._fields.6,
log_record_uri: self._fields.7,
max_stack: self._fields.8,
metadata: self._fields.9,
quantity: self._fields.10.unwrap(),
rarity: self._fields.11,
source: self._fields.12,
source_details: self._fields.13,
stackable: self._fields.14,
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
) -> Inventory<'a> {
Inventory {
acquired_at: self._fields.0.unwrap(),
created_at: self._fields.1.unwrap(),
item_id: self._fields.2.unwrap(),
item_name: self._fields.3,
item_type: self._fields.4,
item_value: self._fields.5,
last_modified: self._fields.6,
log_record_uri: self._fields.7,
max_stack: self._fields.8,
metadata: self._fields.9,
quantity: self._fields.10.unwrap(),
rarity: self._fields.11,
source: self._fields.12,
source_details: self._fields.13,
stackable: self._fields.14,
extra_data: Some(extra_data),
}
}
}
fn lexicon_doc_net_anisota_beta_game_inventory() -> 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("net.anisota.beta.game.inventory"),
defs: {
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("main"),
LexUserType::Record(LexRecord {
description: Some(
CowStr::new_static(
"Beta version: Record representing an item in a player's game inventory",
),
),
key: Some(CowStr::new_static("tid")),
record: LexRecordRecord::Object(LexObject {
required: Some(
vec![
SmolStr::new_static("itemId"),
SmolStr::new_static("quantity"),
SmolStr::new_static("acquiredAt"),
SmolStr::new_static("createdAt")
],
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("acquiredAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the item was acquired"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("createdAt"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the record was created"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("itemId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Unique identifier for the item from gameItems.json",
),
),
max_length: Some(100usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("itemName"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Display name of the item"),
),
max_length: Some(200usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("itemType"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"Type category of the item (consumable, tool, equipment, etc.)",
),
),
max_length: Some(50usize),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("itemValue"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(0i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("lastModified"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("When the record was last modified"),
),
format: Some(LexStringFormat::Datetime),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("logRecordUri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"URI of the game.log record that documents the acquisition of this item",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("maxStack"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("metadata"),
LexObjectProperty::Unknown(LexUnknown {
..Default::default()
}),
);
map.insert(
SmolStr::new_static("quantity"),
LexObjectProperty::Integer(LexInteger {
minimum: Some(1i64),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rarity"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("Rarity level of the item"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("source"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static("How the item was acquired"),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sourceDetails"),
LexObjectProperty::Ref(LexRef {
r#ref: CowStr::new_static("#sourceDetails"),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("stackable"),
LexObjectProperty::Boolean(LexBoolean {
..Default::default()
}),
);
map
},
..Default::default()
}),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("sourceDetails"),
LexUserType::Object(LexObject {
description: Some(
CowStr::new_static(
"Additional details about how the item was acquired",
),
),
properties: {
#[allow(unused_mut)]
let mut map = BTreeMap::new();
map.insert(
SmolStr::new_static("gameCardUri"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"URI of the game card that provided this item",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("questId"),
LexObjectProperty::String(LexString {
description: Some(
CowStr::new_static(
"ID of the quest that rewarded this item",
),
),
..Default::default()
}),
);
map.insert(
SmolStr::new_static("rewardStreak"),
LexObjectProperty::Integer(LexInteger {
..Default::default()
}),
);
map
},
..Default::default()
}),
);
map
},
..Default::default()
}
}