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

//! Generated bindings for the `tools.ozone.setting` Lexicon namespace/module.
pub mod list_options;
pub mod remove_options;
pub mod upsert_option;


#[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::string::{Did, Nsid, Datetime};
use jacquard_common::types::value::Data;
use jacquard_derive::IntoStatic;
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

#[allow(unused_imports)]
use jacquard_lexicon::validation::{ConstraintError, ValidationPath};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct DefsOption<S: BosStr = DefaultStr> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    pub created_by: Did<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    pub did: Did<S>,
    pub key: Nsid<S>,
    pub last_updated_by: Did<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub manager_role: Option<DefsOptionManagerRole<S>>,
    pub scope: DefsOptionScope<S>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    pub value: Data<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DefsOptionManagerRole<S: BosStr = DefaultStr> {
    RoleModerator,
    RoleTriage,
    RoleAdmin,
    RoleVerifier,
    Other(S),
}

impl<S: BosStr> DefsOptionManagerRole<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::RoleModerator => "tools.ozone.team.defs#roleModerator",
            Self::RoleTriage => "tools.ozone.team.defs#roleTriage",
            Self::RoleAdmin => "tools.ozone.team.defs#roleAdmin",
            Self::RoleVerifier => "tools.ozone.team.defs#roleVerifier",
            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() {
            "tools.ozone.team.defs#roleModerator" => Self::RoleModerator,
            "tools.ozone.team.defs#roleTriage" => Self::RoleTriage,
            "tools.ozone.team.defs#roleAdmin" => Self::RoleAdmin,
            "tools.ozone.team.defs#roleVerifier" => Self::RoleVerifier,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for DefsOptionManagerRole<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 DefsOptionManagerRole<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 DefsOptionManagerRole<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

impl<S: BosStr> jacquard_common::IntoStatic for DefsOptionManagerRole<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = DefsOptionManagerRole<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            DefsOptionManagerRole::RoleModerator => DefsOptionManagerRole::RoleModerator,
            DefsOptionManagerRole::RoleTriage => DefsOptionManagerRole::RoleTriage,
            DefsOptionManagerRole::RoleAdmin => DefsOptionManagerRole::RoleAdmin,
            DefsOptionManagerRole::RoleVerifier => DefsOptionManagerRole::RoleVerifier,
            DefsOptionManagerRole::Other(v) => {
                DefsOptionManagerRole::Other(v.into_static())
            }
        }
    }
}


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

impl<S: BosStr> DefsOptionScope<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Instance => "instance",
            Self::Personal => "personal",
            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() {
            "instance" => Self::Instance,
            "personal" => Self::Personal,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for DefsOptionScope<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 DefsOptionScope<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 DefsOptionScope<S> {
    fn default() -> Self {
        Self::Other(Default::default())
    }
}

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

impl<S: BosStr> LexiconSchema for DefsOption<S> {
    fn nsid() -> &'static str {
        "tools.ozone.setting.defs"
    }
    fn def_name() -> &'static str {
        "option"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_setting_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 10240usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 10240usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.description {
            {
                let count = UnicodeSegmentation::graphemes(value.as_ref(), true).count();
                if count > 1024usize {
                    return Err(ConstraintError::MaxGraphemes {
                        path: ValidationPath::from_field("description"),
                        max: 1024usize,
                        actual: count,
                    });
                }
            }
        }
        Ok(())
    }
}

