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

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;

#[allow(unused_imports)]
use jacquard_common::deps::codegen::unicode_segmentation::UnicodeSegmentation;
use jacquard_common::types::string::{Did, Datetime};
use jacquard_derive::{IntoStatic, lexicon};
use jacquard_lexicon::lexicon::LexiconDoc;
use jacquard_lexicon::schema::LexiconSchema;

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

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ActionType<'a> {
    Block,
    Warn,
    Whitelist,
    Other(CowStr<'a>),
}

impl<'a> ActionType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Block => "block",
            Self::Warn => "warn",
            Self::Whitelist => "whitelist",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for ActionType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "block" => Self::Block,
            "warn" => Self::Warn,
            "whitelist" => Self::Whitelist,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ActionType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "block" => Self::Block,
            "warn" => Self::Warn,
            "whitelist" => Self::Whitelist,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for ActionType<'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 ActionType<'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 jacquard_common::IntoStatic for ActionType<'_> {
    type Output = ActionType<'static>;
    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

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Event<'a> {
    #[serde(borrow)]
    pub action: safelink::ActionType<'a>,
    ///Optional comment about the decision
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub comment: Option<CowStr<'a>>,
    pub created_at: Datetime,
    ///DID of the user who created this rule
    #[serde(borrow)]
    pub created_by: Did<'a>,
    #[serde(borrow)]
    pub event_type: safelink::EventType<'a>,
    ///Auto-incrementing row ID
    pub id: i64,
    #[serde(borrow)]
    pub pattern: safelink::PatternType<'a>,
    #[serde(borrow)]
    pub reason: safelink::ReasonType<'a>,
    ///The URL that this rule applies to
    #[serde(borrow)]
    pub url: CowStr<'a>,
}


#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum EventType<'a> {
    AddRule,
    UpdateRule,
    RemoveRule,
    Other(CowStr<'a>),
}

impl<'a> EventType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::AddRule => "addRule",
            Self::UpdateRule => "updateRule",
            Self::RemoveRule => "removeRule",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for EventType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "addRule" => Self::AddRule,
            "updateRule" => Self::UpdateRule,
            "removeRule" => Self::RemoveRule,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for EventType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "addRule" => Self::AddRule,
            "updateRule" => Self::UpdateRule,
            "removeRule" => Self::RemoveRule,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for EventType<'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 EventType<'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 jacquard_common::IntoStatic for EventType<'_> {
    type Output = EventType<'static>;
    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<'a> {
    Domain,
    Url,
    Other(CowStr<'a>),
}

impl<'a> PatternType<'a> {
    pub fn as_str(&self) -> &str {
        match self {
            Self::Domain => "domain",
            Self::Url => "url",
            Self::Other(s) => s.as_ref(),
        }
    }
}

impl<'a> From<&'a str> for PatternType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "domain" => Self::Domain,
            "url" => Self::Url,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for PatternType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "domain" => Self::Domain,
            "url" => Self::Url,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for PatternType<'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 PatternType<'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 jacquard_common::IntoStatic for PatternType<'_> {
    type Output = PatternType<'static>;
    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<'a> {
    Csam,
    Spam,
    Phishing,
    None,
    Other(CowStr<'a>),
}

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

