// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: tools.ozone.safelink.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.safelink` Lexicon namespace/module.
pub mod add_rule;
pub mod query_events;
pub mod query_rules;
pub mod remove_rule;
pub mod update_rule;


#[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, 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};
use crate::tools_ozone::safelink;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ActionType<S: BosStr = DefaultStr> {
    Block,
    Warn,
    Whitelist,
    Other(S),
}

impl<S: BosStr> ActionType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Block => "block",
            Self::Warn => "warn",
            Self::Whitelist => "whitelist",
            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() {
            "block" => Self::Block,
            "warn" => Self::Warn,
            "whitelist" => Self::Whitelist,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for ActionType<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 ActionType<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> jacquard_common::IntoStatic for ActionType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ActionType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ActionType::Block => ActionType::Block,
            ActionType::Warn => ActionType::Warn,
            ActionType::Whitelist => ActionType::Whitelist,
            ActionType::Other(v) => ActionType::Other(v.into_static()),
        }
    }
}

/// An event for URL safety decisions

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Event<S: BosStr = DefaultStr> {
    pub action: safelink::ActionType<S>,
    ///Optional comment about the decision
    #[serde(skip_serializing_if = "Option::is_none")]
    pub comment: Option<S>,
    pub created_at: Datetime,
    ///DID of the user who created this rule
    pub created_by: Did<S>,
    pub event_type: safelink::EventType<S>,
    ///Auto-incrementing row ID
    pub id: i64,
    pub pattern: safelink::PatternType<S>,
    pub reason: safelink::ReasonType<S>,
    ///The URL that this rule applies to
    pub url: 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 EventType<S: BosStr = DefaultStr> {
    AddRule,
    UpdateRule,
    RemoveRule,
    Other(S),
}

impl<S: BosStr> EventType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::AddRule => "addRule",
            Self::UpdateRule => "updateRule",
            Self::RemoveRule => "removeRule",
            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() {
            "addRule" => Self::AddRule,
            "updateRule" => Self::UpdateRule,
            "removeRule" => Self::RemoveRule,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for EventType<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 EventType<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> jacquard_common::IntoStatic for EventType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = EventType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            EventType::AddRule => EventType::AddRule,
            EventType::UpdateRule => EventType::UpdateRule,
            EventType::RemoveRule => EventType::RemoveRule,
            EventType::Other(v) => EventType::Other(v.into_static()),
        }
    }
}


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

impl<S: BosStr> PatternType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Domain => "domain",
            Self::Url => "url",
            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() {
            "domain" => Self::Domain,
            "url" => Self::Url,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for PatternType<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 PatternType<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> jacquard_common::IntoStatic for PatternType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = PatternType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            PatternType::Domain => PatternType::Domain,
            PatternType::Url => PatternType::Url,
            PatternType::Other(v) => PatternType::Other(v.into_static()),
        }
    }
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ReasonType<S: BosStr = DefaultStr> {
    Csam,
    Spam,
    Phishing,
    None,
    Other(S),
}

impl<S: BosStr> ReasonType<S> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Csam => "csam",
            Self::Spam => "spam",
            Self::Phishing => "phishing",
            Self::None => "none",
            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() {
            "csam" => Self::Csam,
            "spam" => Self::Spam,
            "phishing" => Self::Phishing,
            "none" => Self::None,
            _ => Self::Other(s),
        }
    }
}

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

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

impl<S: BosStr> Serialize for ReasonType<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 ReasonType<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> jacquard_common::IntoStatic for ReasonType<S>
where
    S: BosStr + jacquard_common::IntoStatic,
    S::Output: BosStr,
{
    type Output = ReasonType<S::Output>;
    fn into_static(self) -> Self::Output {
        match self {
            ReasonType::Csam => ReasonType::Csam,
            ReasonType::Spam => ReasonType::Spam,
            ReasonType::Phishing => ReasonType::Phishing,
            ReasonType::None => ReasonType::None,
            ReasonType::Other(v) => ReasonType::Other(v.into_static()),
        }
    }
}

