// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: dev.tsunagite.game
//
// 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::blob::BlobRef;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, RecordKey, Rkey};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::dev_tsunagite::types::Indexable;
use crate::dev_tsunagite::game;
/// A closed set of indexable named values.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Enum<S: BosStr = DefaultStr> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    pub id: RecordKey<Rkey<S>>,
    ///The human-readable name of this component in UI.
    pub name: Data<S>,
    ///The allowed values for this enum to take.
    pub values: Vec<Indexable<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A record describing a game hosting leaderboards via Tsunagite.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "dev.tsunagite.game",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Game<S: BosStr = DefaultStr> {
    ///The default component for leaderboard sorting.
    pub default_component: RecordKey<Rkey<S>>,
    ///An array of usable input methods for the game. Optional if the game only has one input method or doesn't separate leaderboards by method.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub input_methods: Option<Vec<S>>,
    ///The obtainable judgments during gameplay.
    pub judgments: Vec<Indexable<S>>,
    ///The logo of the game, for display in UI.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logo: Option<BlobRef<S>>,
    ///An array of playable game modes with different gameplay configurations. Optional if the game only has one mode.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub modes: Option<Vec<S>>,
    ///The human-readable name of the game, for display in UI.
    pub name: Data<S>,
    ///All the components of a score in the game, including grades, lamps, EX score, and whatever other constructs are used.
    pub score_components: Vec<GameScoreComponentsItem<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum GameScoreComponentsItem<S: BosStr = DefaultStr> {
    #[serde(rename = "dev.tsunagite.game#enum")]
    Enum(Box<game::Enum<S>>),
    #[serde(rename = "dev.tsunagite.game#points")]
    Points(Box<game::Points<S>>),
    #[serde(rename = "dev.tsunagite.game#percentage")]
    Percentage(Box<game::Percentage<S>>),
    #[serde(rename = "dev.tsunagite.game#text")]
    Text(Box<game::Text<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 GameGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Game<S>,
}

/// A percentage score with customizable precision.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Percentage<S: BosStr = DefaultStr> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    pub id: RecordKey<Rkey<S>>,
    ///The maximum allowed percentage for this score.  Defaults to `100`.
    #[serde(default = "_default_percentage_maximum")]
    pub maximum: i64,
    ///The human-readable name of this component in UI.
    pub name: Data<S>,
    ///The number of decimal places to include in the percentage.  Defaults to `2`.
    #[serde(default = "_default_percentage_precision")]
    pub precision: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// An integer point score, with or without a cap.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Points<S: BosStr = DefaultStr> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    pub id: RecordKey<Rkey<S>>,
    ///The maximum allowed value for this score.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub maximum: Option<i64>,
    ///The human-readable name of this component in UI.
    pub name: Data<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A fallback component for displaying arbitrary text.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Text<S: BosStr = DefaultStr> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    pub id: RecordKey<Rkey<S>>,
    ///The human-readable name of this component in UI.
    pub name: Data<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

impl<S: BosStr> LexiconSchema for Enum<S> {
    fn nsid() -> &'static str {
        "dev.tsunagite.game"
    }
    fn def_name() -> &'static str {
        "enum"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_tsunagite_game()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("id"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("id"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Collection for Game<S> {
    const NSID: &'static str = "dev.tsunagite.game";
    type Record = GameRecord;
}

impl Collection for GameRecord {
    const NSID: &'static str = "dev.tsunagite.game";
    type Record = GameRecord;
}

impl<S: BosStr> LexiconSchema for Game<S> {
    fn nsid() -> &'static str {
        "dev.tsunagite.game"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_tsunagite_game()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.logo {
            {
                let size = value.blob().size;
                if size > 8000000usize {
                    return Err(ConstraintError::BlobTooLarge {
                        path: ValidationPath::from_field("logo"),
                        max: 8000000usize,
                        actual: size,
                    });
                }
            }
        }
        if let Some(ref value) = self.logo {
            {
                let mime = value.blob().mime_type.as_str();
                let accepted: &[&str] = &[
                    "image/png",
                    "image/jpeg",
                    "image/jxl",
                    "image/webp",
                ];
                let matched = accepted
                    .iter()
                    .any(|pattern| {
                        if *pattern == "*/*" {
                            true
                        } else if pattern.ends_with("/*") {
                            let prefix = &pattern[..pattern.len() - 2];
                            mime.starts_with(prefix)
                                && mime.as_bytes().get(prefix.len()) == Some(&b'/')
                        } else {
                            mime == *pattern
                        }
                    });
                if !matched {
                    return Err(ConstraintError::BlobMimeTypeNotAccepted {
                        path: ValidationPath::from_field("logo"),
                        accepted: vec![
                            "image/png".to_string(), "image/jpeg".to_string(),
                            "image/jxl".to_string(), "image/webp".to_string()
                        ],
                        actual: mime.to_string(),
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Percentage<S> {
    fn nsid() -> &'static str {
        "dev.tsunagite.game"
    }
    fn def_name() -> &'static str {
        "percentage"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_tsunagite_game()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("id"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("id"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Points<S> {
    fn nsid() -> &'static str {
        "dev.tsunagite.game"
    }
    fn def_name() -> &'static str {
        "points"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_tsunagite_game()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("id"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("id"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Text<S> {
    fn nsid() -> &'static str {
        "dev.tsunagite.game"
    }
    fn def_name() -> &'static str {
        "text"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_dev_tsunagite_game()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 32usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("id"),
                    max: 32usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.id;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("id"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

pub mod enum_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 Id;
        type Name;
        type Values;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Id = Unset;
        type Name = Unset;
        type Values = Unset;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetId<St> {}
    impl<St: State> State for SetId<St> {
        type Id = Set<members::id>;
        type Name = St::Name;
        type Values = St::Values;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Id = St::Id;
        type Name = Set<members::name>;
        type Values = St::Values;
    }
    ///State transition - sets the `values` field to Set
    pub struct SetValues<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetValues<St> {}
    impl<St: State> State for SetValues<St> {
        type Id = St::Id;
        type Name = St::Name;
        type Values = Set<members::values>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `values` field
        pub struct values(());
    }
}

/// Builder for constructing an instance of this type.
pub struct EnumBuilder<St: enum_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<RecordKey<Rkey<S>>>, Option<Data<S>>, Option<Vec<Indexable<S>>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Enum<S> {
    /// Create a new builder for this type
    pub fn builder() -> EnumBuilder<enum_state::Empty, S> {
        EnumBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> EnumBuilder<St, S>
where
    St: enum_state::State,
    St::Id: enum_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<RecordKey<Rkey<S>>>,
    ) -> EnumBuilder<enum_state::SetId<St>, S> {
        self._fields.0 = Option::Some(value.into());
        EnumBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EnumBuilder<St, S>
where
    St: enum_state::State,
    St::Name: enum_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<Data<S>>,
    ) -> EnumBuilder<enum_state::SetName<St>, S> {
        self._fields.1 = Option::Some(value.into());
        EnumBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EnumBuilder<St, S>
where
    St: enum_state::State,
    St::Values: enum_state::IsUnset,
{
    /// Set the `values` field (required)
    pub fn values(
        mut self,
        value: impl Into<Vec<Indexable<S>>>,
    ) -> EnumBuilder<enum_state::SetValues<St>, S> {
        self._fields.2 = Option::Some(value.into());
        EnumBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EnumBuilder<St, S>
where
    St: enum_state::State,
    St::Id: enum_state::IsSet,
    St::Name: enum_state::IsSet,
    St::Values: enum_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Enum<S> {
        Enum {
            id: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            values: self._fields.2.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>>) -> Enum<S> {
        Enum {
            id: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            values: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_dev_tsunagite_game() -> LexiconDoc<'static> {
    #[allow(unused_imports)]
    use jacquard_common::{CowStr, deps::smol_str::SmolStr, types::blob::MimeType};
    use jacquard_lexicon::lexicon::*;
    use alloc::collections::BTreeMap;
    LexiconDoc {
        lexicon: Lexicon::Lexicon1,
        id: CowStr::new_static("dev.tsunagite.game"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("enum"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("A closed set of indexable named values."),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("name"), SmolStr::new_static("id"),
                            SmolStr::new_static("values")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The internal ID of this component, limited to the RecordKey characterset.",
                                    ),
                                ),
                                format: Some(LexStringFormat::RecordKey),
                                min_length: Some(1usize),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("dev.tsunagite.translatable"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("values"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "The allowed values for this enum to take.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("dev.tsunagite.types#indexable"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A record describing a game hosting leaderboards via Tsunagite.",
                        ),
                    ),
                    key: Some(CowStr::new_static("any")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("name"),
                                SmolStr::new_static("judgments"),
                                SmolStr::new_static("scoreComponents"),
                                SmolStr::new_static("defaultComponent")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("defaultComponent"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "The default component for leaderboard sorting.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::RecordKey),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("inputMethods"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "An array of usable input methods for the game. Optional if the game only has one input method or doesn't separate leaderboards by method.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Can be tokens or raw strings."),
                                        ),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("judgments"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "The obtainable judgments during gameplay.",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("dev.tsunagite.types#indexable"),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("logo"),
                                LexObjectProperty::Blob(LexBlob { ..Default::default() }),
                            );
                            map.insert(
                                SmolStr::new_static("modes"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "An array of playable game modes with different gameplay configurations. Optional if the game only has one mode.",
                                        ),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        description: Some(
                                            CowStr::new_static("Can be tokens or raw strings."),
                                        ),
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("name"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("dev.tsunagite.translatable"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("scoreComponents"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "All the components of a score in the game, including grades, lamps, EX score, and whatever other constructs are used.",
                                        ),
                                    ),
                                    items: LexArrayItem::Union(LexRefUnion {
                                        refs: vec![
                                            CowStr::new_static("#enum"), CowStr::new_static("#points"),
                                            CowStr::new_static("#percentage"),
                                            CowStr::new_static("#text")
                                        ],
                                        ..Default::default()
                                    }),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("percentage"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A percentage score with customizable precision.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("name"), SmolStr::new_static("id"),
                            SmolStr::new_static("maximum"),
                            SmolStr::new_static("precision")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The internal ID of this component, limited to the RecordKey characterset.",
                                    ),
                                ),
                                format: Some(LexStringFormat::RecordKey),
                                min_length: Some(1usize),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("maximum"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("dev.tsunagite.translatable"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("precision"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("points"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "An integer point score, with or without a cap.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("name"), SmolStr::new_static("id")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The internal ID of this component, limited to the RecordKey characterset.",
                                    ),
                                ),
                                format: Some(LexStringFormat::RecordKey),
                                min_length: Some(1usize),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("maximum"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("dev.tsunagite.translatable"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("text"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A fallback component for displaying arbitrary text.",
                        ),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("name"), SmolStr::new_static("id")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The internal ID of this component, limited to the RecordKey characterset.",
                                    ),
                                ),
                                format: Some(LexStringFormat::RecordKey),
                                min_length: Some(1usize),
                                max_length: Some(32usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("dev.tsunagite.translatable"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod game_state {

    pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
    #[allow(unused)]
    use ::core::marker::PhantomData;
    mod sealed {
        pub trait Sealed {}
    }
    /// State trait tracking which required fields have been set
    pub trait State: sealed::Sealed {
        type DefaultComponent;
        type Judgments;
        type Name;
        type ScoreComponents;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type DefaultComponent = Unset;
        type Judgments = Unset;
        type Name = Unset;
        type ScoreComponents = Unset;
    }
    ///State transition - sets the `default_component` field to Set
    pub struct SetDefaultComponent<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDefaultComponent<St> {}
    impl<St: State> State for SetDefaultComponent<St> {
        type DefaultComponent = Set<members::default_component>;
        type Judgments = St::Judgments;
        type Name = St::Name;
        type ScoreComponents = St::ScoreComponents;
    }
    ///State transition - sets the `judgments` field to Set
    pub struct SetJudgments<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetJudgments<St> {}
    impl<St: State> State for SetJudgments<St> {
        type DefaultComponent = St::DefaultComponent;
        type Judgments = Set<members::judgments>;
        type Name = St::Name;
        type ScoreComponents = St::ScoreComponents;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type DefaultComponent = St::DefaultComponent;
        type Judgments = St::Judgments;
        type Name = Set<members::name>;
        type ScoreComponents = St::ScoreComponents;
    }
    ///State transition - sets the `score_components` field to Set
    pub struct SetScoreComponents<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetScoreComponents<St> {}
    impl<St: State> State for SetScoreComponents<St> {
        type DefaultComponent = St::DefaultComponent;
        type Judgments = St::Judgments;
        type Name = St::Name;
        type ScoreComponents = Set<members::score_components>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `default_component` field
        pub struct default_component(());
        ///Marker type for the `judgments` field
        pub struct judgments(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `score_components` field
        pub struct score_components(());
    }
}

/// Builder for constructing an instance of this type.
pub struct GameBuilder<St: game_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<RecordKey<Rkey<S>>>,
        Option<Vec<S>>,
        Option<Vec<Indexable<S>>>,
        Option<BlobRef<S>>,
        Option<Vec<S>>,
        Option<Data<S>>,
        Option<Vec<GameScoreComponentsItem<S>>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Game<S> {
    /// Create a new builder for this type
    pub fn builder() -> GameBuilder<game_state::Empty, S> {
        GameBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> GameBuilder<St, S>
where
    St: game_state::State,
    St::DefaultComponent: game_state::IsUnset,
{
    /// Set the `defaultComponent` field (required)
    pub fn default_component(
        mut self,
        value: impl Into<RecordKey<Rkey<S>>>,
    ) -> GameBuilder<game_state::SetDefaultComponent<St>, S> {
        self._fields.0 = Option::Some(value.into());
        GameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: game_state::State, S: BosStr> GameBuilder<St, S> {
    /// Set the `inputMethods` field (optional)
    pub fn input_methods(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `inputMethods` field to an Option value (optional)
    pub fn maybe_input_methods(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> GameBuilder<St, S>
where
    St: game_state::State,
    St::Judgments: game_state::IsUnset,
{
    /// Set the `judgments` field (required)
    pub fn judgments(
        mut self,
        value: impl Into<Vec<Indexable<S>>>,
    ) -> GameBuilder<game_state::SetJudgments<St>, S> {
        self._fields.2 = Option::Some(value.into());
        GameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: game_state::State, S: BosStr> GameBuilder<St, S> {
    /// Set the `logo` field (optional)
    pub fn logo(mut self, value: impl Into<Option<BlobRef<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `logo` field to an Option value (optional)
    pub fn maybe_logo(mut self, value: Option<BlobRef<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St: game_state::State, S: BosStr> GameBuilder<St, S> {
    /// Set the `modes` field (optional)
    pub fn modes(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `modes` field to an Option value (optional)
    pub fn maybe_modes(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> GameBuilder<St, S>
where
    St: game_state::State,
    St::Name: game_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<Data<S>>,
    ) -> GameBuilder<game_state::SetName<St>, S> {
        self._fields.5 = Option::Some(value.into());
        GameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GameBuilder<St, S>
where
    St: game_state::State,
    St::ScoreComponents: game_state::IsUnset,
{
    /// Set the `scoreComponents` field (required)
    pub fn score_components(
        mut self,
        value: impl Into<Vec<GameScoreComponentsItem<S>>>,
    ) -> GameBuilder<game_state::SetScoreComponents<St>, S> {
        self._fields.6 = Option::Some(value.into());
        GameBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> GameBuilder<St, S>
where
    St: game_state::State,
    St::DefaultComponent: game_state::IsSet,
    St::Judgments: game_state::IsSet,
    St::Name: game_state::IsSet,
    St::ScoreComponents: game_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Game<S> {
        Game {
            default_component: self._fields.0.unwrap(),
            input_methods: self._fields.1,
            judgments: self._fields.2.unwrap(),
            logo: self._fields.3,
            modes: self._fields.4,
            name: self._fields.5.unwrap(),
            score_components: self._fields.6.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>>) -> Game<S> {
        Game {
            default_component: self._fields.0.unwrap(),
            input_methods: self._fields.1,
            judgments: self._fields.2.unwrap(),
            logo: self._fields.3,
            modes: self._fields.4,
            name: self._fields.5.unwrap(),
            score_components: self._fields.6.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn _default_percentage_maximum() -> i64 {
    100i64
}

fn _default_percentage_precision() -> i64 {
    2i64
}

pub mod percentage_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 Id;
        type Maximum;
        type Name;
        type Precision;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Id = Unset;
        type Maximum = Unset;
        type Name = Unset;
        type Precision = Unset;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetId<St> {}
    impl<St: State> State for SetId<St> {
        type Id = Set<members::id>;
        type Maximum = St::Maximum;
        type Name = St::Name;
        type Precision = St::Precision;
    }
    ///State transition - sets the `maximum` field to Set
    pub struct SetMaximum<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMaximum<St> {}
    impl<St: State> State for SetMaximum<St> {
        type Id = St::Id;
        type Maximum = Set<members::maximum>;
        type Name = St::Name;
        type Precision = St::Precision;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Id = St::Id;
        type Maximum = St::Maximum;
        type Name = Set<members::name>;
        type Precision = St::Precision;
    }
    ///State transition - sets the `precision` field to Set
    pub struct SetPrecision<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPrecision<St> {}
    impl<St: State> State for SetPrecision<St> {
        type Id = St::Id;
        type Maximum = St::Maximum;
        type Name = St::Name;
        type Precision = Set<members::precision>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `maximum` field
        pub struct maximum(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `precision` field
        pub struct precision(());
    }
}

/// Builder for constructing an instance of this type.
pub struct PercentageBuilder<St: percentage_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<RecordKey<Rkey<S>>>, Option<i64>, Option<Data<S>>, Option<i64>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Percentage<S> {
    /// Create a new builder for this type
    pub fn builder() -> PercentageBuilder<percentage_state::Empty, S> {
        PercentageBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> PercentageBuilder<St, S>
where
    St: percentage_state::State,
    St::Id: percentage_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<RecordKey<Rkey<S>>>,
    ) -> PercentageBuilder<percentage_state::SetId<St>, S> {
        self._fields.0 = Option::Some(value.into());
        PercentageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PercentageBuilder<St, S>
where
    St: percentage_state::State,
    St::Maximum: percentage_state::IsUnset,
{
    /// Set the `maximum` field (required)
    pub fn maximum(
        mut self,
        value: impl Into<i64>,
    ) -> PercentageBuilder<percentage_state::SetMaximum<St>, S> {
        self._fields.1 = Option::Some(value.into());
        PercentageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PercentageBuilder<St, S>
where
    St: percentage_state::State,
    St::Name: percentage_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<Data<S>>,
    ) -> PercentageBuilder<percentage_state::SetName<St>, S> {
        self._fields.2 = Option::Some(value.into());
        PercentageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PercentageBuilder<St, S>
where
    St: percentage_state::State,
    St::Precision: percentage_state::IsUnset,
{
    /// Set the `precision` field (required)
    pub fn precision(
        mut self,
        value: impl Into<i64>,
    ) -> PercentageBuilder<percentage_state::SetPrecision<St>, S> {
        self._fields.3 = Option::Some(value.into());
        PercentageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PercentageBuilder<St, S>
where
    St: percentage_state::State,
    St::Id: percentage_state::IsSet,
    St::Maximum: percentage_state::IsSet,
    St::Name: percentage_state::IsSet,
    St::Precision: percentage_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Percentage<S> {
        Percentage {
            id: self._fields.0.unwrap(),
            maximum: self._fields.1.unwrap(),
            name: self._fields.2.unwrap(),
            precision: self._fields.3.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>>,
    ) -> Percentage<S> {
        Percentage {
            id: self._fields.0.unwrap(),
            maximum: self._fields.1.unwrap(),
            name: self._fields.2.unwrap(),
            precision: self._fields.3.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod points_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 Id;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Id = Unset;
        type Name = Unset;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetId<St> {}
    impl<St: State> State for SetId<St> {
        type Id = Set<members::id>;
        type Name = St::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Id = St::Id;
        type Name = Set<members::name>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `name` field
        pub struct name(());
    }
}

/// Builder for constructing an instance of this type.
pub struct PointsBuilder<St: points_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<RecordKey<Rkey<S>>>, Option<i64>, Option<Data<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Points<S> {
    /// Create a new builder for this type
    pub fn builder() -> PointsBuilder<points_state::Empty, S> {
        PointsBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> PointsBuilder<St, S>
where
    St: points_state::State,
    St::Id: points_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<RecordKey<Rkey<S>>>,
    ) -> PointsBuilder<points_state::SetId<St>, S> {
        self._fields.0 = Option::Some(value.into());
        PointsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: points_state::State, S: BosStr> PointsBuilder<St, S> {
    /// Set the `maximum` field (optional)
    pub fn maximum(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `maximum` field to an Option value (optional)
    pub fn maybe_maximum(mut self, value: Option<i64>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> PointsBuilder<St, S>
where
    St: points_state::State,
    St::Name: points_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<Data<S>>,
    ) -> PointsBuilder<points_state::SetName<St>, S> {
        self._fields.2 = Option::Some(value.into());
        PointsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> PointsBuilder<St, S>
where
    St: points_state::State,
    St::Id: points_state::IsSet,
    St::Name: points_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Points<S> {
        Points {
            id: self._fields.0.unwrap(),
            maximum: self._fields.1,
            name: self._fields.2.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>>) -> Points<S> {
        Points {
            id: self._fields.0.unwrap(),
            maximum: self._fields.1,
            name: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod text_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 Id;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Id = Unset;
        type Name = Unset;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetId<St> {}
    impl<St: State> State for SetId<St> {
        type Id = Set<members::id>;
        type Name = St::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetName<St> {}
    impl<St: State> State for SetName<St> {
        type Id = St::Id;
        type Name = Set<members::name>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `name` field
        pub struct name(());
    }
}

/// Builder for constructing an instance of this type.
pub struct TextBuilder<St: text_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<RecordKey<Rkey<S>>>, Option<Data<S>>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Text<S> {
    /// Create a new builder for this type
    pub fn builder() -> TextBuilder<text_state::Empty, S> {
        TextBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> TextBuilder<St, S>
where
    St: text_state::State,
    St::Id: text_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<RecordKey<Rkey<S>>>,
    ) -> TextBuilder<text_state::SetId<St>, S> {
        self._fields.0 = Option::Some(value.into());
        TextBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TextBuilder<St, S>
where
    St: text_state::State,
    St::Name: text_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<Data<S>>,
    ) -> TextBuilder<text_state::SetName<St>, S> {
        self._fields.1 = Option::Some(value.into());
        TextBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> TextBuilder<St, S>
where
    St: text_state::State,
    St::Id: text_state::IsSet,
    St::Name: text_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Text<S> {
        Text {
            id: self._fields.0.unwrap(),
            name: self._fields.1.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>>) -> Text<S> {
        Text {
            id: self._fields.0.unwrap(),
            name: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}