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

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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, Nsid, Datetime};
use jacquard_common::types::value::Data;
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};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct DefsOption<'a> {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub created_at: Option<Datetime>,
    #[serde(borrow)]
    pub created_by: Did<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    #[serde(borrow)]
    pub did: Did<'a>,
    #[serde(borrow)]
    pub key: Nsid<'a>,
    #[serde(borrow)]
    pub last_updated_by: Did<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub manager_role: Option<DefsOptionManagerRole<'a>>,
    #[serde(borrow)]
    pub scope: DefsOptionScope<'a>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    #[serde(borrow)]
    pub value: Data<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum DefsOptionManagerRole<'a> {
    RoleModerator,
    RoleTriage,
    RoleAdmin,
    RoleVerifier,
    Other(CowStr<'a>),
}

impl<'a> DefsOptionManagerRole<'a> {
    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(),
        }
    }
}

impl<'a> From<&'a str> for DefsOptionManagerRole<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "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(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for DefsOptionManagerRole<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "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(CowStr::from(s)),
        }
    }
}

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

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

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

impl jacquard_common::IntoStatic for DefsOptionManagerRole<'_> {
    type Output = DefsOptionManagerRole<'static>;
    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<'a> {
    Instance,
    Personal,
    Other(CowStr<'a>),
}

impl<'a> DefsOptionScope<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Instance => "instance",
            Self::Personal => "personal",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for DefsOptionScope<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "instance" => Self::Instance,
            "personal" => Self::Personal,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for DefsOptionScope<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "instance" => Self::Instance,
            "personal" => Self::Personal,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

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

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

/// Builder for constructing an instance of this type
pub struct DefsOptionBuilder<'a, S: defs_option_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<Datetime>,
        Option<Did<'a>>,
        Option<CowStr<'a>>,
        Option<Did<'a>>,
        Option<Nsid<'a>>,
        Option<Did<'a>>,
        Option<DefsOptionManagerRole<'a>>,
        Option<DefsOptionScope<'a>>,
        Option<Datetime>,
        Option<Data<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: defs_option_state::State> DefsOptionBuilder<'a, 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<'a, S> DefsOptionBuilder<'a, S>
where
    S: defs_option_state::State,
    S::CreatedBy: defs_option_state::IsUnset,
{
    /// Set the `createdBy` field (required)
    pub fn created_by(
        mut self,
        value: impl Into<Did<'a>>,
    ) -> DefsOptionBuilder<'a, defs_option_state::SetCreatedBy<S>> {
        self._fields.1 = Option::Some(value.into());
        DefsOptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

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

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

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

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

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

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

impl<'a, S: defs_option_state::State> DefsOptionBuilder<'a, 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<'a, S> DefsOptionBuilder<'a, S>
where
    S: defs_option_state::State,
    S::Value: defs_option_state::IsUnset,
{
    /// Set the `value` field (required)
    pub fn value(
        mut self,
        value: impl Into<Data<'a>>,
    ) -> DefsOptionBuilder<'a, defs_option_state::SetValue<S>> {
        self._fields.9 = Option::Some(value.into());
        DefsOptionBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S> DefsOptionBuilder<'a, S>
where
    S: defs_option_state::State,
    S::Value: defs_option_state::IsSet,
    S::LastUpdatedBy: defs_option_state::IsSet,
    S::Did: defs_option_state::IsSet,
    S::Key: defs_option_state::IsSet,
    S::CreatedBy: defs_option_state::IsSet,
    S::Scope: defs_option_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> DefsOption<'a> {
        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<jacquard_common::deps::smol_str::SmolStr, Data<'a>>,
    ) -> DefsOption<'a> {
        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()
    }
}