impl<'a> From<&'a str> for ReasonType<'a> {
    fn from(s: &'a str) -> Self {
        match s {
            "csam" => Self::Csam,
            "spam" => Self::Spam,
            "phishing" => Self::Phishing,
            "none" => Self::None,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

impl<'a> From<String> for ReasonType<'a> {
    fn from(s: String) -> Self {
        match s.as_str() {
            "csam" => Self::Csam,
            "spam" => Self::Spam,
            "phishing" => Self::Phishing,
            "none" => Self::None,
            _ => Self::Other(CowStr::from(s)),
        }
    }
}

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

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

impl<'a> serde::Serialize for ReasonType<'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 ReasonType<'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 jacquard_common::IntoStatic for ReasonType<'_> {
    type Output = ReasonType<'static>;
    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

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

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

/// Builder for constructing an instance of this type
pub struct EventBuilder<'a, S: event_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<safelink::ActionType<'a>>,
        Option<CowStr<'a>>,
        Option<Datetime>,
        Option<Did<'a>>,
        Option<safelink::EventType<'a>>,
        Option<i64>,
        Option<safelink::PatternType<'a>>,
        Option<safelink::ReasonType<'a>>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

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

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

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

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

impl<'a, S> EventBuilder<'a, S>
where
    S: event_state::State,
    S::Reason: event_state::IsSet,
    S::EventType: event_state::IsSet,
    S::CreatedBy: event_state::IsSet,
    S::Url: event_state::IsSet,
    S::Pattern: event_state::IsSet,
    S::CreatedAt: event_state::IsSet,
    S::Id: event_state::IsSet,
    S::Action: event_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Event<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Event<'a> {
        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 Pattern;
        type Action;
        type Url;
        type Reason;
        type CreatedAt;
        type CreatedBy;
        type UpdatedAt;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Pattern = Unset;
        type Action = Unset;
        type Url = Unset;
        type Reason = Unset;
        type CreatedAt = Unset;
        type CreatedBy = Unset;
        type UpdatedAt = Unset;
    }
    ///State transition - sets the `pattern` field to Set
    pub struct SetPattern<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetPattern<S> {}
    impl<S: State> State for SetPattern<S> {
        type Pattern = Set<members::pattern>;
        type Action = S::Action;
        type Url = S::Url;
        type Reason = S::Reason;
        type CreatedAt = S::CreatedAt;
        type CreatedBy = S::CreatedBy;
        type UpdatedAt = S::UpdatedAt;
    }
    ///State transition - sets the `action` field to Set
    pub struct SetAction<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetAction<S> {}
    impl<S: State> State for SetAction<S> {
        type Pattern = S::Pattern;
        type Action = Set<members::action>;
        type Url = S::Url;
        type Reason = S::Reason;
        type CreatedAt = S::CreatedAt;
        type CreatedBy = S::CreatedBy;
        type UpdatedAt = S::UpdatedAt;
    }
    ///State transition - sets the `url` field to Set
    pub struct SetUrl<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUrl<S> {}
    impl<S: State> State for SetUrl<S> {
        type Pattern = S::Pattern;
        type Action = S::Action;
        type Url = Set<members::url>;
        type Reason = S::Reason;
        type CreatedAt = S::CreatedAt;
        type CreatedBy = S::CreatedBy;
        type UpdatedAt = S::UpdatedAt;
    }
    ///State transition - sets the `reason` field to Set
    pub struct SetReason<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetReason<S> {}
    impl<S: State> State for SetReason<S> {
        type Pattern = S::Pattern;
        type Action = S::Action;
        type Url = S::Url;
        type Reason = Set<members::reason>;
        type CreatedAt = S::CreatedAt;
        type CreatedBy = S::CreatedBy;
        type UpdatedAt = S::UpdatedAt;
    }
    ///State transition - sets the `created_at` field to Set
    pub struct SetCreatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetCreatedAt<S> {}
    impl<S: State> State for SetCreatedAt<S> {
        type Pattern = S::Pattern;
        type Action = S::Action;
        type Url = S::Url;
        type Reason = S::Reason;
        type CreatedAt = Set<members::created_at>;
        type CreatedBy = S::CreatedBy;
        type UpdatedAt = S::UpdatedAt;
    }
    ///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 Pattern = S::Pattern;
        type Action = S::Action;
        type Url = S::Url;
        type Reason = S::Reason;
        type CreatedAt = S::CreatedAt;
        type CreatedBy = Set<members::created_by>;
        type UpdatedAt = S::UpdatedAt;
    }
    ///State transition - sets the `updated_at` field to Set
    pub struct SetUpdatedAt<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetUpdatedAt<S> {}
    impl<S: State> State for SetUpdatedAt<S> {
        type Pattern = S::Pattern;
        type Action = S::Action;
        type Url = S::Url;
        type Reason = S::Reason;
        type CreatedAt = S::CreatedAt;
        type CreatedBy = S::CreatedBy;
        type UpdatedAt = Set<members::updated_at>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `pattern` field
        pub struct pattern(());
        ///Marker type for the `action` field
        pub struct action(());
        ///Marker type for the `url` field
        pub struct url(());
        ///Marker type for the `reason` field
        pub struct reason(());
        ///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 `updated_at` field
        pub struct updated_at(());
    }
}

/// Builder for constructing an instance of this type
pub struct UrlRuleBuilder<'a, S: url_rule_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (
        Option<safelink::ActionType<'a>>,
        Option<CowStr<'a>>,
        Option<Datetime>,
        Option<Did<'a>>,
        Option<safelink::PatternType<'a>>,
        Option<safelink::ReasonType<'a>>,
        Option<Datetime>,
        Option<CowStr<'a>>,
    ),
    _lifetime: PhantomData<&'a ()>,
}

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

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

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

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

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

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

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

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

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

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

impl<'a, S> UrlRuleBuilder<'a, S>
where
    S: url_rule_state::State,
    S::Pattern: url_rule_state::IsSet,
    S::Action: url_rule_state::IsSet,
    S::Url: url_rule_state::IsSet,
    S::Reason: url_rule_state::IsSet,
    S::CreatedAt: url_rule_state::IsSet,
    S::CreatedBy: url_rule_state::IsSet,
    S::UpdatedAt: url_rule_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> UrlRule<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> UrlRule<'a> {
        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),
        }
    }
}