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

//! Generated bindings for the `place.stream.server` Lexicon namespace/module.
pub mod create_webhook;
pub mod delete_storage;
pub mod delete_webhook;
pub mod get_server_time;
pub mod get_storage;
pub mod get_webhook;
pub mod list_webhooks;
pub mod settings;
pub mod update_webhook;
pub mod upsert_storage;


#[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::{Datetime, UriValue};
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::place_stream::server;

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct RewriteRule<S: BosStr = DefaultStr> {
    ///Text to search for and replace.
    pub from: S,
    ///Text to replace with.
    pub to: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// S3 storage configuration for backups.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Storage<S: BosStr = DefaultStr> {
    ///Whether backup storage is currently active.
    pub is_active: bool,
    ///S3 storage URL with masked secret key in format: s3+https://ACCESS_KEY:***@endpoint/bucket
    pub url: S,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

/// A webhook configuration for receiving Streamplace events.

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct Webhook<S: BosStr = DefaultStr> {
    ///Whether this webhook is currently active.
    pub active: bool,
    ///When this webhook was created.
    pub created_at: Datetime,
    ///A description of what this webhook is used for.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<S>,
    ///Number of consecutive errors for this webhook.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error_count: Option<i64>,
    ///The types of events this webhook should receive.
    pub events: Vec<S>,
    ///Unique identifier for this webhook.
    pub id: S,
    ///When this webhook was last triggered.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub last_triggered: Option<Datetime>,
    ///Words to filter out from chat messages. Messages containing any of these words will not be forwarded.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub mute_words: Option<Vec<S>>,
    ///A user-friendly name for this webhook.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<S>,
    ///Text to prepend to webhook messages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub prefix: Option<S>,
    ///Text replacement rules for webhook messages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rewrite: Option<Vec<server::RewriteRule<S>>>,
    ///Text to append to webhook messages.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub suffix: Option<S>,
    ///When this webhook was last updated.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub updated_at: Option<Datetime>,
    ///The webhook URL where events will be sent.
    pub url: UriValue<S>,
    #[serde(flatten, default, skip_serializing_if = "Option::is_none")]
    pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}

impl<S: BosStr> LexiconSchema for RewriteRule<S> {
    fn nsid() -> &'static str {
        "place.stream.server.defs"
    }
    fn def_name() -> &'static str {
        "rewriteRule"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_server_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        {
            let value = &self.from;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("from"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.from;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) < 1usize {
                return Err(ConstraintError::MinLength {
                    path: ValidationPath::from_field("from"),
                    min: 1usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        {
            let value = &self.to;
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("to"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Storage<S> {
    fn nsid() -> &'static str {
        "place.stream.server.defs"
    }
    fn def_name() -> &'static str {
        "storage"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_server_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        Ok(())
    }
}

impl<S: BosStr> LexiconSchema for Webhook<S> {
    fn nsid() -> &'static str {
        "place.stream.server.defs"
    }
    fn def_name() -> &'static str {
        "webhook"
    }
    fn lexicon_doc() -> LexiconDoc<'static> {
        lexicon_doc_place_stream_server_defs()
    }
    fn validate(&self) -> Result<(), ConstraintError> {
        if let Some(ref value) = self.description {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 500usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("description"),
                    max: 500usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.name {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("name"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.prefix {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("prefix"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        if let Some(ref value) = self.suffix {
            #[allow(unused_comparisons)]
            if <str>::len(value.as_ref()) > 100usize {
                return Err(ConstraintError::MaxLength {
                    path: ValidationPath::from_field("suffix"),
                    max: 100usize,
                    actual: <str>::len(value.as_ref()),
                });
            }
        }
        Ok(())
    }
}

fn lexicon_doc_place_stream_server_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("place.stream.server.defs"),
        defs: {
            let mut map = BTreeMap::new();
            map.insert(
                SmolStr::new_static("rewriteRule"),
                LexUserType::Object(LexObject {
                    required: Some(
                        vec![SmolStr::new_static("from"), SmolStr::new_static("to")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("from"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Text to search for and replace."),
                                ),
                                min_length: Some(1usize),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("to"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Text to replace with."),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("storage"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static("S3 storage configuration for backups."),
                    ),
                    required: Some(
                        vec![SmolStr::new_static("url"), SmolStr::new_static("isActive")],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("isActive"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "S3 storage URL with masked secret key in format: s3+https://ACCESS_KEY:***@endpoint/bucket",
                                    ),
                                ),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map.insert(
                SmolStr::new_static("webhook"),
                LexUserType::Object(LexObject {
                    description: Some(
                        CowStr::new_static(
                            "A webhook configuration for receiving Streamplace events.",
                        ),
                    ),
                    required: Some(
                        vec![
                            SmolStr::new_static("id"), SmolStr::new_static("url"),
                            SmolStr::new_static("events"), SmolStr::new_static("active"),
                            SmolStr::new_static("createdAt")
                        ],
                    ),
                    properties: {
                        #[allow(unused_mut)]
                        let mut map = BTreeMap::new();
                        map.insert(
                            SmolStr::new_static("active"),
                            LexObjectProperty::Boolean(LexBoolean {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("createdAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When this webhook was created."),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("description"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "A description of what this webhook is used for.",
                                    ),
                                ),
                                max_length: Some(500usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("errorCount"),
                            LexObjectProperty::Integer(LexInteger {
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("events"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "The types of events this webhook should receive.",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("id"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Unique identifier for this webhook."),
                                ),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("lastTriggered"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When this webhook was last triggered."),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("muteWords"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Words to filter out from chat messages. Messages containing any of these words will not be forwarded.",
                                    ),
                                ),
                                items: LexArrayItem::String(LexString {
                                    max_length: Some(100usize),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("name"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("A user-friendly name for this webhook."),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("prefix"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Text to prepend to webhook messages."),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("rewrite"),
                            LexObjectProperty::Array(LexArray {
                                description: Some(
                                    CowStr::new_static(
                                        "Text replacement rules for webhook messages.",
                                    ),
                                ),
                                items: LexArrayItem::Ref(LexRef {
                                    r#ref: CowStr::new_static("#rewriteRule"),
                                    ..Default::default()
                                }),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("suffix"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("Text to append to webhook messages."),
                                ),
                                max_length: Some(100usize),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("updatedAt"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static("When this webhook was last updated."),
                                ),
                                format: Some(LexStringFormat::Datetime),
                                ..Default::default()
                            }),
                        );
                        map.insert(
                            SmolStr::new_static("url"),
                            LexObjectProperty::String(LexString {
                                description: Some(
                                    CowStr::new_static(
                                        "The webhook URL where events will be sent.",
                                    ),
                                ),
                                format: Some(LexStringFormat::Uri),
                                ..Default::default()
                            }),
                        );
                        map
                    },
                    ..Default::default()
                }),
            );
            map
        },
        ..Default::default()
    }
}

pub mod storage_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 IsActive;
        type Url;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type IsActive = Unset;
        type Url = Unset;
    }
    ///State transition - sets the `is_active` field to Set
    pub struct SetIsActive<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetIsActive<St> {}
    impl<St: State> State for SetIsActive<St> {
        type IsActive = Set<members::is_active>;
        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 IsActive = St::IsActive;
        type Url = Set<members::url>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `is_active` field
        pub struct is_active(());
        ///Marker type for the `url` field
        pub struct url(());
    }
}

/// Builder for constructing an instance of this type.
pub struct StorageBuilder<St: storage_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (Option<bool>, Option<S>),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Storage<S> {
    /// Create a new builder for this type
    pub fn builder() -> StorageBuilder<storage_state::Empty, S> {
        StorageBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> StorageBuilder<St, S>
where
    St: storage_state::State,
    St::IsActive: storage_state::IsUnset,
{
    /// Set the `isActive` field (required)
    pub fn is_active(
        mut self,
        value: impl Into<bool>,
    ) -> StorageBuilder<storage_state::SetIsActive<St>, S> {
        self._fields.0 = Option::Some(value.into());
        StorageBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St, S: BosStr> StorageBuilder<St, S>
where
    St: storage_state::State,
    St::IsActive: storage_state::IsSet,
    St::Url: storage_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Storage<S> {
        Storage {
            is_active: self._fields.0.unwrap(),
            url: self._fields.1.unwrap(),
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Storage<S> {
        Storage {
            is_active: self._fields.0.unwrap(),
            url: self._fields.1.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}

pub mod webhook_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 Active;
        type CreatedAt;
        type Events;
        type Id;
        type Url;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Active = Unset;
        type CreatedAt = Unset;
        type Events = Unset;
        type Id = Unset;
        type Url = Unset;
    }
    ///State transition - sets the `active` field to Set
    pub struct SetActive<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetActive<St> {}
    impl<St: State> State for SetActive<St> {
        type Active = Set<members::active>;
        type CreatedAt = St::CreatedAt;
        type Events = St::Events;
        type Id = St::Id;
        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 Active = St::Active;
        type CreatedAt = Set<members::created_at>;
        type Events = St::Events;
        type Id = St::Id;
        type Url = St::Url;
    }
    ///State transition - sets the `events` field to Set
    pub struct SetEvents<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEvents<St> {}
    impl<St: State> State for SetEvents<St> {
        type Active = St::Active;
        type CreatedAt = St::CreatedAt;
        type Events = Set<members::events>;
        type Id = St::Id;
        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 Active = St::Active;
        type CreatedAt = St::CreatedAt;
        type Events = St::Events;
        type Id = Set<members::id>;
        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 Active = St::Active;
        type CreatedAt = St::CreatedAt;
        type Events = St::Events;
        type Id = St::Id;
        type Url = Set<members::url>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `active` field
        pub struct active(());
        ///Marker type for the `created_at` field
        pub struct created_at(());
        ///Marker type for the `events` field
        pub struct events(());
        ///Marker type for the `id` field
        pub struct id(());
        ///Marker type for the `url` field
        pub struct url(());
    }
}

/// Builder for constructing an instance of this type.
pub struct WebhookBuilder<St: webhook_state::State, S: BosStr = DefaultStr> {
    _state: PhantomData<fn() -> St>,
    _fields: (
        Option<bool>,
        Option<Datetime>,
        Option<S>,
        Option<i64>,
        Option<Vec<S>>,
        Option<S>,
        Option<Datetime>,
        Option<Vec<S>>,
        Option<S>,
        Option<S>,
        Option<Vec<server::RewriteRule<S>>>,
        Option<S>,
        Option<Datetime>,
        Option<UriValue<S>>,
    ),
    _type: PhantomData<fn() -> S>,
}

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

impl<S: BosStr> Webhook<S> {
    /// Create a new builder for this type
    pub fn builder() -> WebhookBuilder<webhook_state::Empty, S> {
        WebhookBuilder::builder()
    }
}

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

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

impl<St, S: BosStr> WebhookBuilder<St, S>
where
    St: webhook_state::State,
    St::Active: webhook_state::IsUnset,
{
    /// Set the `active` field (required)
    pub fn active(
        mut self,
        value: impl Into<bool>,
    ) -> WebhookBuilder<webhook_state::SetActive<St>, S> {
        self._fields.0 = Option::Some(value.into());
        WebhookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

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

impl<St: webhook_state::State, S: BosStr> WebhookBuilder<St, S> {
    /// Set the `errorCount` field (optional)
    pub fn error_count(mut self, value: impl Into<Option<i64>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `errorCount` field to an Option value (optional)
    pub fn maybe_error_count(mut self, value: Option<i64>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<St, S: BosStr> WebhookBuilder<St, S>
where
    St: webhook_state::State,
    St::Events: webhook_state::IsUnset,
{
    /// Set the `events` field (required)
    pub fn events(
        mut self,
        value: impl Into<Vec<S>>,
    ) -> WebhookBuilder<webhook_state::SetEvents<St>, S> {
        self._fields.4 = Option::Some(value.into());
        WebhookBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

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

impl<St: webhook_state::State, S: BosStr> WebhookBuilder<St, S> {
    /// Set the `lastTriggered` field (optional)
    pub fn last_triggered(mut self, value: impl Into<Option<Datetime>>) -> Self {
        self._fields.6 = value.into();
        self
    }
    /// Set the `lastTriggered` field to an Option value (optional)
    pub fn maybe_last_triggered(mut self, value: Option<Datetime>) -> Self {
        self._fields.6 = value;
        self
    }
}

impl<St: webhook_state::State, S: BosStr> WebhookBuilder<St, S> {
    /// Set the `muteWords` field (optional)
    pub fn mute_words(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
        self._fields.7 = value.into();
        self
    }
    /// Set the `muteWords` field to an Option value (optional)
    pub fn maybe_mute_words(mut self, value: Option<Vec<S>>) -> Self {
        self._fields.7 = value;
        self
    }
}

impl<St: webhook_state::State, S: BosStr> WebhookBuilder<St, S> {
    /// Set the `name` field (optional)
    pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.8 = value.into();
        self
    }
    /// Set the `name` field to an Option value (optional)
    pub fn maybe_name(mut self, value: Option<S>) -> Self {
        self._fields.8 = value;
        self
    }
}

impl<St: webhook_state::State, S: BosStr> WebhookBuilder<St, S> {
    /// Set the `prefix` field (optional)
    pub fn prefix(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.9 = value.into();
        self
    }
    /// Set the `prefix` field to an Option value (optional)
    pub fn maybe_prefix(mut self, value: Option<S>) -> Self {
        self._fields.9 = value;
        self
    }
}

impl<St: webhook_state::State, S: BosStr> WebhookBuilder<St, S> {
    /// Set the `rewrite` field (optional)
    pub fn rewrite(
        mut self,
        value: impl Into<Option<Vec<server::RewriteRule<S>>>>,
    ) -> Self {
        self._fields.10 = value.into();
        self
    }
    /// Set the `rewrite` field to an Option value (optional)
    pub fn maybe_rewrite(mut self, value: Option<Vec<server::RewriteRule<S>>>) -> Self {
        self._fields.10 = value;
        self
    }
}

impl<St: webhook_state::State, S: BosStr> WebhookBuilder<St, S> {
    /// Set the `suffix` field (optional)
    pub fn suffix(mut self, value: impl Into<Option<S>>) -> Self {
        self._fields.11 = value.into();
        self
    }
    /// Set the `suffix` field to an Option value (optional)
    pub fn maybe_suffix(mut self, value: Option<S>) -> Self {
        self._fields.11 = value;
        self
    }
}

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

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

impl<St, S: BosStr> WebhookBuilder<St, S>
where
    St: webhook_state::State,
    St::Active: webhook_state::IsSet,
    St::CreatedAt: webhook_state::IsSet,
    St::Events: webhook_state::IsSet,
    St::Id: webhook_state::IsSet,
    St::Url: webhook_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Webhook<S> {
        Webhook {
            active: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            description: self._fields.2,
            error_count: self._fields.3,
            events: self._fields.4.unwrap(),
            id: self._fields.5.unwrap(),
            last_triggered: self._fields.6,
            mute_words: self._fields.7,
            name: self._fields.8,
            prefix: self._fields.9,
            rewrite: self._fields.10,
            suffix: self._fields.11,
            updated_at: self._fields.12,
            url: self._fields.13.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>>) -> Webhook<S> {
        Webhook {
            active: self._fields.0.unwrap(),
            created_at: self._fields.1.unwrap(),
            description: self._fields.2,
            error_count: self._fields.3,
            events: self._fields.4.unwrap(),
            id: self._fields.5.unwrap(),
            last_triggered: self._fields.6,
            mute_words: self._fields.7,
            name: self._fields.8,
            prefix: self._fields.9,
            rewrite: self._fields.10,
            suffix: self._fields.11,
            updated_at: self._fields.12,
            url: self._fields.13.unwrap(),
            extra_data: Some(extra_data),
        }
    }
}