// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: app.gainforest.evaluator.service
//
// 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};
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_gainforest::evaluator::MethodInfo;
use crate::app_gainforest::evaluator::service;
/// Definition of a single evaluation type produced by this evaluator.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct EvaluationTypeDefinition<S: BosStr = DefaultStr> {
    ///The evaluation type identifier (must match an entry in evaluationTypes).
    pub identifier: S,
    ///Human-readable names and descriptions in various languages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub locales: Option<Vec<service::EvaluationTypeLocale<S>>>,
    ///Default method info for this evaluation type (can be overridden per-evaluation).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub method: Option<MethodInfo<S>>,
    ///The lexicon reference for the result type (e.g., 'app.gainforest.evaluator.defs#speciesIdResult').
    pub result_type: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Localized name and description for an evaluation type.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct EvaluationTypeLocale<S: BosStr = DefaultStr> {
    ///Longer description of what this evaluation type does.
    pub description: S,
    ///Language code (BCP-47, e.g., 'en', 'pt-BR').
    pub lang: S,
    ///Short human-readable name for this evaluation type.
    pub name: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Policies declaring what this evaluator does and how it operates.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct EvaluatorPolicies<S: BosStr = DefaultStr> {
    ///Whether this evaluator requires user subscription ('subscription') or processes all matching records ('open').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub access_model: Option<EvaluatorPoliciesAccessModel<S>>,
    ///Detailed definitions for each evaluation type, including human-readable descriptions.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evaluation_type_definitions: Option<Vec<service::EvaluationTypeDefinition<S>>>,
    ///List of evaluation type identifiers this evaluator produces (e.g., 'species-id', 'data-quality').
    pub evaluation_types: Vec<S>,
    ///NSIDs of record collections this evaluator can evaluate (e.g., 'app.gainforest.dwc.occurrence').
    #[serde(skip_serializing_if = "Option::is_none")]
    pub subject_collections: Option<Vec<S>>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// Whether this evaluator requires user subscription ('subscription') or processes all matching records ('open').

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EvaluatorPoliciesAccessModel<S: BosStr = DefaultStr> {
    Open,
    Subscription,
    Other(S),
}

impl<S: BosStr> EvaluatorPoliciesAccessModel<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Open => "open",
            Self::Subscription => "subscription",
            Self::Other(s) => s.as_ref(),
        }
    }
    /// Construct from a string-like value, matching known values.
    pub fn from_value(s: S) -> Self {
        match s.as_ref() {
            "open" => Self::Open,
            "subscription" => Self::Subscription,
            _ => Self::Other(s),
        }
    }
}

impl<S: BosStr> core::fmt::Display for EvaluatorPoliciesAccessModel<S> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

impl<S: BosStr> AsRef<str> for EvaluatorPoliciesAccessModel<S> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

impl<S: BosStr> Serialize for EvaluatorPoliciesAccessModel<S> {
    fn serialize<Ser>(&self, serializer: Ser) -> Result<Ser::Ok, Ser::Error>
    where
        Ser: serde::Serializer,
    {
        serializer.serialize_str(self.as_str())
    }
}

impl<'de, S: Deserialize<'de> + BosStr> Deserialize<'de>
for EvaluatorPoliciesAccessModel<S> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = S::deserialize(deserializer)?;
        Ok(Self::from_value(s))
    }
}

impl<S: BosStr + Default> Default for EvaluatorPoliciesAccessModel<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for EvaluatorPoliciesAccessModel<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = EvaluatorPoliciesAccessModel<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            EvaluatorPoliciesAccessModel::Open => EvaluatorPoliciesAccessModel::Open,
            EvaluatorPoliciesAccessModel::Subscription => {
                EvaluatorPoliciesAccessModel::Subscription
            }
            EvaluatorPoliciesAccessModel::Other(v) => {
                EvaluatorPoliciesAccessModel::Other(v.into_static())
            }
        }
    }
}

/// An evaluator service declaration. Publish at /app.gainforest.evaluator.service/self to declare this account as an evaluator.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    rename = "app.gainforest.evaluator.service",
    tag = "$type",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Service<S: BosStr = DefaultStr> {
    ///Timestamp of when this evaluator service was declared.
    pub created_at: Datetime,
    ///The evaluator's policies including supported evaluation types and access model.
    pub policies: service::EvaluatorPolicies<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 ServiceGetRecordOutput<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cid: Option<Cid<S>>,
    pub uri: AtUri<S>,
    pub value: Service<S>,
}

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

