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

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

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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::types::value::Data;
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, 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::app_certified::Did;
use crate::com_atproto::repo::strong_ref::StrongRef;
use crate::org_hypercerts::SmallBlob;
use crate::org_hypercerts::Uri;
use crate::org_hypercerts::context::evaluation;
/// An evaluation of a hypercert record (e.g. an activity and its impact).

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "org.hypercerts.context.evaluation",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Evaluation<S: BosStr = DefaultStr> {
    ///Evaluation data (URIs or blobs) containing detailed reports or methodology
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<Vec<EvaluationContentItem<S>>>,
    ///Client-declared timestamp when this record was originally created
    pub created_at: Datetime,
    ///DIDs of the evaluators
    pub evaluators: Vec<Did<S>>,
    ///An optional reference for georeferenced evaluations. The record referenced must conform with the lexicon app.certified.location.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub location: Option<StrongRef<S>>,
    ///Optional references to the measurements that contributed to this evaluation. The record(s) referenced must conform with the lexicon org.hypercerts.context.measurement
    #[serde(skip_serializing_if = "Option::is_none")]
    pub measurements: Option<Vec<StrongRef<S>>>,
    ///Optional overall score for this evaluation on a numeric scale.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub score: Option<evaluation::Score<S>>,
    ///A strong reference to what is being evaluated (e.g. activity, measurement, contribution, etc.)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject: Option<StrongRef<S>>,
    ///Brief evaluation summary
    pub summary: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[open_union]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(tag = "$type", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub enum EvaluationContentItem<S: BosStr = DefaultStr> {
    #[serde(rename = "org.hypercerts.defs#uri")]
    Uri(Box<Uri<S>>),
    #[serde(rename = "org.hypercerts.defs#smallBlob")]
    SmallBlob(Box<SmallBlob<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 EvaluationGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Evaluation<S>,
}

/// Overall score for an evaluation on a numeric scale.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Score<S: BosStr = DefaultStr> {
    ///Maximum value of the scale, e.g. 5 or 10.
    pub max: i64,
    ///Minimum value of the scale, e.g. 0 or 1.
    pub min: i64,
    ///Score within the inclusive range [min, max].
    pub value: i64,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

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

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

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

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

impl<S: BosStr> Collection for Evaluation<S> {
    const NSID: &'static str = "org.hypercerts.context.evaluation";
    type Record = EvaluationRecord;
}

impl Collection for EvaluationRecord {
    const NSID: &'static str = "org.hypercerts.context.evaluation";
    type Record = EvaluationRecord;
}

impl<S: BosStr> LexiconSchema for Evaluation<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.context.evaluation"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_context_evaluation()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.content {
            #[allow(unused_comparisons)]
            if value.len() > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("content"),
                    max: 100usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.evaluators;
            #[allow(unused_comparisons)]
            if value.len() > 1000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("evaluators"),
                    max: 1000usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.measurements {
            #[allow(unused_comparisons)]
            if value.len() > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("measurements"),
                    max: 100usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.summary;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 5000usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("summary"),
                    max: 5000usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.summary;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1000usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("summary"),
                        max: 1000usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Score<S> {
    fn nsid() -> &'static str {
        "org.hypercerts.context.evaluation"
    }
    fn def_name() -> &'static str {
        "score"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_org_hypercerts_context_evaluation()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod evaluation_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 CreatedAt;
        type Evaluators;
        type Summary;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Evaluators = Unset;
        type Summary = Unset;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedAt<St> {}
    impl<St: State> State for SetCreatedAt<St> {
        type CreatedAt = Set<members::created_at>;
        type Evaluators = St::Evaluators;
        type Summary = St::Summary;
    }
    ///State transition - sets the `evaluators` field to Set
    pub struct SetEvaluators<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEvaluators<St> {}
    impl<St: State> State for SetEvaluators<St> {
        type CreatedAt = St::CreatedAt;
        type Evaluators = Set<members::evaluators>;
        type Summary = St::Summary;
    }
    ///State transition - sets the `summary` field to Set
    pub struct SetSummary<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetSummary<St> {}
    impl<St: State> State for SetSummary<St> {
        type CreatedAt = St::CreatedAt;
        type Evaluators = St::Evaluators;
        type Summary = Set<members::summary>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `evaluators` field
        pub struct evaluators(());
        ///Marker type for the `summary` field
        pub struct summary(());
    }
}

/// Builder for constructing an instance of this type.
pub struct EvaluationBuilder<St: evaluation_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Vec<EvaluationContentItem<S>>>,
        Option<Datetime>,
        Option<Vec<Did<S>>>,
        Option<StrongRef<S>>,
        Option<Vec<StrongRef<S>>>,
        Option<evaluation::Score<S>>,
        Option<StrongRef<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Evaluation<S> {
    /// Create a new builder for this type
    pub fn builder() -> EvaluationBuilder<evaluation_state::Empty, S> {
        EvaluationBuilder::builder()
    }
}

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

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

impl<St: evaluation_state::State, S: BosStr> EvaluationBuilder<St, S> {
    /// Set the `content` field (optional)
    pub fn content(
        mut self,
        value: impl Into<Option<Vec<EvaluationContentItem<S>>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `content` field to an Option value (optional)
    pub fn maybe_content(
        mut self,
        value: Option<Vec<EvaluationContentItem<S>>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> EvaluationBuilder<St, S>
where
    St: evaluation_state::State,
    St::CreatedAt: evaluation_state::IsUnset,
{
    /// Set the `createdAt` field (required)
    pub fn created_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> EvaluationBuilder<evaluation_state::SetCreatedAt<St>, S> {
        self._fields.1 = Option::Some(value.into());
        EvaluationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EvaluationBuilder<St, S>
where
    St: evaluation_state::State,
    St::Evaluators: evaluation_state::IsUnset,
{
    /// Set the `evaluators` field (required)
    pub fn evaluators(
        mut self,
        value: impl Into<Vec<Did<S>>>,
    ) -> EvaluationBuilder<evaluation_state::SetEvaluators<St>, S> {
        self._fields.2 = Option::Some(value.into());
        EvaluationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: evaluation_state::State, S: BosStr> EvaluationBuilder<St, S> {
    /// Set the `location` field (optional)
    pub fn location(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `location` field to an Option value (optional)
    pub fn maybe_location(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

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

impl<St: evaluation_state::State, S: BosStr> EvaluationBuilder<St, S> {
    /// Set the `score` field (optional)
    pub fn score(mut self, value: impl Into<Option<evaluation::Score<S>>>) -> Self {
        self._fields.5 = value.into();
        self
    }
    /// Set the `score` field to an Option value (optional)
    pub fn maybe_score(mut self, value: Option<evaluation::Score<S>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<St: evaluation_state::State, S: BosStr> EvaluationBuilder<St, S> {
    /// Set the `subject` field (optional)
    pub fn subject(mut self, value: impl Into<Option<StrongRef<S>>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `subject` field to an Option value (optional)
    pub fn maybe_subject(mut self, value: Option<StrongRef<S>>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> EvaluationBuilder<St, S>
where
    St: evaluation_state::State,
    St::Summary: evaluation_state::IsUnset,
{
    /// Set the `summary` field (required)
    pub fn summary(
        mut self,
        value: impl Into<S>,
    ) -> EvaluationBuilder<evaluation_state::SetSummary<St>, S> {
        self._fields.7 = Option::Some(value.into());
        EvaluationBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EvaluationBuilder<St, S>
where
    St: evaluation_state::State,
    St::CreatedAt: evaluation_state::IsSet,
    St::Evaluators: evaluation_state::IsSet,
    St::Summary: evaluation_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Evaluation<S> {
        Evaluation {
            content: self._fields.0,
            created_at: self._fields.1.unwrap(),
            evaluators: self._fields.2.unwrap(),
            location: self._fields.3,
            measurements: self._fields.4,
            score: self._fields.5,
            subject: self._fields.6,
            summary: 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>>,
    ) -> Evaluation<S> {
        Evaluation {
            content: self._fields.0,
            created_at: self._fields.1.unwrap(),
            evaluators: self._fields.2.unwrap(),
            location: self._fields.3,
            measurements: self._fields.4,
            score: self._fields.5,
            subject: self._fields.6,
            summary: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_org_hypercerts_context_evaluation() -> 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("org.hypercerts.context.evaluation"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "An evaluation of a hypercert record (e.g. an activity and its impact).",
                        ),
                    ),
                    key: Some(CowStr::new_static("tid")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("evaluators"),
                                SmolStr::new_static("summary"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("content"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Evaluation data (URIs or blobs) containing detailed reports or methodology",
                                        ),
                                    ),
                                    items: LexArrayItem::Union(LexRefUnion {
                                        refs: vec![
                                            CowStr::new_static("org.hypercerts.defs#uri"),
                                            CowStr::new_static("org.hypercerts.defs#smallBlob")
                                        ],
                                        ..Default::default()
                                    }),
                                    max_length: Some(100usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Client-declared timestamp when this record was originally created",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("evaluators"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static("DIDs of the evaluators"),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("app.certified.defs#did"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("location"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("measurements"),
                                LexObjectProperty::Array(LexArray {
                                    description: Some(
                                        CowStr::new_static(
                                            "Optional references to the measurements that contributed to this evaluation. The record(s) referenced must conform with the lexicon org.hypercerts.context.measurement",
                                        ),
                                    ),
                                    items: LexArrayItem::Ref(LexRef {
                                        r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                        ..Default::default()
                                    }),
                                    max_length: Some(100usize),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("score"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#score"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("subject"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("com.atproto.repo.strongRef"),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("summary"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static("Brief evaluation summary"),
                                    ),
                                    max_length: Some(5000usize),
                                    max_graphemes: Some(1000usize),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("score"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Overall score for an evaluation on a numeric scale.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("min"), SmolStr::new_static("max"),
                            SmolStr::new_static("value")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("max"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("min"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod score_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 Max;
        type Min;
        type Value;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Max = Unset;
        type Min = Unset;
        type Value = Unset;
    }
    ///State transition - sets the `max` field to Set
    pub struct SetMax<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMax<St> {}
    impl<St: State> State for SetMax<St> {
        type Max = Set<members::max>;
        type Min = St::Min;
        type Value = St::Value;
    }
    ///State transition - sets the `min` field to Set
    pub struct SetMin<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetMin<St> {}
    impl<St: State> State for SetMin<St> {
        type Max = St::Max;
        type Min = Set<members::min>;
        type Value = St::Value;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetValue<St> {}
    impl<St: State> State for SetValue<St> {
        type Max = St::Max;
        type Min = St::Min;
        type Value = Set<members::value>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `max` field
        pub struct max(());
        ///Marker type for the `min` field
        pub struct min(());
        ///Marker type for the `value` field
        pub struct value(());
    }
}

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

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

impl<S: BosStr> Score<S> {
    /// Create a new builder for this type
    pub fn builder() -> ScoreBuilder<score_state::Empty, S> {
        ScoreBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> ScoreBuilder<St, S>
where
    St: score_state::State,
    St::Max: score_state::IsUnset,
{
    /// Set the `max` field (required)
    pub fn max(
        mut self,
        value: impl Into<i64>,
    ) -> ScoreBuilder<score_state::SetMax<St>, S> {
        self._fields.0 = Option::Some(value.into());
        ScoreBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> ScoreBuilder<St, S>
where
    St: score_state::State,
    St::Value: score_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<i64>,
    ) -> ScoreBuilder<score_state::SetValue<St>, S> {
        self._fields.2 = Option::Some(value.into());
        ScoreBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ScoreBuilder<St, S>
where
    St: score_state::State,
    St::Max: score_state::IsSet,
    St::Min: score_state::IsSet,
    St::Value: score_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Score<S> {
        Score {
            max: self._fields.0.unwrap(),
            min: self._fields.1.unwrap(),
            value: 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>>) -> Score<S> {
        Score {
            max: self._fields.0.unwrap(),
            min: self._fields.1.unwrap(),
            value: self._fields.2.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}