pub mod defs_option_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 CreatedBy;
        type Did;
        type Key;
        type LastUpdatedBy;
        type Scope;
        type Value;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type CreatedBy = Unset;
        type Did = Unset;
        type Key = Unset;
        type LastUpdatedBy = Unset;
        type Scope = Unset;
        type Value = Unset;
    }
    ///State transition - sets the `created_by` field to Set
    pub struct SetCreatedBy<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetCreatedBy<St> {}
    impl<St: State> State for SetCreatedBy<St> {
        type CreatedBy = Set<members::created_by>;
        type Did = St::Did;
        type Key = St::Key;
        type LastUpdatedBy = St::LastUpdatedBy;
        type Scope = St::Scope;
        type Value = St::Value;
    }
    ///State transition - sets the `did` field to Set
    pub struct SetDid<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetDid<St> {}
    impl<St: State> State for SetDid<St> {
        type CreatedBy = St::CreatedBy;
        type Did = Set<members::did>;
        type Key = St::Key;
        type LastUpdatedBy = St::LastUpdatedBy;
        type Scope = St::Scope;
        type Value = St::Value;
    }
    ///State transition - sets the `key` field to Set
    pub struct SetKey<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetKey<St> {}
    impl<St: State> State for SetKey<St> {
        type CreatedBy = St::CreatedBy;
        type Did = St::Did;
        type Key = Set<members::key>;
        type LastUpdatedBy = St::LastUpdatedBy;
        type Scope = St::Scope;
        type Value = St::Value;
    }
    ///State transition - sets the `last_updated_by` field to Set
    pub struct SetLastUpdatedBy<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetLastUpdatedBy<St> {}
    impl<St: State> State for SetLastUpdatedBy<St> {
        type CreatedBy = St::CreatedBy;
        type Did = St::Did;
        type Key = St::Key;
        type LastUpdatedBy = Set<members::last_updated_by>;
        type Scope = St::Scope;
        type Value = St::Value;
    }
    ///State transition - sets the `scope` field to Set
    pub struct SetScope<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetScope<St> {}
    impl<St: State> State for SetScope<St> {
        type CreatedBy = St::CreatedBy;
        type Did = St::Did;
        type Key = St::Key;
        type LastUpdatedBy = St::LastUpdatedBy;
        type Scope = Set<members::scope>;
        type Value = St::Value;
    }
    ///State transition - sets the `value` field to Set
    pub struct SetValue<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetValue<St> {}
    impl<St: State> State for SetValue<St> {
        type CreatedBy = St::CreatedBy;
        type Did = St::Did;
        type Key = St::Key;
        type LastUpdatedBy = St::LastUpdatedBy;
        type Scope = St::Scope;
        type Value = Set<members::value>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `created_by` field
        pub struct created_by(());
        ///Marker type for the `did` field
        pub struct did(());
        ///Marker type for the `key` field
        pub struct key(());
        ///Marker type for the `last_updated_by` field
        pub struct last_updated_by(());
        ///Marker type for the `scope` field
        pub struct scope(());
        ///Marker type for the `value` field
        pub struct value(());
    }
}

/// Builder for constructing an instance of this type.
pub struct DefsOptionBuilder<St: defs_option_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<Datetime>,
        Option<Did<S>>,
        Option<S>,
        Option<Did<S>>,
        Option<Nsid<S>>,
        Option<Did<S>>,
        Option<DefsOptionManagerRole<S>>,
        Option<DefsOptionScope<S>>,
        Option<Datetime>,
        Option<Data<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> DefsOption<S> {
    /// Create a new builder for this type
    pub fn builder() -> DefsOptionBuilder<defs_option_state::Empty, S> {
        DefsOptionBuilder::builder()
    }
}

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

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