impl<S: BosStr> LexiconSchema for EvaluationTypeDefinition<S> {
    fn nsid() -> &'static str {
        "app.gainforest.evaluator.service"
    }
    fn def_name() -> &'static str {
        "evaluationTypeDefinition"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_gainforest_evaluator_service()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.identifier;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("identifier"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.locales {
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("locales"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.result_type;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 128usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("result_type"),
                        max: 128usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for EvaluationTypeLocale<S> {
    fn nsid() -> &'static str {
        "app.gainforest.evaluator.service"
    }
    fn def_name() -> &'static str {
        "evaluationTypeLocale"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_gainforest_evaluator_service()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.description;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 2048usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("description"),
                        max: 2048usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.lang;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 16usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("lang"),
                        max: 16usize,
                        actual: count,
                    });
                }
            }
        }
        {
            let value = &self.name;
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 128usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("name"),
                        max: 128usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for EvaluatorPolicies<S> {
    fn nsid() -> &'static str {
        "app.gainforest.evaluator.service"
    }
    fn def_name() -> &'static str {
        "evaluatorPolicies"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_gainforest_evaluator_service()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.access_model {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 64usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("access_model"),
                        max: 64usize,
                        actual: count,
                    });
                }
            }
        }
        if let Some(ref value) = self.evaluation_type_definitions {
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("evaluation_type_definitions"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        {
            let value = &self.evaluation_types;
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("evaluation_types"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        if let Some(ref value) = self.subject_collections {
            #[allow(unused_comparisons)]
            if value.len() > 20usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("subject_collections"),
                    max: 20usize,
                    actual: value.len(),
                });
            }
        }
        Ok(())
    }
}

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

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

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

impl<S: BosStr> Collection for Service<S> {
    const NSID: &'static str = "app.gainforest.evaluator.service";
    type Record = ServiceRecord;
}

impl Collection for ServiceRecord {
    const NSID: &'static str = "app.gainforest.evaluator.service";
    type Record = ServiceRecord;
}

impl<S: BosStr> LexiconSchema for Service<S> {
    fn nsid() -> &'static str {
        "app.gainforest.evaluator.service"
    }
    fn def_name() -> &'static str {
        "main"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_app_gainforest_evaluator_service()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

