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

#[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};
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.

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

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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct EvaluationTypeLocale<'a> {
    ///Longer description of what this evaluation type does.
    #[serde(borrow)]
    pub description: CowStr<'a>,
    ///Language code (BCP-47, e.g., 'en', 'pt-BR').
    #[serde(borrow)]
    pub lang: CowStr<'a>,
    ///Short human-readable name for this evaluation type.
    #[serde(borrow)]
    pub name: CowStr<'a>,
}

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

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

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

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EvaluatorPoliciesAccessModel<'a> {
    Open,
    Subscription,
    Other(CowStr<'a>),
}

impl<'a> EvaluatorPoliciesAccessModel<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Open => "open",
            Self::Subscription => "subscription",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for EvaluatorPoliciesAccessModel<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "open" => Self::Open,
            "subscription" => Self::Subscription,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for EvaluatorPoliciesAccessModel<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "open" => Self::Open,
            "subscription" => Self::Subscription,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

impl<'a> AsRef<str> for EvaluatorPoliciesAccessModel<'a> {
    fn as_ref(&self) -> &str {
        self.as_str()
    }
}

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

impl<'de, 'a> serde::Deserialize<'de> for EvaluatorPoliciesAccessModel<'a>
where
    'de: 'a,
{
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        let s = <&'de str>::deserialize(deserializer)?;
        Ok(Self::from(s))
    }
}

impl<'a> Default for EvaluatorPoliciesAccessModel<'a> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl jacquard_common::IntoStatic for EvaluatorPoliciesAccessModel<'_> {
    type Output = EvaluatorPoliciesAccessModel<'static>;
    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.

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Service<'a> {
    ///Timestamp of when this evaluator service was declared.
    pub created_at: Datetime,
    ///The evaluator's policies including supported evaluation types and access model.
    #[serde(borrow)]
    pub policies: service::EvaluatorPolicies<'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 ServiceGetRecordOutput<'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: Service<'a>,
}

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

impl<'a> LexiconSchema for EvaluationTypeDefinition<'a> {
    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<'a> LexiconSchema for EvaluationTypeLocale<'a> {
    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<'a> LexiconSchema for EvaluatorPolicies<'a> {
    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<'de> = ServiceGetRecordOutput<'de>;
    type Err<'de> = RecordError<'de>;
}

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

impl Collection for Service<'_> {
    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<'a> LexiconSchema for Service<'a> {
    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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEvaluationTypes<S> {}
    impl<S: State> State for SetEvaluationTypes<S> {
        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<'a, S: evaluator_policies_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<EvaluatorPoliciesAccessModel<'a>>,
        Option<Vec<service::EvaluationTypeDefinition<'a>>>,
        Option<Vec<CowStr<'a>>>,
        Option<Vec<CowStr<'a>>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: evaluator_policies_state::State> EvaluatorPoliciesBuilder<'a, S> {
    /// Set the `accessModel` field (optional)
    pub fn access_model(
        mut self,
        value: impl Into<Option<EvaluatorPoliciesAccessModel<'a>>>,
    ) -> 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<'a>>,
    ) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<'a, S: evaluator_policies_state::State> EvaluatorPoliciesBuilder<'a, S> {
    /// Set the `evaluationTypeDefinitions` field (optional)
    pub fn evaluation_type_definitions(
        mut self,
        value: impl Into<Option<Vec<service::EvaluationTypeDefinition<'a>>>>,
    ) -> 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<'a>>>,
    ) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<'a, S> EvaluatorPoliciesBuilder<'a, S>
where
    S: evaluator_policies_state::State,
    S::EvaluationTypes: evaluator_policies_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> EvaluatorPolicies<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> EvaluatorPolicies<'a> {
        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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type CreatedAt = Set<members::created_at>;
        type Policies = S::Policies;
    }
    ///State transition - sets the `policies` field to Set
    pub struct SetPolicies<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPolicies<S> {}
    impl<S: State> State for SetPolicies<S> {
        type CreatedAt = S::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<'a, S: service_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<Datetime>, Option<service::EvaluatorPolicies<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

impl<'a, S> ServiceBuilder<'a, S>
where
    S: service_state::State,
    S::CreatedAt: service_state::IsSet,
    S::Policies: service_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Service<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Service<'a> {
        Service {
            created_at: self._fields.0.unwrap(),
            policies: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}