// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: net.anisota.harvest.minigame
//
// 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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::net_anisota::harvest::minigame;
/// A record of a harvest minigame round played by a user

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Minigame<'a> {
    ///Version of the Anisota client
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub client_version: Option<CowStr<'a>>,
    ///When the record was created
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    ///Number of shapes harvested early (during growth phase)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub early_harvests: Option<i64>,
    ///Bonus points awarded for harvest efficiency (percentage of shapes collected)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub efficiency_bonus: Option<i64>,
    ///Final score achieved in the round
    pub final_score: i64,
    ///Where the game was played: dedicated minigame page or harvest loading screen
    #[serde(borrow)]
    pub game_context: CowStr<'a>,
    ///Number of shapes harvested late (during decay phase)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub late_harvests: Option<i64>,
    ///Percentage indicating how close on average the user harvested at peak timing (scaled by 100, so 9550 = 95.50%)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub peak_harvest_rate: Option<i64>,
    ///Bonus points awarded for achieving high peak harvest rate
    #[serde(skip_serializing_if = "Option::is_none")]
    pub peak_rate_bonus: Option<i64>,
    ///Number of shapes harvested at perfect (peak) timing
    #[serde(skip_serializing_if = "Option::is_none")]
    pub perfect_harvests: Option<i64>,
    ///When the game round was played (ISO 8601)
    pub played_at: Datetime,
    ///Average rate of points scored per second (scaled by 100, so 123 = 1.23 points/second)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub points_per_second: Option<i64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub rarity_breakdown: Option<minigame::RarityBreakdown<'a>>,
    ///Duration of the round in seconds
    pub round_duration: i64,
    ///Total number of shapes collected/harvested
    pub shapes_collected: i64,
    ///Total number of shapes that expired without being harvested
    #[serde(skip_serializing_if = "Option::is_none")]
    pub shapes_missed: Option<i64>,
    ///Total number of shapes spawned during the round (collected + missed)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total_shapes_spawned: Option<i64>,
}

/// 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 MinigameGetRecordOutput<'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: Minigame<'a>,
}

/// Count of each rarity level collected

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct RarityBreakdown<'a> {
    ///Number of common (triangle) shapes collected
    #[serde(skip_serializing_if = "Option::is_none")]
    pub common: Option<i64>,
    ///Number of rare (star) shapes collected
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rare: Option<i64>,
    ///Number of uncommon (diamond) shapes collected
    #[serde(skip_serializing_if = "Option::is_none")]
    pub uncommon: Option<i64>,
    ///Number of very common (circle) shapes collected
    #[serde(skip_serializing_if = "Option::is_none")]
    pub very_common: Option<i64>,
    ///Number of very rare (sparkle) shapes collected
    #[serde(skip_serializing_if = "Option::is_none")]
    pub very_rare: Option<i64>,
}

impl<'a> Minigame<'a> {
    pub fn uri(
        uri: impl Into<CowStr<'a>>,
    ) -> Result<RecordUri<'a, MinigameRecord>, UriError> {
        RecordUri::try_from_uri(AtUri::new_cow(uri.into())?)
    }
}

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

#[derive(Debug, Serialize, Deserialize)]
pub struct MinigameRecord;
impl XrpcResp for MinigameRecord {
    const NSID: &'static str = "net.anisota.harvest.minigame";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = MinigameGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

impl From<MinigameGetRecordOutput<'_>> for Minigame<'_> {
    fn from(output: MinigameGetRecordOutput<'_>) -> Self {
        use jacquard_common::IntoStatic;
        output.value.into_static()
    }
}

impl Collection for Minigame<'_> {
    const NSID: &'static str = "net.anisota.harvest.minigame";
    type Record = MinigameRecord;
}

impl Collection for MinigameRecord {
    const NSID: &'static str = "net.anisota.harvest.minigame";
    type Record = MinigameRecord;
}

