// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: pub.quizzy.quiz
//
// This file was automatically generated from Lexicon schemas.
// Any manual changes will be overwritten on the next regeneration.

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};

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

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::pub_quizzy::quiz;
/// A quiz containing one or more rounds of questions

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "pub.quizzy.quiz",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Quiz<S: BosStr = DefaultStr> {
    ///A short description about the quiz, and what to expect from it
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///This quiz includes questions with audio, eg. a music round  Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_quiz_has_audio")]
    pub has_audio: Option<bool>,
    ///This quiz includes questions with visuals, eg. a picture round  Defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_quiz_has_visuals")]
    pub has_visuals: Option<bool>,
    ///Dominant language(s) of the quiz
    pub locales: Vec<Language>,
    ///If this is an edit or revision of a previous quiz, link that previous version here.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub revision_of: Option<StrongRef<S>>,
    ///Ordered list of rounds in this quiz
    pub rounds: Vec<quiz::Round<S>>,
    ///When this quiz was created
    pub timestamp: Datetime,
    ///A title for the quiz
    pub title: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

/// Reference to a question with its point value

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct QuestionRef<S: BosStr = DefaultStr> {
    ///A custom name for this question, as opposed to its number
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<S>,
    ///Points awarded for complete correctness  Defaults to `1`.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(default = "_default_question_ref_points")]
    pub points: Option<i64>,
    pub question: StrongRef<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A round within a quiz

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Round<S: BosStr = DefaultStr> {
    ///Ordered list of questions in this round
    pub questions: Vec<quiz::QuestionRef<S>>,
    ///Optional title for this round (requires locale if set)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub title: Option<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

impl<S: BosStr> Collection for Quiz<S> {
    const NSID: &'static str = "pub.quizzy.quiz";
    type Record = QuizRecord;
}

impl Collection for QuizRecord {
    const NSID: &'static str = "pub.quizzy.quiz";
    type Record = QuizRecord;
}

impl<S: BosStr> LexiconSchema for Quiz<S> {
    fn nsid() -> &'static str {
        "pub.quizzy.quiz"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_quizzy_quiz()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 300usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 300usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.description {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 3000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("description"),
                        max: 3000usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.locales;
            #[allow(unused_comparisons)]
            if value.len() > 10usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("locales"),
                    max: 10usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.locales;
            #[allow(unused_comparisons)]
            if value.len() < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("locales"),
                    min: 1usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.rounds;
            #[allow(unused_comparisons)]
            if value.len() > 50usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("rounds"),
                    max: 50usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.rounds;
            #[allow(unused_comparisons)]
            if value.len() < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("rounds"),
                    min: 1usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for QuestionRef<S> {
    fn nsid() -> &'static str {
        "pub.quizzy.quiz"
    }
    fn def_name() -> &'static str {
        "questionRef"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_quizzy_quiz()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.name {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 16usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 16usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.name {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 160usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("name"),
                        max: 160usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.points {
            if *value < 1i64 {
                return Err(ConstraintError::Minimum {
                    path: ValidationPath::from_field("points"),
                    min: 1i64,
                    actual: *value,
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Round<S> {
    fn nsid() -> &'static str {
        "pub.quizzy.quiz"
    }
    fn def_name() -> &'static str {
        "round"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_pub_quizzy_quiz()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.questions;
            #[allow(unused_comparisons)]
            if value.len() > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("questions"),
                    max: 100usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.questions;
            #[allow(unused_comparisons)]
            if value.len() < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("questions"),
                    min: 1usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.title {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("title"),
                    max: 1000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.title {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 100usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("title"),
                        max: 100usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

fn _default_quiz_has_audio() -> Option<bool> {
    Some(false)
}

fn _default_quiz_has_visuals() -> Option<bool> {
    Some(false)
}

pub mod quiz_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 Locales;
        type Rounds;
        type Timestamp;
        type Title;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Locales = Unset;
        type Rounds = Unset;
        type Timestamp = Unset;
        type Title = Unset;
    }
    ///State transition - sets the `locales` field to Set
    pub struct SetLocales<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLocales<St> {}
    impl<St: State> State for SetLocales<St> {
        type Locales = Set<members::locales>;
        type Rounds = St::Rounds;
        type Timestamp = St::Timestamp;
        type Title = St::Title;
    }
    ///State transition - sets the `rounds` field to Set
    pub struct SetRounds<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetRounds<St> {}
    impl<St: State> State for SetRounds<St> {
        type Locales = St::Locales;
        type Rounds = Set<members::rounds>;
        type Timestamp = St::Timestamp;
        type Title = St::Title;
    }
    ///State transition - sets the `timestamp` field to Set
    pub struct SetTimestamp<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTimestamp<St> {}
    impl<St: State> State for SetTimestamp<St> {
        type Locales = St::Locales;
        type Rounds = St::Rounds;
        type Timestamp = Set<members::timestamp>;
        type Title = St::Title;
    }
    ///State transition - sets the `title` field to Set
    pub struct SetTitle<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetTitle<St> {}
    impl<St: State> State for SetTitle<St> {
        type Locales = St::Locales;
        type Rounds = St::Rounds;
        type Timestamp = St::Timestamp;
        type Title = Set<members::title>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `locales` field
        pub struct locales(());
        ///Marker type for the `rounds` field
        pub struct rounds(());
        ///Marker type for the `timestamp` field
        pub struct timestamp(());
        ///Marker type for the `title` field
        pub struct title(());
    }
}

/// Builder for constructing an instance of this type.
pub struct QuizBuilder<St: quiz_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<S>,
        Option<bool>,
        Option<bool>,
        Option<Vec<Language>>,
        Option<StrongRef<S>>,
        Option<Vec<quiz::Round<S>>>,
        Option<Datetime>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Quiz<S> {
    /// Create a new builder for this type
    pub fn builder() -> QuizBuilder<quiz_state::Empty, S> {
        QuizBuilder::builder()
    }
}

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

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

impl<St: quiz_state::State, S: BosStr> QuizBuilder<St, S> {
    /// Set the `description` field (optional)
    pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `description` field to an Option value (optional)
    pub fn maybe_description(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: quiz_state::State, S: BosStr> QuizBuilder<St, S> {
    /// Set the `hasAudio` field (optional)
    pub fn has_audio(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `hasAudio` field to an Option value (optional)
    pub fn maybe_has_audio(mut self, value: Option<bool>) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St: quiz_state::State, S: BosStr> QuizBuilder<St, S> {
    /// Set the `hasVisuals` field (optional)
    pub fn has_visuals(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `hasVisuals` field to an Option value (optional)
    pub fn maybe_has_visuals(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<St, S: BosStr> QuizBuilder<St, S>
where
    St: quiz_state::State,
    St::Locales: quiz_state::IsUnset,
{
    /// Set the `locales` field (required)
    pub fn locales(
        mut self,
        value: impl Into<Vec<Language>>,
    ) -> QuizBuilder<quiz_state::SetLocales<St>, S> {
        self._fields.3 = Option::Some(value.into());
        QuizBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: quiz_state::State, S: BosStr> QuizBuilder<St, S> {
    /// Set the `revisionOf` field (optional)
    pub fn revision_of(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.4 = value.into();
        self
    }
    /// Set the `revisionOf` field to an Option value (optional)
    pub fn maybe_revision_of(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.4 = value;
        self
    }
}

impl<St, S: BosStr> QuizBuilder<St, S>
where
    St: quiz_state::State,
    St::Rounds: quiz_state::IsUnset,
{
    /// Set the `rounds` field (required)
    pub fn rounds(
        mut self,
        value: impl Into<Vec<quiz::Round<S>>>,
    ) -> QuizBuilder<quiz_state::SetRounds<St>, S> {
        self._fields.5 = Option::Some(value.into());
        QuizBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> QuizBuilder<St, S>
where
    St: quiz_state::State,
    St::Title: quiz_state::IsUnset,
{
    /// Set the `title` field (required)
    pub fn title(
        mut self,
        value: impl Into<S>,
    ) -> QuizBuilder<quiz_state::SetTitle<St>, S> {
        self._fields.7 = Option::Some(value.into());
        QuizBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> QuizBuilder<St, S>
where
    St: quiz_state::State,
    St::Locales: quiz_state::IsSet,
    St::Rounds: quiz_state::IsSet,
    St::Timestamp: quiz_state::IsSet,
    St::Title: quiz_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Quiz<S> {
        Quiz {
            description: self._fields.0,
            has_audio: self._fields.1.or_else(|| Some(false)),
            has_visuals: self._fields.2.or_else(|| Some(false)),
            locales: self._fields.3.unwrap(),
            revision_of: self._fields.4,
            rounds: self._fields.5.unwrap(),
            timestamp: self._fields.6.unwrap(),
            title: self._fields.7.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>>) -> Quiz<S> {
        Quiz {
            description: self._fields.0,
            has_audio: self._fields.1.or_else(|| Some(false)),
            has_visuals: self._fields.2.or_else(|| Some(false)),
            locales: self._fields.3.unwrap(),
            revision_of: self._fields.4,
            rounds: self._fields.5.unwrap(),
            timestamp: self._fields.6.unwrap(),
            title: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_pub_quizzy_quiz() -> 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("pub.quizzy.quiz"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "A quiz containing one or more rounds of questions",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("title"), SmolStr::new_static("rounds"),
                                SmolStr::new_static("locales"),
                                SmolStr::new_static("timestamp")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("description"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "A short description about the quiz, and what to expect from it",
                                        ),
                                    ),
                                    max_length: Some(300usize),
                                    max_graphemes: Some(3000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("hasAudio"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("hasVisuals"),
                                LexObjectProperty::Boolean(LexBoolean {
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("locales"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("Dominant language(s) of the quiz"),
                                    ),
                                    items: LexArrayItem::String(LexString {
                                        format: Some(LexStringFormat::Language),
                                        ..Default::default()
                                    }),
                                    min_length: Some(1usize),
                                    max_length: Some(10usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("revisionOf"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("rounds"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("Ordered list of rounds in this quiz"),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("#round"),
                                        ..Default::default()
                                    }),
                                    min_length: Some(1usize),
                                    max_length: Some(50usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("timestamp"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("When this quiz was created"),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("title"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("A title for the quiz"),
                                    ),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("questionRef"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Reference to a question with its point value",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("question")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "A custom name for this question, as opposed to its number",
                                    ),
                                ),
                                max_length: Some(16usize),
                                max_graphemes: Some(160usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("points"),
                            LexObjectProperty::Integer(LexInteger {
                                minimum: Some(1i64),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("question"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("round"),
                LexUserType::Object(LexObject {
                    description: Some(CowStr::new_static("A round within a quiz")),
                    required: Some(vec![SmolStr::new_static("questions")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("questions"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Ordered list of questions in this round",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#questionRef"),
                                    ..Default::default()
                                }),
                                min_length: Some(1usize),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("title"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Optional title for this round (requires locale if set)",
                                    ),
                                ),
                                max_length: Some(1000usize),
                                max_graphemes: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

fn _default_question_ref_points() -> Option<i64> {
    Some(1i64)
}

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

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

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

impl<S: BosStr> QuestionRef<S> {
    /// Create a new builder for this type
    pub fn builder() -> QuestionRefBuilder<question_ref_state::Empty, S> {
        QuestionRefBuilder::builder()
    }
}

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

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

impl<St: question_ref_state::State, S: BosStr> QuestionRefBuilder<St, S> {
    /// Set the `name` field (optional)
    pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `name` field to an Option value (optional)
    pub fn maybe_name(mut self, value: Option<S>) -> Self {
        self._fields.0 = value;
        self
    }
}

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

impl<St, S: BosStr> QuestionRefBuilder<St, S>
where
    St: question_ref_state::State,
    St::Question: question_ref_state::IsUnset,
{
    /// Set the `question` field (required)
    pub fn question(
        mut self,
        value: impl Into<StrongRef<S>>,
    ) -> QuestionRefBuilder<question_ref_state::SetQuestion<St>, S> {
        self._fields.2 = Option::Some(value.into());
        QuestionRefBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> QuestionRefBuilder<St, S>
where
    St: question_ref_state::State,
    St::Question: question_ref_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> QuestionRef<S> {
        QuestionRef {
            name: self._fields.0,
            points: self._fields.1.or_else(|| Some(1i64)),
            question: 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>>,
    ) -> QuestionRef<S> {
        QuestionRef {
            name: self._fields.0,
            points: self._fields.1.or_else(|| Some(1i64)),
            question: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

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

/// Builder for constructing an instance of this type.
pub struct RoundBuilder<St: round_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<Vec<quiz::QuestionRef<S>>>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Round<S> {
    /// Create a new builder for this type
    pub fn builder() -> RoundBuilder<round_state::Empty, S> {
        RoundBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> RoundBuilder<St, S>
where
    St: round_state::State,
    St::Questions: round_state::IsUnset,
{
    /// Set the `questions` field (required)
    pub fn questions(
        mut self,
        value: impl Into<Vec<quiz::QuestionRef<S>>>,
    ) -> RoundBuilder<round_state::SetQuestions<St>, S> {
        self._fields.0 = Option::Some(value.into());
        RoundBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> RoundBuilder<St, S>
where
    St: round_state::State,
    St::Questions: round_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Round<S> {
        Round {
            questions: self._fields.0.unwrap(),
            title: self._fields.1,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Round<S> {
        Round {
            questions: self._fields.0.unwrap(),
            title: self._fields.1,
            extra_data: Some(extra_data),
        }
    }
}