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

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::collection::{Collection, RecordError};
use jacquard_common::types::string::{AtUri, Cid, Datetime};
use jacquard_common::types::uri::{RecordUri, UriError};
use jacquard_common::xrpc::XrpcResp;
use jacquard_derive::{IntoStatic, lexicon, 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).

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Evaluation<'a> {
    ///Evaluation data (URIs or blobs) containing detailed reports or methodology
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub content: Option<Vec<EvaluationContentItem<'a>>>,
    ///Client-declared timestamp when this record was originally created
    pub created_at: Datetime,
    ///DIDs of the evaluators
    #[serde(borrow)]
    pub evaluators: Vec<Did<'a>>,
    ///An optional reference for georeferenced evaluations. The record referenced must conform with the lexicon app.certified.location.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub location: Option<StrongRef<'a>>,
    ///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")]
    #[serde(borrow)]
    pub measurements: Option<Vec<StrongRef<'a>>>,
    ///Optional overall score for this evaluation on a numeric scale.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub score: Option<evaluation::Score<'a>>,
    ///A strong reference to what is being evaluated (e.g. activity, measurement, contribution, etc.)
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub subject: Option<StrongRef<'a>>,
    ///Brief evaluation summary
    #[serde(borrow)]
    pub summary: CowStr<'a>,
}


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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Score<'a> {
    ///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,
}

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

/// 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<'de> = EvaluationGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

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

/// Builder for constructing an instance of this type
pub struct EvaluationBuilder<'a, S: evaluation_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Vec<EvaluationContentItem<'a>>>,
        Option<Datetime>,
        Option<Vec<Did<'a>>>,
        Option<StrongRef<'a>>,
        Option<Vec<StrongRef<'a>>>,
        Option<evaluation::Score<'a>>,
        Option<StrongRef<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
    /// Set the `content` field (optional)
    pub fn content(
        mut self,
        value: impl Into<Option<Vec<EvaluationContentItem<'a>>>>,
    ) -> 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<'a>>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

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

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

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

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

impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
    /// Set the `score` field (optional)
    pub fn score(mut self, value: impl Into<Option<evaluation::Score<'a>>>) -> 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<'a>>) -> Self {
        self._fields.5 = value;
        self
    }
}

impl<'a, S: evaluation_state::State> EvaluationBuilder<'a, S> {
    /// Set the `subject` field (optional)
    pub fn subject(mut self, value: impl Into<Option<StrongRef<'a>>>) -> 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<'a>>) -> Self {
        self._fields.6 = value;
        self
    }
}

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

impl<'a, S> EvaluationBuilder<'a, S>
where
    S: evaluation_state::State,
    S::Evaluators: evaluation_state::IsSet,
    S::Summary: evaluation_state::IsSet,
    S::CreatedAt: evaluation_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Evaluation<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Evaluation<'a> {
        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 Min;
        type Value;
        type Max;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Min = Unset;
        type Value = Unset;
        type Max = Unset;
    }
    ///State transition - sets the `min` field to Set
    pub struct SetMin<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMin<S> {}
    impl<S: State> State for SetMin<S> {
        type Min = Set<members::min>;
        type Value = S::Value;
        type Max = S::Max;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetValue<S> {}
    impl<S: State> State for SetValue<S> {
        type Min = S::Min;
        type Value = Set<members::value>;
        type Max = S::Max;
    }
    ///State transition - sets the `max` field to Set
    pub struct SetMax<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetMax<S> {}
    impl<S: State> State for SetMax<S> {
        type Min = S::Min;
        type Value = S::Value;
        type Max = Set<members::max>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `min` field
        pub struct min(());
        ///Marker type for the `value` field
        pub struct value(());
        ///Marker type for the `max` field
        pub struct max(());
    }
}

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

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

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

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

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

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

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