fn lexicon_doc_app_gainforest_evaluator_service() -> 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("app.gainforest.evaluator.service"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("evaluationTypeDefinition"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Definition of a single evaluation type produced by this evaluator.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("identifier"),
                            SmolStr::new_static("resultType")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("identifier"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The evaluation type identifier (must match an entry in evaluationTypes).",
                                    ),
                                ),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("locales"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Human-readable names and descriptions in various languages.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#evaluationTypeLocale"),
                                    ..Default::default()
                                }),
                                max_length: Some(20usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("method"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static(
                                    "app.gainforest.evaluator.defs#methodInfo",
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("resultType"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The lexicon reference for the result type (e.g., 'app.gainforest.evaluator.defs#speciesIdResult').",
                                    ),
                                ),
                                max_graphemes: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("evaluationTypeLocale"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Localized name and description for an evaluation type.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("lang"), SmolStr::new_static("name"),
                            SmolStr::new_static("description")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Longer description of what this evaluation type does.",
                                    ),
                                ),
                                max_graphemes: Some(2048usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("lang"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Language code (BCP-47, e.g., 'en', 'pt-BR').",
                                    ),
                                ),
                                max_graphemes: Some(16usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Short human-readable name for this evaluation type.",
                                    ),
                                ),
                                max_graphemes: Some(128usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("evaluatorPolicies"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "Policies declaring what this evaluator does and how it operates.",
                        ),
                    ),
                    required: Some(vec![SmolStr::new_static("evaluationTypes")]),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("accessModel"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Whether this evaluator requires user subscription ('subscription') or processes all matching records ('open').",
                                    ),
                                ),
                                max_graphemes: Some(64usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("evaluationTypeDefinitions"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Detailed definitions for each evaluation type, including human-readable descriptions.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#evaluationTypeDefinition"),
                                    ..Default::default()
                                }),
                                max_length: Some(20usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("evaluationTypes"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "List of evaluation type identifiers this evaluator produces (e.g., 'species-id', 'data-quality').",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    max_graphemes: Some(64usize),
                                    ..Default::default()
                                }),
                                max_length: Some(20usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("subjectCollections"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "NSIDs of record collections this evaluator can evaluate (e.g., 'app.gainforest.dwc.occurrence').",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    max_graphemes: Some(128usize),
                                    ..Default::default()
                                }),
                                max_length: Some(20usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("main"),
                LexUserType::Record(LexRecord {
                    description: Some(
                        CowStr::new_static(
                            "An evaluator service declaration. Publish at /app.gainforest.evaluator.service/self to declare this account as an evaluator.",
                        ),
                    ),
                    key: Some(CowStr::new_static("literal:self")),
                    record: LexRecordRecord::Object(LexObject {
                        required: Some(
                            vec![
                                SmolStr::new_static("policies"),
                                SmolStr::new_static("createdAt")
                            ],
                        ),
                        properties: {
                            #[allow(unused_mut)]
                            let mut map = BTreeMap::new();
                            map.insert(
                                SmolStr::new_static("createdAt"),
                                LexObjectProperty::String(LexString {
                                    description: Some(
                                        CowStr::new_static(
                                            "Timestamp of when this evaluator service was declared.",
                                        ),
                                    ),
                                    format: Some(LexStringFormat::Datetime),
                                    ..Default::default()
                                }),
                            );
                            map.insert(
                                SmolStr::new_static("policies"),
                                LexObjectProperty::Ref(LexRef {
                                    r#ref: CowStr::new_static("#evaluatorPolicies"),
                                    ..Default::default()
                                }),
                            );
                            map
                        },
                        ..Default::default()
                    }),
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

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

/// Builder for constructing an instance of this type.
pub struct EvaluatorPoliciesBuilder<
    St: evaluator_policies_state::State,
    S: BosStr = DefaultStr,
> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<EvaluatorPoliciesAccessModel<S>>,
        Option<Vec<service::EvaluationTypeDefinition<S>>>,
        Option<Vec<S>>,
        Option<Vec<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> EvaluatorPolicies<S> {
    /// Create a new builder for this type
    pub fn builder() -> EvaluatorPoliciesBuilder<evaluator_policies_state::Empty, S> {
        EvaluatorPoliciesBuilder::builder()
    }
}

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

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

impl<St: evaluator_policies_state::State, S: BosStr> EvaluatorPoliciesBuilder<St, S> {
    /// Set the `accessModel` field (optional)
    pub fn access_model(
        mut self,
        value: impl Into<Option<EvaluatorPoliciesAccessModel<S>>>,
    ) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `accessModel` field to an Option value (optional)
    pub fn maybe_access_model(
        mut self,
        value: Option<EvaluatorPoliciesAccessModel<S>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St: evaluator_policies_state::State, S: BosStr> EvaluatorPoliciesBuilder<St, S> {
    /// Set the `evaluationTypeDefinitions` field (optional)
    pub fn evaluation_type_definitions(
        mut self,
        value: impl Into<Option<Vec<service::EvaluationTypeDefinition<S>>>>,
    ) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `evaluationTypeDefinitions` field to an Option value (optional)
    pub fn maybe_evaluation_type_definitions(
        mut self,
        value: Option<Vec<service::EvaluationTypeDefinition<S>>>,
    ) -> Self {
        self._fields.1 = value;
        self
    }
}

impl<St, S: BosStr> EvaluatorPoliciesBuilder<St, S>
where
    St: evaluator_policies_state::State,
    St::EvaluationTypes: evaluator_policies_state::IsUnset,
{
    /// Set the `evaluationTypes` field (required)
    pub fn evaluation_types(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> EvaluatorPoliciesBuilder<evaluator_policies_state::SetEvaluationTypes<St>, S> {
        self._fields.2 = Option::Some(value.into());
        EvaluatorPoliciesBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: evaluator_policies_state::State, S: BosStr> EvaluatorPoliciesBuilder<St, S> {
    /// Set the `subjectCollections` field (optional)
    pub fn subject_collections(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `subjectCollections` field to an Option value (optional)
    pub fn maybe_subject_collections(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> EvaluatorPoliciesBuilder<St, S>
where
    St: evaluator_policies_state::State,
    St::EvaluationTypes: evaluator_policies_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> EvaluatorPolicies<S> {
        EvaluatorPolicies {
            access_model: self._fields.0,
            evaluation_type_definitions: self._fields.1,
            evaluation_types: self._fields.2.unwrap(),
            subject_collections: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(
        self,
        extra_data: BTreeMap<SmolStr, Data<S>>,
    ) -> EvaluatorPolicies<S> {
        EvaluatorPolicies {
            access_model: self._fields.0,
            evaluation_type_definitions: self._fields.1,
            evaluation_types: self._fields.2.unwrap(),
            subject_collections: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}

pub mod service_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 Policies;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedAt = Unset;
        type Policies = 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 Policies = St::Policies;
    }
    ///State transition - sets the `policies` field to Set
    pub struct SetPolicies<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPolicies<St> {}
    impl<St: State> State for SetPolicies<St> {
        type CreatedAt = St::CreatedAt;
        type Policies = Set<members::policies>;
    }
    /// 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 `policies` field
        pub struct policies(());
    }
}

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

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

impl<S: BosStr> Service<S> {
    /// Create a new builder for this type
    pub fn builder() -> ServiceBuilder<service_state::Empty, S> {
        ServiceBuilder::builder()
    }
}

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

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

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

impl<St, S: BosStr> ServiceBuilder<St, S>
where
    St: service_state::State,
    St::Policies: service_state::IsUnset,
{
    /// Set the `policies` field (required)
    pub fn policies(
        mut self,
        value: impl Into<service::EvaluatorPolicies<S>>,
    ) -> ServiceBuilder<service_state::SetPolicies<St>, S> {
        self._fields.1 = Option::Some(value.into());
        ServiceBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> ServiceBuilder<St, S>
where
    St: service_state::State,
    St::CreatedAt: service_state::IsSet,
    St::Policies: service_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Service<S> {
        Service {
            created_at: self._fields.0.unwrap(),
            policies: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Service<S> {
        Service {
            created_at: self._fields.0.unwrap(),
            policies: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}