impl<St: defs_option_state::State, S: BosStr> DefsOptionBuilder<St, S> {
    /// Set the `createdAt` field (optional)
    pub fn created_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `createdAt` field to an Option value (optional)
    pub fn maybe_created_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<St, S: BosStr> DefsOptionBuilder<St, S>
where
    St: defs_option_state::State,
    St::CreatedBy: defs_option_state::IsUnset,
{
    /// Set the `createdBy` field (required)
    pub fn created_by(
        mut self,
        value: impl Into<Did<S>>,
    ) -> DefsOptionBuilder<defs_option_state::SetCreatedBy<St>, S> {
        self._fields.1 = Option::Some(value.into());
        DefsOptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> DefsOptionBuilder<St, S>
where
    St: defs_option_state::State,
    St::Did: defs_option_state::IsUnset,
{
    /// Set the `did` field (required)
    pub fn did(
        mut self,
        value: impl Into<Did<S>>,
    ) -> DefsOptionBuilder<defs_option_state::SetDid<St>, S> {
        self._fields.3 = Option::Some(value.into());
        DefsOptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DefsOptionBuilder<St, S>
where
    St: defs_option_state::State,
    St::Key: defs_option_state::IsUnset,
{
    /// Set the `key` field (required)
    pub fn key(
        mut self,
        value: impl Into<Nsid<S>>,
    ) -> DefsOptionBuilder<defs_option_state::SetKey<St>, S> {
        self._fields.4 = Option::Some(value.into());
        DefsOptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> DefsOptionBuilder<St, S>
where
    St: defs_option_state::State,
    St::LastUpdatedBy: defs_option_state::IsUnset,
{
    /// Set the `lastUpdatedBy` field (required)
    pub fn last_updated_by(
        mut self,
        value: impl Into<Did<S>>,
    ) -> DefsOptionBuilder<defs_option_state::SetLastUpdatedBy<St>, S> {
        self._fields.5 = Option::Some(value.into());
        DefsOptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: defs_option_state::State, S: BosStr> DefsOptionBuilder<St, S> {
    /// Set the `managerRole` field (optional)
    pub fn manager_role(
        mut self,
        value: impl Into<Option<DefsOptionManagerRole<S>>>,
    ) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `managerRole` field to an Option value (optional)
    pub fn maybe_manager_role(
        mut self,
        value: Option<DefsOptionManagerRole<S>>,
    ) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St, S: BosStr> DefsOptionBuilder<St, S>
where
    St: defs_option_state::State,
    St::Scope: defs_option_state::IsUnset,
{
    /// Set the `scope` field (required)
    pub fn scope(
        mut self,
        value: impl Into<DefsOptionScope<S>>,
    ) -> DefsOptionBuilder<defs_option_state::SetScope<St>, S> {
        self._fields.7 = Option::Some(value.into());
        DefsOptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: defs_option_state::State, S: BosStr> DefsOptionBuilder<St, S> {
    /// Set the `updatedAt` field (optional)
    pub fn updated_at(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `updatedAt` field to an Option value (optional)
    pub fn maybe_updated_at(mut self, value: Option<Datetime>) -> Self {
        self._fields.8 = value;
        self
    }
}

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

impl<St, S: BosStr> DefsOptionBuilder<St, S>
where
    St: defs_option_state::State,
    St::CreatedBy: defs_option_state::IsSet,
    St::Did: defs_option_state::IsSet,
    St::Key: defs_option_state::IsSet,
    St::LastUpdatedBy: defs_option_state::IsSet,
    St::Scope: defs_option_state::IsSet,
    St::Value: defs_option_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> DefsOption<S> {
        DefsOption {
            created_at: self._fields.0,
            created_by: self._fields.1.unwrap(),
            description: self._fields.2,
            did: self._fields.3.unwrap(),
            key: self._fields.4.unwrap(),
            last_updated_by: self._fields.5.unwrap(),
            manager_role: self._fields.6,
            scope: self._fields.7.unwrap(),
            updated_at: self._fields.8,
            value: self._fields.9.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>>,
    ) -> DefsOption<S> {
        DefsOption {
            created_at: self._fields.0,
            created_by: self._fields.1.unwrap(),
            description: self._fields.2,
            did: self._fields.3.unwrap(),
            key: self._fields.4.unwrap(),
            last_updated_by: self._fields.5.unwrap(),
            manager_role: self._fields.6,
            scope: self._fields.7.unwrap(),
            updated_at: self._fields.8,
            value: self._fields.9.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_tools_ozone_setting_defs() -> 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("tools.ozone.setting.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("option"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![
                            SmolStr::new_static("key"), SmolStr::new_static("value"),
                            SmolStr::new_static("did"), SmolStr::new_static("scope"),
                            SmolStr::new_static("createdBy"),
                            SmolStr::new_static("lastUpdatedBy")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdBy"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString {
                                max_length: Some(10240usize),
                                max_graphemes: Some(1024usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("did"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("key"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Nsid),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("lastUpdatedBy"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("managerRole"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("scope"),
                            LexObjectProperty::String(LexString { ..Default::default() }),
                        );
                        map.insert(
                            SmolStr::new_static("updatedAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("value"),
                            LexObjectProperty::Unknown(LexUnknown {
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}