// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: net.anisota.beta.game.log
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[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};
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::log;
/// Details about item/specimen collection

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CollectionData<S: BosStr = DefaultStr> {
    ///Catch probability for specimens (decimal string between 0.0 and 1.0)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub catch_probability: Option<S>,
    ///URI of the created inventory record
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inventory_record_uri: Option<S>,
    ///How the item was obtained
    #[serde(skip_serializing_if = "Option::is_none")]
    pub method: Option<S>,
    ///URI of the created specimen record
    #[serde(skip_serializing_if = "Option::is_none")]
    pub specimen_record_uri: Option<S>,
    ///Whether collection was successful
    #[serde(skip_serializing_if = "Option::is_none")]
    pub success: Option<bool>,
    ///Milliseconds between card generation and collection
    #[serde(skip_serializing_if = "Option::is_none")]
    pub time_since_generation: Option<i64>,
    ///Milliseconds between card being viewed and collected
    #[serde(skip_serializing_if = "Option::is_none")]
    pub time_since_viewed: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Details about daily rewards claim

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DailyRewardsData<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub reward_items: Option<Vec<log::RewardItem<S>>>,
    ///Number of rewards claimed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rewards_count: Option<i64>,
    ///Current daily reward streak
    #[serde(skip_serializing_if = "Option::is_none")]
    pub streak: Option<i64>,
    ///Milliseconds since last claim
    #[serde(skip_serializing_if = "Option::is_none")]
    pub time_since_last_claim: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Context about the feed when event occurred

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct FeedContext<S: BosStr = DefaultStr> {
    ///URI of the feed being viewed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub feed_uri: Option<S>,
    ///Number of game cards injected
    #[serde(skip_serializing_if = "Option::is_none")]
    pub game_card_count: Option<i64>,
    ///Number of posts in the feed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub post_count: Option<i64>,
    ///User's scroll position or card index
    #[serde(skip_serializing_if = "Option::is_none")]
    pub scroll_position: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Details about game cards generated or interacted with

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct GameCardData<S: BosStr = DefaultStr> {
    ///Type of game card
    #[serde(skip_serializing_if = "Option::is_none")]
    pub card_type: Option<S>,
    ///Unique identifier for the game card
    #[serde(skip_serializing_if = "Option::is_none")]
    pub card_uri: Option<S>,
    ///Random seed used for generation (for verification)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub generation_seed: Option<S>,
    ///Position where card was injected in feed
    #[serde(skip_serializing_if = "Option::is_none")]
    pub injection_position: Option<i64>,
    ///ID of the item/specimen
    #[serde(skip_serializing_if = "Option::is_none")]
    pub item_id: Option<S>,
    ///Quantity of items
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quantity: Option<i64>,
    ///Rarity of the item/specimen
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rarity: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Details about item usage

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct ItemUsageData<S: BosStr = DefaultStr> {
    ///Effect that was applied
    #[serde(skip_serializing_if = "Option::is_none")]
    pub effect_applied: Option<S>,
    ///URI of the modified inventory record
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inventory_record_uri: Option<S>,
    ///ID of the item used
    #[serde(skip_serializing_if = "Option::is_none")]
    pub item_id: Option<S>,
    ///Quantity of the item used
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quantity_used: Option<i64>,
    ///Remaining quantity after use
    #[serde(skip_serializing_if = "Option::is_none")]
    pub remaining_quantity: Option<i64>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A log record for tracking game events and user actions for provenance and anti-bot analysis

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "net.anisota.beta.game.log",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Log<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub collection_data: Option<log::CollectionData<S>>,
    ///When the log record was created
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub daily_rewards_data: Option<log::DailyRewardsData<S>>,
    ///Type of event being logged
    pub event_type: S,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub feed_context: Option<log::FeedContext<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub game_card_data: Option<log::GameCardData<S>>,
    ///Unique ID of the game card this event relates to
    #[serde(skip_serializing_if = "Option::is_none")]
    pub game_card_id: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub item_usage_data: Option<log::ItemUsageData<S>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub metadata: Option<log::Metadata<S>>,
    ///URI of the parent log record that triggered this event
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parent_log_uri: Option<S>,
    ///URI of the root log record in this event chain
    #[serde(skip_serializing_if = "Option::is_none")]
    pub root_log_uri: Option<S>,
    ///Unique session identifier to group related events
    pub session_id: S,
    ///URI of the session record this event belongs to (at://did/collection/rkey)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub session_uri: Option<S>,
    ///When the event occurred (ISO 8601)
    pub timestamp: Datetime,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Typed wrapper for GetRecord response with this collection's record type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct LogGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Log<S>,
}

/// Additional event-specific metadata

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Metadata<S: BosStr = DefaultStr> {
    ///Version of the client application
    #[serde(skip_serializing_if = "Option::is_none")]
    pub client_version: Option<S>,
    ///Network latency in milliseconds
    #[serde(skip_serializing_if = "Option::is_none")]
    pub network_latency: Option<i64>,
    ///Performance timing data
    #[serde(skip_serializing_if = "Option::is_none")]
    pub performance_timings: Option<Data<S>>,
    ///Platform (web, mobile, etc.)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub platform: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Item received as a reward

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RewardItem<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub item_id: Option<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub quantity: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rarity: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> Log<S> {
    pub fn uri(uri: S) -> Result<RecordUri<S, LogRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new(uri)?)
    }
}

impl<S: BosStr> LexiconSchema for CollectionData<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "collectionData"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.time_since_generation {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("time_since_generation"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.time_since_viewed {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("time_since_viewed"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for DailyRewardsData<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "dailyRewardsData"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.rewards_count {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("rewards_count"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.streak {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("streak"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.time_since_last_claim {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("time_since_last_claim"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for FeedContext<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "feedContext"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.game_card_count {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("game_card_count"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.post_count {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("post_count"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.scroll_position {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("scroll_position"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for GameCardData<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "gameCardData"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.injection_position {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("injection_position"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.quantity {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("quantity"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for ItemUsageData<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "itemUsageData"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.quantity_used {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("quantity_used"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.remaining_quantity {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("remaining_quantity"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

/// Marker type for deserializing records from this collection.

#[derive(Debug, Serialize, Deserialize)]
pub struct LogRecord;
impl XrpcResp for LogRecord {
    const NSID: &'static str = "net.anisota.beta.game.log";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = LogGetRecordOutput<S>;
    type Err = RecordError;
}

impl<S: BosStr> From<LogGetRecordOutput<S>> for Log<S> {
    fn from(output: LogGetRecordOutput<S>) -> Self {
        output.value
    }
}

impl<S: BosStr> Collection for Log<S> {
    const NSID: &'static str = "net.anisota.beta.game.log";
    type Record = LogRecord;
}

impl Collection for LogRecord {
    const NSID: &'static str = "net.anisota.beta.game.log";
    type Record = LogRecord;
}

impl<S: BosStr> LexiconSchema for Log<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.session_id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 64usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("session_id"),
                    max: 64usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Metadata<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "metadata"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.network_latency {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("network_latency"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for RewardItem<S> {
    fn nsid() -> &'static str {
        "net.anisota.beta.game.log"
    }
    fn def_name() -> &'static str {
        "rewardItem"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_beta_game_log()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.quantity {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("quantity"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_net_anisota_beta_game_log() -> 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.log"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("collectionData"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Details about item/specimen collection"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("catchProbability"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Catch probability for specimens (decimal string between 0.0 and 1.0)",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("inventoryRecordUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URI of the created inventory record"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("method"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("How the item was obtained"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("specimenRecordUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URI of the created specimen record"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("success"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("timeSinceGeneration"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("timeSinceViewed"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("dailyRewardsData"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Details about daily rewards claim"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("rewardItems"),
                            LexObjectProperty::Array(LexArray {
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#rewardItem"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rewardsCount"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("streak"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("timeSinceLastClaim"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("feedContext"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Context about the feed when event occurred"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("feedUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URI of the feed being viewed"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("gameCardCount"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("postCount"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("scrollPosition"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("gameCardData"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Details about game cards generated or interacted with",
                        ),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("cardType"),
                            LexObjectProperty::String(LexString {
                                description: Some(CowStr::new_static("Type of game card")),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("cardUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Unique identifier for the game card"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("generationSeed"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Random seed used for generation (for verification)",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("injectionPosition"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("itemId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("ID of the item/specimen"),
                                ),
                                ..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 of the item/specimen"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("itemUsageData"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Details about item usage")),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("effectApplied"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Effect that was applied"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("inventoryRecordUri"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("URI of the modified inventory record"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("itemId"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("ID of the item used"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("quantityUsed"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("remainingQuantity"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A log record for tracking game events and user actions for provenance and anti-bot analysis",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("eventType"),
                                SmolStr::new_static("timestamp"),
                                SmolStr::new_static("sessionId")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("collectionData"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#collectionData"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the log record was created"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("dailyRewardsData"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#dailyRewardsData"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("eventType"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Type of event being logged"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("feedContext"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#feedContext"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("gameCardData"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#gameCardData"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("gameCardId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Unique ID of the game card this event relates to",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("itemUsageData"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#itemUsageData"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("metadata"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#metadata"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("parentLogUri"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "URI of the parent log record that triggered this event",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("rootLogUri"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "URI of the root log record in this event chain",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sessionId"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Unique session identifier to group related events",
                                        ),
                                    ),
                                    max_length: Some(64usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("sessionUri"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "URI of the session record this event belongs to (at://did/collection/rkey)",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("timestamp"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When the event occurred (ISO 8601)"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("metadata"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Additional event-specific metadata"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("clientVersion"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Version of the client application"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("networkLatency"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("performanceTimings"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("platform"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Platform (web, mobile, etc.)"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("rewardItem"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("Item received as a reward")),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("itemId"),
                            LexObjectProperty::String(LexString { ..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 { ..Default::default() }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod log_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type EventType;
        type SessionId;
        type Timestamp;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type EventType = Unset;
        type SessionId = Unset;
        type Timestamp = Unset;
    }
    ///State transition - sets the `event_type` field to Set
    pub struct SetEventType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEventType<St> {}
    impl<St: State> State for SetEventType<St> {
        type EventType = Set<members::event_type>;
        type SessionId = St::SessionId;
        type Timestamp = St::Timestamp;
    }
    ///State transition - sets the `session_id` field to Set
    pub struct SetSessionId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSessionId<St> {}
    impl<St: State> State for SetSessionId<St> {
        type EventType = St::EventType;
        type SessionId = Set<members::session_id>;
        type Timestamp = St::Timestamp;
    }
    ///State transition - sets the `timestamp` field to Set
    pub struct SetTimestamp<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTimestamp<St> {}
    impl<St: State> State for SetTimestamp<St> {
        type EventType = St::EventType;
        type SessionId = St::SessionId;
        type Timestamp = Set<members::timestamp>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `event_type` field
        pub struct event_type(());
        ///Marker type for the `session_id` field
        pub struct session_id(());
        ///Marker type for the `timestamp` field
        pub struct timestamp(());
    }
}

/// Builder for constructing an instance of this type.
pub struct LogBuilder<St: log_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<log::CollectionData<S>>,
        Option<Datetime>,
        Option<log::DailyRewardsData<S>>,
        Option<S>,
        Option<log::FeedContext<S>>,
        Option<log::GameCardData<S>>,
        Option<S>,
        Option<log::ItemUsageData<S>>,
        Option<log::Metadata<S>>,
        Option<S>,
        Option<S>,
        Option<S>,
        Option<S>,
        Option<Datetime>,
    ),
    _type: PhantomData<fn() -> S>,
}

impl Log<DefaultStr> {
    /// Create a new builder for this type, using the default string type (DefaultStr = SmolStr) if needed
    pub fn new() -> LogBuilder<log_state::Empty, DefaultStr> {
        LogBuilder::new()
    }
}

impl<S: BosStr> Log<S> {
    /// Create a new builder for this type
    pub fn builder() -> LogBuilder<log_state::Empty, S> {
        LogBuilder::builder()
    }
}

impl LogBuilder<log_state::Empty, DefaultStr> {
    /// Create a new builder with all fields unset, using the default string type, if needed
    pub fn new() -> Self {
        LogBuilder {
            _state: PhantomData,
            _fields: (
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
            ),
            _type: PhantomData,
        }
    }
}

impl<S: BosStr> LogBuilder<log_state::Empty, S> {
    /// Create a new builder with all fields unset
    pub fn builder() -> Self {
        LogBuilder {
            _state: PhantomData,
            _fields: (
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
            ),
            _type: PhantomData,
        }
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `collectionData` field (optional)
    pub fn collection_data(
        mut self,
        value: impl Into<Option<log::CollectionData<S>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `collectionData` field to an Option value (optional)
    pub fn maybe_collection_data(
        mut self,
        value: Option<log::CollectionData<S>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `createdAt` field to an Option value (optional)
    pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `dailyRewardsData` field (optional)
    pub fn daily_rewards_data(
        mut self,
        value: impl Into<Option<log::DailyRewardsData<S>>>,
    ) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `dailyRewardsData` field to an Option value (optional)
    pub fn maybe_daily_rewards_data(
        mut self,
        value: Option<log::DailyRewardsData<S>>,
    ) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> LogBuilder<St, S>
where
    St: log_state::State,
    St::EventType: log_state::IsUnset,
{
    /// Set the `eventType` field (required)
    pub fn event_type(
        mut self,
        value: impl Into<S>,
    ) -> LogBuilder<log_state::SetEventType<St>, S> {
        self._fields.3 = Option::Some(value.into());
        LogBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `feedContext` field (optional)
    pub fn feed_context(
        mut self,
        value: impl Into<Option<log::FeedContext<S>>>,
    ) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `feedContext` field to an Option value (optional)
    pub fn maybe_feed_context(mut self, value: Option<log::FeedContext<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `gameCardData` field (optional)
    pub fn game_card_data(
        mut self,
        value: impl Into<Option<log::GameCardData<S>>>,
    ) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `gameCardData` field to an Option value (optional)
    pub fn maybe_game_card_data(mut self, value: Option<log::GameCardData<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `gameCardId` field (optional)
    pub fn game_card_id(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `gameCardId` field to an Option value (optional)
    pub fn maybe_game_card_id(mut self, value: Option<S>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `itemUsageData` field (optional)
    pub fn item_usage_data(
        mut self,
        value: impl Into<Option<log::ItemUsageData<S>>>,
    ) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `itemUsageData` field to an Option value (optional)
    pub fn maybe_item_usage_data(
        mut self,
        value: Option<log::ItemUsageData<S>>,
    ) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `metadata` field (optional)
    pub fn metadata(mut self, value: impl Into<Option<log::Metadata<S>>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `metadata` field to an Option value (optional)
    pub fn maybe_metadata(mut self, value: Option<log::Metadata<S>>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `parentLogUri` field (optional)
    pub fn parent_log_uri(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `parentLogUri` field to an Option value (optional)
    pub fn maybe_parent_log_uri(mut self, value: Option<S>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `rootLogUri` field (optional)
    pub fn root_log_uri(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `rootLogUri` field to an Option value (optional)
    pub fn maybe_root_log_uri(mut self, value: Option<S>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St, S: BosStr> LogBuilder<St, S>
where
    St: log_state::State,
    St::SessionId: log_state::IsUnset,
{
    /// Set the `sessionId` field (required)
    pub fn session_id(
        mut self,
        value: impl Into<S>,
    ) -> LogBuilder<log_state::SetSessionId<St>, S> {
        self._fields.11 = Option::Some(value.into());
        LogBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: log_state::State, S: BosStr> LogBuilder<St, S> {
    /// Set the `sessionUri` field (optional)
    pub fn session_uri(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `sessionUri` field to an Option value (optional)
    pub fn maybe_session_uri(mut self, value: Option<S>) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<St, S: BosStr> LogBuilder<St, S>
where
    St: log_state::State,
    St::Timestamp: log_state::IsUnset,
{
    /// Set the `timestamp` field (required)
    pub fn timestamp(
        mut self,
        value: impl Into<Datetime>,
    ) -> LogBuilder<log_state::SetTimestamp<St>, S> {
        self._fields.13 = Option::Some(value.into());
        LogBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> LogBuilder<St, S>
where
    St: log_state::State,
    St::EventType: log_state::IsSet,
    St::SessionId: log_state::IsSet,
    St::Timestamp: log_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Log<S> {
        Log {
            collection_data: self._fields.0,
            created_at: self._fields.1,
            daily_rewards_data: self._fields.2,
            event_type: self._fields.3.unwrap(),
            feed_context: self._fields.4,
            game_card_data: self._fields.5,
            game_card_id: self._fields.6,
            item_usage_data: self._fields.7,
            metadata: self._fields.8,
            parent_log_uri: self._fields.9,
            root_log_uri: self._fields.10,
            session_id: self._fields.11.unwrap(),
            session_uri: self._fields.12,
            timestamp: self._fields.13.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Log<S> {
        Log {
            collection_data: self._fields.0,
            created_at: self._fields.1,
            daily_rewards_data: self._fields.2,
            event_type: self._fields.3.unwrap(),
            feed_context: self._fields.4,
            game_card_data: self._fields.5,
            game_card_id: self._fields.6,
            item_usage_data: self._fields.7,
            metadata: self._fields.8,
            parent_log_uri: self._fields.9,
            root_log_uri: self._fields.10,
            session_id: self._fields.11.unwrap(),
            session_uri: self._fields.12,
            timestamp: self._fields.13.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}