// @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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Enum<'a> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    #[serde(borrow)]
    pub id: RecordKey<Rkey<'a>>,
    ///The human-readable name of this component in UI.
    #[serde(borrow)]
    pub name: Data<'a>,
    ///The allowed values for this enum to take.
    #[serde(borrow)]
    pub values: Vec<Indexable<'a>>,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Game<'a> {
    ///The default component for leaderboard sorting.
    #[serde(borrow)]
    pub default_component: RecordKey<Rkey<'a>>,
    ///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")]
    #[serde(borrow)]
    pub input_methods: Option<Vec<CowStr<'a>>>,
    ///The obtainable judgments during gameplay.
    #[serde(borrow)]
    pub judgments: Vec<Indexable<'a>>,
    ///The logo of the game, for display in UI.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub logo: Option<BlobRef<'a>>,
    ///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")]
    #[serde(borrow)]
    pub modes: Option<Vec<CowStr<'a>>>,
    ///The human-readable name of the game, for display in UI.
    #[serde(borrow)]
    pub name: Data<'a>,
    ///All the components of a score in the game, including grades, lamps, EX score, and whatever other constructs are used.
    #[serde(borrow)]
    pub score_components: Vec<GameScoreComponentsItem<'a>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum GameScoreComponentsItem<'a> {
    #[serde(rename = "dev.tsunagite.game#enum")]
    Enum(Box<game::Enum<'a>>),
    #[serde(rename = "dev.tsunagite.game#points")]
    Points(Box<game::Points<'a>>),
    #[serde(rename = "dev.tsunagite.game#percentage")]
    Percentage(Box<game::Percentage<'a>>),
    #[serde(rename = "dev.tsunagite.game#text")]
    Text(Box<game::Text<'a>>),
}

/// 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<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub cid: Option<Cid<'a>>,
    #[serde(borrow)]
    pub uri: AtUri<'a>,
    #[serde(borrow)]
    pub value: Game<'a>,
}

/// A percentage score with customizable precision.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Percentage<'a> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    #[serde(borrow)]
    pub id: RecordKey<Rkey<'a>>,
    ///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.
    #[serde(borrow)]
    pub name: Data<'a>,
    ///The number of decimal places to include in the percentage.  Defaults to `2`.
    #[serde(default = "_default_percentage_precision")]
    pub precision: i64,
}

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Points<'a> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    #[serde(borrow)]
    pub id: RecordKey<Rkey<'a>>,
    ///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.
    #[serde(borrow)]
    pub name: Data<'a>,
}

/// A fallback component for displaying arbitrary text.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Text<'a> {
    ///The internal ID of this component, limited to the RecordKey characterset.
    #[serde(borrow)]
    pub id: RecordKey<Rkey<'a>>,
    ///The human-readable name of this component in UI.
    #[serde(borrow)]
    pub name: Data<'a>,
}

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

impl<'a> LexiconSchema for Enum<'a> {
    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<'de> = GameGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

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

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

impl<'a> LexiconSchema for Game<'a> {
    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<'a> LexiconSchema for Percentage<'a> {
    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<'a> LexiconSchema for Points<'a> {
    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<'a> LexiconSchema for Text<'a> {
    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 Values;
        type Id;
        type Name;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Values = Unset;
        type Id = Unset;
        type Name = Unset;
    }
    ///State transition - sets the `values` field to Set
    pub struct SetValues<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetValues<S> {}
    impl<S: State> State for SetValues<S> {
        type Values = Set<members::values>;
        type Id = S::Id;
        type Name = S::Name;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetId<S> {}
    impl<S: State> State for SetId<S> {
        type Values = S::Values;
        type Id = Set<members::id>;
        type Name = S::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Values = S::Values;
        type Id = S::Id;
        type Name = Set<members::name>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `values` field
        pub struct values(());
        ///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 EnumBuilder<'a, S: enum_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<RecordKey<Rkey<'a>>>, Option<Data<'a>>, Option<Vec<Indexable<'a>>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

impl<'a, S> EnumBuilder<'a, S>
where
    S: enum_state::State,
    S::Values: enum_state::IsSet,
    S::Id: enum_state::IsSet,
    S::Name: enum_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Enum<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Enum<'a> {
        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 ScoreComponents;
        type DefaultComponent;
        type Name;
        type Judgments;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type ScoreComponents = Unset;
        type DefaultComponent = Unset;
        type Name = Unset;
        type Judgments = Unset;
    }
    ///State transition - sets the `score_components` field to Set
    pub struct SetScoreComponents<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetScoreComponents<S> {}
    impl<S: State> State for SetScoreComponents<S> {
        type ScoreComponents = Set<members::score_components>;
        type DefaultComponent = S::DefaultComponent;
        type Name = S::Name;
        type Judgments = S::Judgments;
    }
    ///State transition - sets the `default_component` field to Set
    pub struct SetDefaultComponent<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetDefaultComponent<S> {}
    impl<S: State> State for SetDefaultComponent<S> {
        type ScoreComponents = S::ScoreComponents;
        type DefaultComponent = Set<members::default_component>;
        type Name = S::Name;
        type Judgments = S::Judgments;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type ScoreComponents = S::ScoreComponents;
        type DefaultComponent = S::DefaultComponent;
        type Name = Set<members::name>;
        type Judgments = S::Judgments;
    }
    ///State transition - sets the `judgments` field to Set
    pub struct SetJudgments<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetJudgments<S> {}
    impl<S: State> State for SetJudgments<S> {
        type ScoreComponents = S::ScoreComponents;
        type DefaultComponent = S::DefaultComponent;
        type Name = S::Name;
        type Judgments = Set<members::judgments>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `score_components` field
        pub struct score_components(());
        ///Marker type for the `default_component` field
        pub struct default_component(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `judgments` field
        pub struct judgments(());
    }
}

/// Builder for constructing an instance of this type
pub struct GameBuilder<'a, S: game_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<RecordKey<Rkey<'a>>>,
        Option<Vec<CowStr<'a>>>,
        Option<Vec<Indexable<'a>>>,
        Option<BlobRef<'a>>,
        Option<Vec<CowStr<'a>>>,
        Option<Data<'a>>,
        Option<Vec<GameScoreComponentsItem<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: game_state::State> GameBuilder<'a, S> {
    /// Set the `inputMethods` field (optional)
    pub fn input_methods(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

impl<'a, S: game_state::State> GameBuilder<'a, S> {
    /// Set the `logo` field (optional)
    pub fn logo(mut self, value: impl Into<Option<BlobRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S: game_state::State> GameBuilder<'a, S> {
    /// Set the `modes` field (optional)
    pub fn modes(mut self, value: impl Into<Option<Vec<CowStr<'a>>>>) -> 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<CowStr<'a>>>) -> Self {
        self._fields.4 = value;
        self
    }
}

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

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

impl<'a, S> GameBuilder<'a, S>
where
    S: game_state::State,
    S::ScoreComponents: game_state::IsSet,
    S::DefaultComponent: game_state::IsSet,
    S::Name: game_state::IsSet,
    S::Judgments: game_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Game<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Game<'a> {
        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 Maximum;
        type Name;
        type Id;
        type Precision;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Maximum = Unset;
        type Name = Unset;
        type Id = Unset;
        type Precision = Unset;
    }
    ///State transition - sets the `maximum` field to Set
    pub struct SetMaximum<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMaximum<S> {}
    impl<S: State> State for SetMaximum<S> {
        type Maximum = Set<members::maximum>;
        type Name = S::Name;
        type Id = S::Id;
        type Precision = S::Precision;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Maximum = S::Maximum;
        type Name = Set<members::name>;
        type Id = S::Id;
        type Precision = S::Precision;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetId<S> {}
    impl<S: State> State for SetId<S> {
        type Maximum = S::Maximum;
        type Name = S::Name;
        type Id = Set<members::id>;
        type Precision = S::Precision;
    }
    ///State transition - sets the `precision` field to Set
    pub struct SetPrecision<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPrecision<S> {}
    impl<S: State> State for SetPrecision<S> {
        type Maximum = S::Maximum;
        type Name = S::Name;
        type Id = S::Id;
        type Precision = Set<members::precision>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `maximum` field
        pub struct maximum(());
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `precision` field
        pub struct precision(());
    }
}

/// Builder for constructing an instance of this type
pub struct PercentageBuilder<'a, S: percentage_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<RecordKey<Rkey<'a>>>, Option<i64>, Option<Data<'a>>, Option<i64>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

impl<'a, S> PercentageBuilder<'a, S>
where
    S: percentage_state::State,
    S::Maximum: percentage_state::IsSet,
    S::Name: percentage_state::IsSet,
    S::Id: percentage_state::IsSet,
    S::Precision: percentage_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Percentage<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Percentage<'a> {
        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 Name;
        type Id;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Name = Unset;
        type Id = Unset;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Name = Set<members::name>;
        type Id = S::Id;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetId<S> {}
    impl<S: State> State for SetId<S> {
        type Name = S::Name;
        type Id = Set<members::id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `name` field
        pub struct name(());
        ///Marker type for the `id` field
        pub struct id(());
    }
}

/// Builder for constructing an instance of this type
pub struct PointsBuilder<'a, S: points_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<RecordKey<Rkey<'a>>>, Option<i64>, Option<Data<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

impl<'a, S: points_state::State> PointsBuilder<'a, 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<'a, S> PointsBuilder<'a, S>
where
    S: points_state::State,
    S::Name: points_state::IsUnset,
{
    /// Set the `name` field (required)
    pub fn name(
        mut self,
        value: impl Into<Data<'a>>,
    ) -> PointsBuilder<'a, points_state::SetName<S>> {
        self._fields.2 = Option::Some(value.into());
        PointsBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> PointsBuilder<'a, S>
where
    S: points_state::State,
    S::Name: points_state::IsSet,
    S::Id: points_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Points<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> Points<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetId<S> {}
    impl<S: State> State for SetId<S> {
        type Id = Set<members::id>;
        type Name = S::Name;
    }
    ///State transition - sets the `name` field to Set
    pub struct SetName<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetName<S> {}
    impl<S: State> State for SetName<S> {
        type Id = S::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<'a, S: text_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<RecordKey<Rkey<'a>>>, Option<Data<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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