/// Input for creating a URL safety rule

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct UrlRule<S: BosStr = DefaultStr> {
    pub action: safelink::ActionType<S>,
    ///Optional comment about the decision
    #[serde(skip_serializing_if = "Option::is_none")]
    pub comment: Option<S>,
    ///Timestamp when the rule was created
    pub created_at: Datetime,
    ///DID of the user added the rule.
    pub created_by: Did<S>,
    pub pattern: safelink::PatternType<S>,
    pub reason: safelink::ReasonType<S>,
    ///Timestamp when the rule was last updated
    pub updated_at: Datetime,
    ///The URL or domain to apply the rule to
    pub url: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for Event<S> {
    fn nsid() -> &'static str {
        "tools.ozone.safelink.defs"
    }
    fn def_name() -> &'static str {
        "event"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_safelink_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for UrlRule<S> {
    fn nsid() -> &'static str {
        "tools.ozone.safelink.defs"
    }
    fn def_name() -> &'static str {
        "urlRule"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_tools_ozone_safelink_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

pub mod event_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 Action;
        type CreatedAt;
        type CreatedBy;
        type EventType;
        type Id;
        type Pattern;
        type Reason;
        type Url;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Action = Unset;
        type CreatedAt = Unset;
        type CreatedBy = Unset;
        type EventType = Unset;
        type Id = Unset;
        type Pattern = Unset;
        type Reason = Unset;
        type Url = Unset;
    }
    ///State transition - sets the `action` field to Set
    pub struct SetAction<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAction<St> {}
    impl<St: State> State for SetAction<St> {
        type Action = Set<members::action>;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type EventType = St::EventType;
        type Id = St::Id;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type Url = St::Url;
    }
    ///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 Action = St::Action;
        type CreatedAt = Set<members::created_at>;
        type CreatedBy = St::CreatedBy;
        type EventType = St::EventType;
        type Id = St::Id;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type Url = St::Url;
    }
    ///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 Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = Set<members::created_by>;
        type EventType = St::EventType;
        type Id = St::Id;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type Url = St::Url;
    }
    ///State transition - sets the `event_type` field to Set
    pub struct SetEventType<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEventType<St> {}
    impl<St: State> State for SetEventType<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type EventType = Set<members::event_type>;
        type Id = St::Id;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type Url = St::Url;
    }
    ///State transition - sets the `id` field to Set
    pub struct SetId<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetId<St> {}
    impl<St: State> State for SetId<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type EventType = St::EventType;
        type Id = Set<members::id>;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type Url = St::Url;
    }
    ///State transition - sets the `pattern` field to Set
    pub struct SetPattern<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPattern<St> {}
    impl<St: State> State for SetPattern<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type EventType = St::EventType;
        type Id = St::Id;
        type Pattern = Set<members::pattern>;
        type Reason = St::Reason;
        type Url = St::Url;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReason<St> {}
    impl<St: State> State for SetReason<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type EventType = St::EventType;
        type Id = St::Id;
        type Pattern = St::Pattern;
        type Reason = Set<members::reason>;
        type Url = St::Url;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUrl<St> {}
    impl<St: State> State for SetUrl<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type EventType = St::EventType;
        type Id = St::Id;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type Url = Set<members::url>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `action` field
        pub struct action(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `created_by` field
        pub struct created_by(());
        ///Marker type for the `event_type` field
        pub struct event_type(());
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `pattern` field
        pub struct pattern(());
        ///Marker type for the `reason` field
        pub struct reason(());
        ///Marker type for the `url` field
        pub struct url(());
    }
}

