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

#[allow(unused_imports)]
use alloc::collections::BTreeMap;

#[allow(unused_imports)]
use core::marker::PhantomData;
use jacquard_common::CowStr;
use jacquard_common::types::string::UriValue;
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
use crate::place_stream::server::RewriteRule;
use crate::place_stream::server::Webhook;

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct UpdateWebhook<'a> {
    ///Whether this webhook should be active.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub active: Option<bool>,
    ///A description of what this webhook is used for.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub description: Option<CowStr<'a>>,
    ///The types of events this webhook should receive.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub events: Option<Vec<CowStr<'a>>>,
    ///The ID of the webhook to update.
    #[serde(borrow)]
    pub id: CowStr<'a>,
    ///Words to filter out from chat messages. Messages containing any of these words will not be forwarded.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub mute_words: Option<Vec<CowStr<'a>>>,
    ///A user-friendly name for this webhook.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub name: Option<CowStr<'a>>,
    ///Text to prepend to webhook messages.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub prefix: Option<CowStr<'a>>,
    ///Text replacement rules for webhook messages.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub rewrite: Option<Vec<RewriteRule<'a>>>,
    ///Text to append to webhook messages.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub suffix: Option<CowStr<'a>>,
    ///The webhook URL where events will be sent.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(borrow)]
    pub url: Option<UriValue<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct UpdateWebhookOutput<'a> {
    #[serde(borrow)]
    pub webhook: Webhook<'a>,
}


#[open_union]
#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
    Eq,
    thiserror::Error,
    miette::Diagnostic,
    IntoStatic
)]

#[serde(tag = "error", content = "message")]
#[serde(bound(deserialize = "'de: 'a"))]
pub enum UpdateWebhookError<'a> {
    /// The specified webhook was not found.
    #[serde(rename = "WebhookNotFound")]
    WebhookNotFound(Option<CowStr<'a>>),
    /// The authenticated user does not have access to this webhook.
    #[serde(rename = "Unauthorized")]
    Unauthorized(Option<CowStr<'a>>),
    /// The provided webhook URL is invalid or unreachable.
    #[serde(rename = "InvalidUrl")]
    InvalidUrl(Option<CowStr<'a>>),
    /// A webhook with this URL already exists for this user.
    #[serde(rename = "DuplicateWebhook")]
    DuplicateWebhook(Option<CowStr<'a>>),
}

impl core::fmt::Display for UpdateWebhookError<'_> {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        match self {
            Self::WebhookNotFound(msg) => {
                write!(f, "WebhookNotFound")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            Self::Unauthorized(msg) => {
                write!(f, "Unauthorized")?;
                if let Some(msg) = msg {
                    write!(f, ": {}", msg)?;
                }
                Ok(())
            }
            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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

/// Response type for place.stream.server.updateWebhook
pub struct UpdateWebhookResponse;
impl jacquard_common::xrpc::XrpcResp for UpdateWebhookResponse {
    const NSID: &'static str = "place.stream.server.updateWebhook";
    const ENCODING: &'static str = "application/json";
    type Output<'de> = UpdateWebhookOutput<'de>;
    type Err<'de> = UpdateWebhookError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for UpdateWebhook<'a> {
    const NSID: &'static str = "place.stream.server.updateWebhook";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Response = UpdateWebhookResponse;
}

/// Endpoint type for place.stream.server.updateWebhook
pub struct UpdateWebhookRequest;
impl jacquard_common::xrpc::XrpcEndpoint for UpdateWebhookRequest {
    const PATH: &'static str = "/xrpc/place.stream.server.updateWebhook";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
        "application/json",
    );
    type Request<'de> = UpdateWebhook<'de>;
    type Response = UpdateWebhookResponse;
}