// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: place.stream.server.getWebhook
//
// 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_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};
use crate::place_stream::server::Webhook;

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


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct GetWebhookOutput<'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 GetWebhookError<'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>>),
}

impl core::fmt::Display for GetWebhookError<'_> {
    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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

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

impl<'a> jacquard_common::xrpc::XrpcRequest for GetWebhook<'a> {
    const NSID: &'static str = "place.stream.server.getWebhook";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Response = GetWebhookResponse;
}

/// Endpoint type for place.stream.server.getWebhook
pub struct GetWebhookRequest;
impl jacquard_common::xrpc::XrpcEndpoint for GetWebhookRequest {
    const PATH: &'static str = "/xrpc/place.stream.server.getWebhook";
    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Query;
    type Request<'de> = GetWebhook<'de>;
    type Response = GetWebhookResponse;
}

pub mod get_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 Id;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Id = Unset;
    }
    ///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 Id = Set<members::id>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `id` field
        pub struct id(());
    }
}

/// Builder for constructing an instance of this type
pub struct GetWebhookBuilder<'a, S: get_webhook_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<CowStr<'a>>,),
    _lifetime: PhantomData<&'a ()>,
}

impl<'a> GetWebhook<'a> {
    /// Create a new builder for this type
    pub fn new() -> GetWebhookBuilder<'a, get_webhook_state::Empty> {
        GetWebhookBuilder::new()
    }
}

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

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

impl<'a, S> GetWebhookBuilder<'a, S>
where
    S: get_webhook_state::State,
    S::Id: get_webhook_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> GetWebhook<'a> {
        GetWebhook {
            id: self._fields.0.unwrap(),
        }
    }
}