/// Builder for constructing an instance of this type.
pub struct EventBuilder<St: event_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<safelink::ActionType<S>>,
        Option<S>,
        Option<Datetime>,
        Option<Did<S>>,
        Option<safelink::EventType<S>>,
        Option<i64>,
        Option<safelink::PatternType<S>>,
        Option<safelink::ReasonType<S>>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Event<S> {
    /// Create a new builder for this type
    pub fn builder() -> EventBuilder<event_state::Empty, S> {
        EventBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::Action: event_state::IsUnset,
{
    /// Set the `action` field (required)
    pub fn action(
        mut self,
        value: impl Into<safelink::ActionType<S>>,
    ) -> EventBuilder<event_state::SetAction<St>, S> {
        self._fields.0 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: event_state::State, S: BosStr> EventBuilder<St, S> {
    /// Set the `comment` field (optional)
    pub fn comment(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `comment` field to an Option value (optional)
    pub fn maybe_comment(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::EventType: event_state::IsUnset,
{
    /// Set the `eventType` field (required)
    pub fn event_type(
        mut self,
        value: impl Into<safelink::EventType<S>>,
    ) -> EventBuilder<event_state::SetEventType<St>, S> {
        self._fields.4 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::Id: event_state::IsUnset,
{
    /// Set the `id` field (required)
    pub fn id(
        mut self,
        value: impl Into<i64>,
    ) -> EventBuilder<event_state::SetId<St>, S> {
        self._fields.5 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::Pattern: event_state::IsUnset,
{
    /// Set the `pattern` field (required)
    pub fn pattern(
        mut self,
        value: impl Into<safelink::PatternType<S>>,
    ) -> EventBuilder<event_state::SetPattern<St>, S> {
        self._fields.6 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::Reason: event_state::IsUnset,
{
    /// Set the `reason` field (required)
    pub fn reason(
        mut self,
        value: impl Into<safelink::ReasonType<S>>,
    ) -> EventBuilder<event_state::SetReason<St>, S> {
        self._fields.7 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::Url: event_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<S>,
    ) -> EventBuilder<event_state::SetUrl<St>, S> {
        self._fields.8 = Option::Some(value.into());
        EventBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> EventBuilder<St, S>
where
    St: event_state::State,
    St::Action: event_state::IsSet,
    St::CreatedAt: event_state::IsSet,
    St::CreatedBy: event_state::IsSet,
    St::EventType: event_state::IsSet,
    St::Id: event_state::IsSet,
    St::Pattern: event_state::IsSet,
    St::Reason: event_state::IsSet,
    St::Url: event_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Event<S> {
        Event {
            action: self._fields.0.unwrap(),
            comment: self._fields.1,
            created_at: self._fields.2.unwrap(),
            created_by: self._fields.3.unwrap(),
            event_type: self._fields.4.unwrap(),
            id: self._fields.5.unwrap(),
            pattern: self._fields.6.unwrap(),
            reason: self._fields.7.unwrap(),
            url: self._fields.8.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>>) -> Event<S> {
        Event {
            action: self._fields.0.unwrap(),
            comment: self._fields.1,
            created_at: self._fields.2.unwrap(),
            created_by: self._fields.3.unwrap(),
            event_type: self._fields.4.unwrap(),
            id: self._fields.5.unwrap(),
            pattern: self._fields.6.unwrap(),
            reason: self._fields.7.unwrap(),
            url: self._fields.8.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

fn lexicon_doc_tools_ozone_safelink_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.safelink.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("actionType"),
                LexUserType::String(LexString { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("event"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("An event for URL safety decisions"),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("id"), SmolStr::new_static("eventType"),
                            SmolStr::new_static("url"), SmolStr::new_static("pattern"),
                            SmolStr::new_static("action"), SmolStr::new_static("reason"),
                            SmolStr::new_static("createdBy"),
                            SmolStr::new_static("createdAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("action"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#actionType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("comment"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Optional comment about the decision"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdBy"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("DID of the user who created this rule"),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("eventType"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#eventType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("pattern"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#patternType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reason"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#reasonType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The URL that this rule applies to"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("eventType"),
                LexUserType::String(LexString { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("patternType"),
                LexUserType::String(LexString { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("reasonType"),
                LexUserType::String(LexString { ..Default::default() }),
            );
            map.insert(
                SmolStr::new_static("urlRule"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("Input for creating a URL safety rule"),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("url"), SmolStr::new_static("pattern"),
                            SmolStr::new_static("action"), SmolStr::new_static("reason"),
                            SmolStr::new_static("createdBy"),
                            SmolStr::new_static("createdAt"),
                            SmolStr::new_static("updatedAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("action"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#actionType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("comment"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Optional comment about the decision"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Timestamp when the rule was created"),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdBy"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("DID of the user added the rule."),
                                ),
                                format: Some(LexStringFormat::Did),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("pattern"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#patternType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("reason"),
                            LexObjectProperty::Ref(LexRef {
                                r#ref: CowStr::new_static("#reasonType"),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("updatedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "Timestamp when the rule was last updated",
                                    ),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("The URL or domain to apply the rule to"),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod url_rule_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 Action;
        type CreatedAt;
        type CreatedBy;
        type Pattern;
        type Reason;
        type UpdatedAt;
        type Url;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Action = Unset;
        type CreatedAt = Unset;
        type CreatedBy = Unset;
        type Pattern = Unset;
        type Reason = Unset;
        type UpdatedAt = Unset;
        type Url = Unset;
    }
    ///State transition - sets the `action` field to Set
    pub struct SetAction<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetAction<St> {}
    impl<St: State> State for SetAction<St> {
        type Action = Set<members::action>;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type UpdatedAt = St::UpdatedAt;
        type Url = St::Url;
    }
    ///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 Action = St::Action;
        type CreatedAt = Set<members::created_at>;
        type CreatedBy = St::CreatedBy;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type UpdatedAt = St::UpdatedAt;
        type Url = St::Url;
    }
    ///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 Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = Set<members::created_by>;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type UpdatedAt = St::UpdatedAt;
        type Url = St::Url;
    }
    ///State transition - sets the `pattern` field to Set
    pub struct SetPattern<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetPattern<St> {}
    impl<St: State> State for SetPattern<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Pattern = Set<members::pattern>;
        type Reason = St::Reason;
        type UpdatedAt = St::UpdatedAt;
        type Url = St::Url;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetReason<St> {}
    impl<St: State> State for SetReason<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Pattern = St::Pattern;
        type Reason = Set<members::reason>;
        type UpdatedAt = St::UpdatedAt;
        type Url = St::Url;
    }
    ///State transition - sets the `updated_at` field to Set
    pub struct SetUpdatedAt<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUpdatedAt<St> {}
    impl<St: State> State for SetUpdatedAt<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type UpdatedAt = Set<members::updated_at>;
        type Url = St::Url;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetUrl<St> {}
    impl<St: State> State for SetUrl<St> {
        type Action = St::Action;
        type CreatedAt = St::CreatedAt;
        type CreatedBy = St::CreatedBy;
        type Pattern = St::Pattern;
        type Reason = St::Reason;
        type UpdatedAt = St::UpdatedAt;
        type Url = Set<members::url>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `action` field
        pub struct action(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `created_by` field
        pub struct created_by(());
        ///Marker type for the `pattern` field
        pub struct pattern(());
        ///Marker type for the `reason` field
        pub struct reason(());
        ///Marker type for the `updated_at` field
        pub struct updated_at(());
        ///Marker type for the `url` field
        pub struct url(());
    }
}

/// Builder for constructing an instance of this type.
pub struct UrlRuleBuilder<St: url_rule_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<safelink::ActionType<S>>,
        Option<S>,
        Option<Datetime>,
        Option<Did<S>>,
        Option<safelink::PatternType<S>>,
        Option<safelink::ReasonType<S>>,
        Option<Datetime>,
        Option<S>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> UrlRule<S> {
    /// Create a new builder for this type
    pub fn builder() -> UrlRuleBuilder<url_rule_state::Empty, S> {
        UrlRuleBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> UrlRuleBuilder<St, S>
where
    St: url_rule_state::State,
    St::Action: url_rule_state::IsUnset,
{
    /// Set the `action` field (required)
    pub fn action(
        mut self,
        value: impl Into<safelink::ActionType<S>>,
    ) -> UrlRuleBuilder<url_rule_state::SetAction<St>, S> {
        self._fields.0 = Option::Some(value.into());
        UrlRuleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St: url_rule_state::State, S: BosStr> UrlRuleBuilder<St, S> {
    /// Set the `comment` field (optional)
    pub fn comment(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.1 = value.into();
        self
    }
    /// Set the `comment` field to an Option value (optional)
    pub fn maybe_comment(mut self, value: Option<S>) -> Self {
        self._fields.1 = value;
        self
    }
}

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

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

impl<St, S: BosStr> UrlRuleBuilder<St, S>
where
    St: url_rule_state::State,
    St::Pattern: url_rule_state::IsUnset,
{
    /// Set the `pattern` field (required)
    pub fn pattern(
        mut self,
        value: impl Into<safelink::PatternType<S>>,
    ) -> UrlRuleBuilder<url_rule_state::SetPattern<St>, S> {
        self._fields.4 = Option::Some(value.into());
        UrlRuleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UrlRuleBuilder<St, S>
where
    St: url_rule_state::State,
    St::Reason: url_rule_state::IsUnset,
{
    /// Set the `reason` field (required)
    pub fn reason(
        mut self,
        value: impl Into<safelink::ReasonType<S>>,
    ) -> UrlRuleBuilder<url_rule_state::SetReason<St>, S> {
        self._fields.5 = Option::Some(value.into());
        UrlRuleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UrlRuleBuilder<St, S>
where
    St: url_rule_state::State,
    St::UpdatedAt: url_rule_state::IsUnset,
{
    /// Set the `updatedAt` field (required)
    pub fn updated_at(
        mut self,
        value: impl Into<Datetime>,
    ) -> UrlRuleBuilder<url_rule_state::SetUpdatedAt<St>, S> {
        self._fields.6 = Option::Some(value.into());
        UrlRuleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UrlRuleBuilder<St, S>
where
    St: url_rule_state::State,
    St::Url: url_rule_state::IsUnset,
{
    /// Set the `url` field (required)
    pub fn url(
        mut self,
        value: impl Into<S>,
    ) -> UrlRuleBuilder<url_rule_state::SetUrl<St>, S> {
        self._fields.7 = Option::Some(value.into());
        UrlRuleBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<St, S: BosStr> UrlRuleBuilder<St, S>
where
    St: url_rule_state::State,
    St::Action: url_rule_state::IsSet,
    St::CreatedAt: url_rule_state::IsSet,
    St::CreatedBy: url_rule_state::IsSet,
    St::Pattern: url_rule_state::IsSet,
    St::Reason: url_rule_state::IsSet,
    St::UpdatedAt: url_rule_state::IsSet,
    St::Url: url_rule_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> UrlRule<S> {
        UrlRule {
            action: self._fields.0.unwrap(),
            comment: self._fields.1,
            created_at: self._fields.2.unwrap(),
            created_by: self._fields.3.unwrap(),
            pattern: self._fields.4.unwrap(),
            reason: self._fields.5.unwrap(),
            updated_at: self._fields.6.unwrap(),
            url: self._fields.7.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> UrlRule<S> {
        UrlRule {
            action: self._fields.0.unwrap(),
            comment: self._fields.1,
            created_at: self._fields.2.unwrap(),
            created_by: self._fields.3.unwrap(),
            pattern: self._fields.4.unwrap(),
            reason: self._fields.5.unwrap(),
            updated_at: self._fields.6.unwrap(),
            url: self._fields.7.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}