impl<'a> LexiconSchema for Minigame<'a> {
    fn nsid() -> &'static str {
        "net.anisota.harvest.minigame"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_harvest_minigame()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.early_harvests {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("early_harvests"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.efficiency_bonus {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("efficiency_bonus"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.final_score;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("final_score"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.late_harvests {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("late_harvests"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.peak_harvest_rate {
            if *value > 10000i64 {
                return Err(ConstraintError::Maximum {
                    path: ValidationPath::from_field("peak_harvest_rate"),
                    max: 10000i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.peak_harvest_rate {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("peak_harvest_rate"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.peak_rate_bonus {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("peak_rate_bonus"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.perfect_harvests {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("perfect_harvests"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.points_per_second {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("points_per_second"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.round_duration;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("round_duration"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        {
            let value = &self.shapes_collected;
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("shapes_collected"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.shapes_missed {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("shapes_missed"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.total_shapes_spawned {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("total_shapes_spawned"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<'a> LexiconSchema for RarityBreakdown<'a> {
    fn nsid() -> &'static str {
        "net.anisota.harvest.minigame"
    }
    fn def_name() -> &'static str {
        "rarityBreakdown"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_net_anisota_harvest_minigame()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.common {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("common"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.rare {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("rare"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.uncommon {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("uncommon"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.very_common {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("very_common"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        if let Some(ref value) = self.very_rare {
            if *value < 0i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("very_rare"),
                    min: 0i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

pub mod minigame_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 RoundDuration;
        type PlayedAt;
        type FinalScore;
        type ShapesCollected;
        type GameContext;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type RoundDuration = Unset;
        type PlayedAt = Unset;
        type FinalScore = Unset;
        type ShapesCollected = Unset;
        type GameContext = Unset;
    }
    ///State transition - sets the `round_duration` field to Set
    pub struct SetRoundDuration<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetRoundDuration<S> {}
    impl<S: State> State for SetRoundDuration<S> {
        type RoundDuration = Set<members::round_duration>;
        type PlayedAt = S::PlayedAt;
        type FinalScore = S::FinalScore;
        type ShapesCollected = S::ShapesCollected;
        type GameContext = S::GameContext;
    }
    ///State transition - sets the `played_at` field to Set
    pub struct SetPlayedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPlayedAt<S> {}
    impl<S: State> State for SetPlayedAt<S> {
        type RoundDuration = S::RoundDuration;
        type PlayedAt = Set<members::played_at>;
        type FinalScore = S::FinalScore;
        type ShapesCollected = S::ShapesCollected;
        type GameContext = S::GameContext;
    }
    ///State transition - sets the `final_score` field to Set
    pub struct SetFinalScore<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetFinalScore<S> {}
    impl<S: State> State for SetFinalScore<S> {
        type RoundDuration = S::RoundDuration;
        type PlayedAt = S::PlayedAt;
        type FinalScore = Set<members::final_score>;
        type ShapesCollected = S::ShapesCollected;
        type GameContext = S::GameContext;
    }
    ///State transition - sets the `shapes_collected` field to Set
    pub struct SetShapesCollected<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetShapesCollected<S> {}
    impl<S: State> State for SetShapesCollected<S> {
        type RoundDuration = S::RoundDuration;
        type PlayedAt = S::PlayedAt;
        type FinalScore = S::FinalScore;
        type ShapesCollected = Set<members::shapes_collected>;
        type GameContext = S::GameContext;
    }
    ///State transition - sets the `game_context` field to Set
    pub struct SetGameContext<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetGameContext<S> {}
    impl<S: State> State for SetGameContext<S> {
        type RoundDuration = S::RoundDuration;
        type PlayedAt = S::PlayedAt;
        type FinalScore = S::FinalScore;
        type ShapesCollected = S::ShapesCollected;
        type GameContext = Set<members::game_context>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `round_duration` field
        pub struct round_duration(());
        ///Marker type for the `played_at` field
        pub struct played_at(());
        ///Marker type for the `final_score` field
        pub struct final_score(());
        ///Marker type for the `shapes_collected` field
        pub struct shapes_collected(());
        ///Marker type for the `game_context` field
        pub struct game_context(());
    }
}

/// Builder for constructing an instance of this type
pub struct MinigameBuilder<'a, S: minigame_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<CowStr<'a>>,
        Option<Datetime>,
        Option<i64>,
        Option<i64>,
        Option<i64>,
        Option<CowStr<'a>>,
        Option<i64>,
        Option<i64>,
        Option<i64>,
        Option<i64>,
        Option<Datetime>,
        Option<i64>,
        Option<minigame::RarityBreakdown<'a>>,
        Option<i64>,
        Option<i64>,
        Option<i64>,
        Option<i64>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> Minigame<'a> {
    /// Create a new builder for this type
    pub fn new() -> MinigameBuilder<'a, minigame_state::Empty> {
        MinigameBuilder::new()
    }
}

impl<'a> MinigameBuilder<'a, minigame_state::Empty> {
    /// Create a new builder with all fields unset
    pub fn new() -> Self {
        MinigameBuilder {
            _state: PhantomData,
            _fields: (
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
                None,
            ),
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `clientVersion` field (optional)
    pub fn client_version(mut self, value: impl Into<Option<CowStr<'a>>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `clientVersion` field to an Option value (optional)
    pub fn maybe_client_version(mut self, value: Option<CowStr<'a>>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, 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<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `earlyHarvests` field (optional)
    pub fn early_harvests(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `earlyHarvests` field to an Option value (optional)
    pub fn maybe_early_harvests(mut self, value: Option<i64>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `efficiencyBonus` field (optional)
    pub fn efficiency_bonus(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `efficiencyBonus` field to an Option value (optional)
    pub fn maybe_efficiency_bonus(mut self, value: Option<i64>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> MinigameBuilder<'a, S>
where
    S: minigame_state::State,
    S::FinalScore: minigame_state::IsUnset,
{
    /// Set the `finalScore` field (required)
    pub fn final_score(
        mut self,
        value: impl Into<i64>,
    ) -> MinigameBuilder<'a, minigame_state::SetFinalScore<S>> {
        self._fields.4 = Option::Some(value.into());
        MinigameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MinigameBuilder<'a, S>
where
    S: minigame_state::State,
    S::GameContext: minigame_state::IsUnset,
{
    /// Set the `gameContext` field (required)
    pub fn game_context(
        mut self,
        value: impl Into<CowStr<'a>>,
    ) -> MinigameBuilder<'a, minigame_state::SetGameContext<S>> {
        self._fields.5 = Option::Some(value.into());
        MinigameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `lateHarvests` field (optional)
    pub fn late_harvests(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `lateHarvests` field to an Option value (optional)
    pub fn maybe_late_harvests(mut self, value: Option<i64>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `peakHarvestRate` field (optional)
    pub fn peak_harvest_rate(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `peakHarvestRate` field to an Option value (optional)
    pub fn maybe_peak_harvest_rate(mut self, value: Option<i64>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `peakRateBonus` field (optional)
    pub fn peak_rate_bonus(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `peakRateBonus` field to an Option value (optional)
    pub fn maybe_peak_rate_bonus(mut self, value: Option<i64>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `perfectHarvests` field (optional)
    pub fn perfect_harvests(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `perfectHarvests` field to an Option value (optional)
    pub fn maybe_perfect_harvests(mut self, value: Option<i64>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<'a, S> MinigameBuilder<'a, S>
where
    S: minigame_state::State,
    S::PlayedAt: minigame_state::IsUnset,
{
    /// Set the `playedAt` field (required)
    pub fn played_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> MinigameBuilder<'a, minigame_state::SetPlayedAt<S>> {
        self._fields.10 = Option::Some(value.into());
        MinigameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `pointsPerSecond` field (optional)
    pub fn points_per_second(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `pointsPerSecond` field to an Option value (optional)
    pub fn maybe_points_per_second(mut self, value: Option<i64>) -> Self {
        self._fields.11 = value;
        self
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `rarityBreakdown` field (optional)
    pub fn rarity_breakdown(
        mut self,
        value: impl Into<Option<minigame::RarityBreakdown<'a>>>,
    ) -> Self {
        self._fields.12 = value.into();
        self
    }
    /// Set the `rarityBreakdown` field to an Option value (optional)
    pub fn maybe_rarity_breakdown(
        mut self,
        value: Option<minigame::RarityBreakdown<'a>>,
    ) -> Self {
        self._fields.12 = value;
        self
    }
}

impl<'a, S> MinigameBuilder<'a, S>
where
    S: minigame_state::State,
    S::RoundDuration: minigame_state::IsUnset,
{
    /// Set the `roundDuration` field (required)
    pub fn round_duration(
        mut self,
        value: impl Into<i64>,
    ) -> MinigameBuilder<'a, minigame_state::SetRoundDuration<S>> {
        self._fields.13 = Option::Some(value.into());
        MinigameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> MinigameBuilder<'a, S>
where
    S: minigame_state::State,
    S::ShapesCollected: minigame_state::IsUnset,
{
    /// Set the `shapesCollected` field (required)
    pub fn shapes_collected(
        mut self,
        value: impl Into<i64>,
    ) -> MinigameBuilder<'a, minigame_state::SetShapesCollected<S>> {
        self._fields.14 = Option::Some(value.into());
        MinigameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `shapesMissed` field (optional)
    pub fn shapes_missed(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.15 = value.into();
        self
    }
    /// Set the `shapesMissed` field to an Option value (optional)
    pub fn maybe_shapes_missed(mut self, value: Option<i64>) -> Self {
        self._fields.15 = value;
        self
    }
}

impl<'a, S: minigame_state::State> MinigameBuilder<'a, S> {
    /// Set the `totalShapesSpawned` field (optional)
    pub fn total_shapes_spawned(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.16 = value.into();
        self
    }
    /// Set the `totalShapesSpawned` field to an Option value (optional)
    pub fn maybe_total_shapes_spawned(mut self, value: Option<i64>) -> Self {
        self._fields.16 = value;
        self
    }
}

impl<'a, S> MinigameBuilder<'a, S>
where
    S: minigame_state::State,
    S::RoundDuration: minigame_state::IsSet,
    S::PlayedAt: minigame_state::IsSet,
    S::FinalScore: minigame_state::IsSet,
    S::ShapesCollected: minigame_state::IsSet,
    S::GameContext: minigame_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Minigame<'a> {
        Minigame {
            client_version: self._fields.0,
            created_at: self._fields.1,
            early_harvests: self._fields.2,
            efficiency_bonus: self._fields.3,
            final_score: self._fields.4.unwrap(),
            game_context: self._fields.5.unwrap(),
            late_harvests: self._fields.6,
            peak_harvest_rate: self._fields.7,
            peak_rate_bonus: self._fields.8,
            perfect_harvests: self._fields.9,
            played_at: self._fields.10.unwrap(),
            points_per_second: self._fields.11,
            rarity_breakdown: self._fields.12,
            round_duration: self._fields.13.unwrap(),
            shapes_collected: self._fields.14.unwrap(),
            shapes_missed: self._fields.15,
            total_shapes_spawned: self._fields.16,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Minigame<'a> {
        Minigame {
            client_version: self._fields.0,
            created_at: self._fields.1,
            early_harvests: self._fields.2,
            efficiency_bonus: self._fields.3,
            final_score: self._fields.4.unwrap(),
            game_context: self._fields.5.unwrap(),
            late_harvests: self._fields.6,
            peak_harvest_rate: self._fields.7,
            peak_rate_bonus: self._fields.8,
            perfect_harvests: self._fields.9,
            played_at: self._fields.10.unwrap(),
            points_per_second: self._fields.11,
            rarity_breakdown: self._fields.12,
            round_duration: self._fields.13.unwrap(),
            shapes_collected: self._fields.14.unwrap(),
            shapes_missed: self._fields.15,
            total_shapes_spawned: self._fields.16,
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_net_anisota_harvest_minigame() -> 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.harvest.minigame"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A record of a harvest minigame round played by a user",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("playedAt"),
                                SmolStr::new_static("roundDuration"),
                                SmolStr::new_static("gameContext"),
                                SmolStr::new_static("finalScore"),
                                SmolStr::new_static("shapesCollected")
                            ],
                        ),
                        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 Anisota client"),
                                    ),
                                    ..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("earlyHarvests"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("efficiencyBonus"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("finalScore"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("gameContext"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Where the game was played: dedicated minigame page or harvest loading screen",
                                        ),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("lateHarvests"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("peakHarvestRate"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    maximum: Some(10000i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("peakRateBonus"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("perfectHarvests"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("playedAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "When the game round was played (ISO 8601)",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("pointsPerSecond"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("rarityBreakdown"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#rarityBreakdown"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("roundDuration"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("shapesCollected"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("shapesMissed"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("totalShapesSpawned"),
                                LexObjectProperty::Integer(LexInteger {
                                    minimum: Some(0i64),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("rarityBreakdown"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Count of each rarity level collected"),
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("common"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rare"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("uncommon"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("veryCommon"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("veryRare"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(0i64),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}