#[allow(unused_imports)]
use alloc::collections::BTreeMap;
#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::{CowStr, BosStr, DefaultStr, FromStaticStr};
use jacquard_common::deps::smol_str::SmolStr;
use jacquard_common::types::string::UriValue;
use jacquard_common::types::value::Data;
use jacquard_derive::{IntoStatic, open_union};
use serde::{Serialize, Deserialize};
use crate::place_stream::server::RewriteRule;
use crate::place_stream::server::Webhook;
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateWebhook<S: BosStr = DefaultStr> {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default = "_default_create_webhook_active")]
pub active: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<S>,
pub events: Vec<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mute_words: Option<Vec<S>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub prefix: Option<S>,
#[serde(skip_serializing_if = "Option::is_none")]
pub rewrite: Option<Vec<RewriteRule<S>>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub suffix: Option<S>,
pub url: UriValue<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase", bound(deserialize = "S: Deserialize<'de> + BosStr"))]
pub struct CreateWebhookOutput<S: BosStr = DefaultStr> {
pub webhook: Webhook<S>,
#[serde(flatten, default, skip_serializing_if = "Option::is_none")]
pub extra_data: Option<BTreeMap<SmolStr, Data<S>>>,
}
#[derive(
Serialize,
Deserialize,
Debug,
Clone,
PartialEq,
Eq,
thiserror::Error,
miette::Diagnostic
)]
#[serde(tag = "error", content = "message")]
pub enum CreateWebhookError {
#[serde(rename = "InvalidUrl")]
InvalidUrl(Option<SmolStr>),
#[serde(rename = "DuplicateWebhook")]
DuplicateWebhook(Option<SmolStr>),
#[serde(rename = "TooManyWebhooks")]
TooManyWebhooks(Option<SmolStr>),
#[serde(untagged)]
Other { error: SmolStr, message: Option<SmolStr> },
}
impl core::fmt::Display for CreateWebhookError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::InvalidUrl(msg) => {
write!(f, "InvalidUrl")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::DuplicateWebhook(msg) => {
write!(f, "DuplicateWebhook")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::TooManyWebhooks(msg) => {
write!(f, "TooManyWebhooks")?;
if let Some(msg) = msg {
write!(f, ": {}", msg)?;
}
Ok(())
}
Self::Other { error, message } => {
write!(f, "{}", error)?;
if let Some(msg) = message {
write!(f, ": {}", msg)?;
}
Ok(())
}
}
}
}
pub struct CreateWebhookResponse;
impl jacquard_common::xrpc::XrpcResp for CreateWebhookResponse {
const NSID: &'static str = "place.stream.server.createWebhook";
const ENCODING: &'static str = "application/json";
type Output<S: BosStr> = CreateWebhookOutput<S>;
type Err = CreateWebhookError;
}
impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for CreateWebhook<S> {
const NSID: &'static str = "place.stream.server.createWebhook";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Response = CreateWebhookResponse;
}
pub struct CreateWebhookRequest;
impl jacquard_common::xrpc::XrpcEndpoint for CreateWebhookRequest {
const PATH: &'static str = "/xrpc/place.stream.server.createWebhook";
const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
"application/json",
);
type Request<S: BosStr> = CreateWebhook<S>;
type Response = CreateWebhookResponse;
}
fn _default_create_webhook_active() -> Option<bool> {
Some(false)
}
pub mod create_webhook_state {
pub use crate::builder_types::{Set, Unset, IsSet, IsUnset};
#[allow(unused)]
use ::core::marker::PhantomData;
mod sealed {
pub trait Sealed {}
}
pub trait State: sealed::Sealed {
type Events;
type Url;
}
pub struct Empty(());
impl sealed::Sealed for Empty {}
impl State for Empty {
type Events = Unset;
type Url = Unset;
}
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 Events = Set<members::events>;
type Url = St::Url;
}
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 Events = St::Events;
type Url = Set<members::url>;
}
#[allow(non_camel_case_types)]
pub mod members {
pub struct events(());
pub struct url(());
}
}
pub struct CreateWebhookBuilder<S: BosStr, St: create_webhook_state::State> {
_state: PhantomData<fn() -> St>,
_fields: (
Option<bool>,
Option<S>,
Option<Vec<S>>,
Option<Vec<S>>,
Option<S>,
Option<S>,
Option<Vec<RewriteRule<S>>>,
Option<S>,
Option<UriValue<S>>,
),
_type: PhantomData<fn() -> S>,
}
impl<S: BosStr> CreateWebhook<S> {
pub fn new() -> CreateWebhookBuilder<S, create_webhook_state::Empty> {
CreateWebhookBuilder::new()
}
}
impl<S: BosStr> CreateWebhookBuilder<S, create_webhook_state::Empty> {
pub fn new() -> Self {
CreateWebhookBuilder {
_state: PhantomData,
_fields: (None, None, None, None, None, None, None, None, None),
_type: PhantomData,
}
}
}
impl<S: BosStr, St: create_webhook_state::State> CreateWebhookBuilder<S, St> {
pub fn active(mut self, value: impl Into<Option<bool>>) -> Self {
self._fields.0 = value.into();
self
}
pub fn maybe_active(mut self, value: Option<bool>) -> Self {
self._fields.0 = value;
self
}
}
impl<S: BosStr, St: create_webhook_state::State> CreateWebhookBuilder<S, St> {
pub fn description(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.1 = value.into();
self
}
pub fn maybe_description(mut self, value: Option<S>) -> Self {
self._fields.1 = value;
self
}
}
impl<S: BosStr, St> CreateWebhookBuilder<S, St>
where
St: create_webhook_state::State,
St::Events: create_webhook_state::IsUnset,
{
pub fn events(
mut self,
value: impl Into<Vec<S>>,
) -> CreateWebhookBuilder<S, create_webhook_state::SetEvents<St>> {
self._fields.2 = Option::Some(value.into());
CreateWebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St: create_webhook_state::State> CreateWebhookBuilder<S, St> {
pub fn mute_words(mut self, value: impl Into<Option<Vec<S>>>) -> Self {
self._fields.3 = value.into();
self
}
pub fn maybe_mute_words(mut self, value: Option<Vec<S>>) -> Self {
self._fields.3 = value;
self
}
}
impl<S: BosStr, St: create_webhook_state::State> CreateWebhookBuilder<S, St> {
pub fn name(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.4 = value.into();
self
}
pub fn maybe_name(mut self, value: Option<S>) -> Self {
self._fields.4 = value;
self
}
}
impl<S: BosStr, St: create_webhook_state::State> CreateWebhookBuilder<S, St> {
pub fn prefix(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.5 = value.into();
self
}
pub fn maybe_prefix(mut self, value: Option<S>) -> Self {
self._fields.5 = value;
self
}
}
impl<S: BosStr, St: create_webhook_state::State> CreateWebhookBuilder<S, St> {
pub fn rewrite(mut self, value: impl Into<Option<Vec<RewriteRule<S>>>>) -> Self {
self._fields.6 = value.into();
self
}
pub fn maybe_rewrite(mut self, value: Option<Vec<RewriteRule<S>>>) -> Self {
self._fields.6 = value;
self
}
}
impl<S: BosStr, St: create_webhook_state::State> CreateWebhookBuilder<S, St> {
pub fn suffix(mut self, value: impl Into<Option<S>>) -> Self {
self._fields.7 = value.into();
self
}
pub fn maybe_suffix(mut self, value: Option<S>) -> Self {
self._fields.7 = value;
self
}
}
impl<S: BosStr, St> CreateWebhookBuilder<S, St>
where
St: create_webhook_state::State,
St::Url: create_webhook_state::IsUnset,
{
pub fn url(
mut self,
value: impl Into<UriValue<S>>,
) -> CreateWebhookBuilder<S, create_webhook_state::SetUrl<St>> {
self._fields.8 = Option::Some(value.into());
CreateWebhookBuilder {
_state: PhantomData,
_fields: self._fields,
_type: PhantomData,
}
}
}
impl<S: BosStr, St> CreateWebhookBuilder<S, St>
where
St: create_webhook_state::State,
St::Events: create_webhook_state::IsSet,
St::Url: create_webhook_state::IsSet,
{
pub fn build(self) -> CreateWebhook<S> {
CreateWebhook {
active: self._fields.0.or_else(|| Some(false)),
description: self._fields.1,
events: self._fields.2.unwrap(),
mute_words: self._fields.3,
name: self._fields.4,
prefix: self._fields.5,
rewrite: self._fields.6,
suffix: self._fields.7,
url: self._fields.8.unwrap(),
extra_data: Default::default(),
}
}
pub fn build_with_data(
self,
extra_data: BTreeMap<SmolStr, Data<S>>,
) -> CreateWebhook<S> {
CreateWebhook {
active: self._fields.0.or_else(|| Some(false)),
description: self._fields.1,
events: self._fields.2.unwrap(),
mute_words: self._fields.3,
name: self._fields.4,
prefix: self._fields.5,
rewrite: self._fields.6,
suffix: self._fields.7,
url: self._fields.8.unwrap(),
extra_data: Some(extra_data),
}
}
}