jacquard-api 0.12.0-beta.2

Generated AT Protocol API bindings for Jacquard
Documentation
// @generated by jacquard-lexicon. DO NOT EDIT.
//
// Lexicon: events.smokesignal.event.configure
//
// 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::deps::smol_str::SmolStr;
use jacquard_common::types::string::{AtUri, UriValue};
use jacquard_common::types::value::Data;
use jacquard_common::{BosStr, CowStr, DefaultStr, FromStaticStr};
use jacquard_derive::{IntoStatic, open_union};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct Configure<S: BosStr = DefaultStr> {
    ///When true, the RSVP button redirects to an external ticketing URL instead of creating a direct RSVP.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub disable_direct_rsvp: Option<bool>,
    ///AT-URI of the event to configure.
    pub event: AtUri<S>,
    ///When true, RSVPs require a confirmed email address.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub require_confirmed_email: Option<bool>,
    ///URL to redirect users to for external ticketing (e.g., ti.to, eventbrite).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub rsvp_redirect_url: Option<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, Default)]
#[serde(
    rename_all = "camelCase",
    bound(deserialize = "S: Deserialize<'de> + BosStr")
)]
pub struct ConfigureOutput<S: BosStr = DefaultStr> {
    #[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 ConfigureError {
    /// The specified event does not exist.
    #[serde(rename = "EventNotFound")]
    EventNotFound(Option<SmolStr>),
    /// The authenticated user does not own this event.
    #[serde(rename = "NotAuthorized")]
    NotAuthorized(Option<SmolStr>),
    /// The provided redirect URL is invalid or not allowed.
    #[serde(rename = "InvalidRedirectUrl")]
    InvalidRedirectUrl(Option<SmolStr>),
    /// Catch-all for unknown error codes.
    #[serde(untagged)]
    Other {
        error: SmolStr,
        message: Option<SmolStr>,
    },
}

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

/// Response type for events.smokesignal.event.configure
pub struct ConfigureResponse;
impl jacquard_common::xrpc::XrpcResp for ConfigureResponse {
    const NSID: &'static str = "events.smokesignal.event.configure";
    const ENCODING: &'static str = "application/json";
    type Output<S: BosStr> = ConfigureOutput<S>;
    type Err = ConfigureError;
}

impl<S: BosStr> jacquard_common::xrpc::XrpcRequest for Configure<S> {
    const NSID: &'static str = "events.smokesignal.event.configure";
    const METHOD: jacquard_common::xrpc::XrpcMethod =
        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
    type Response = ConfigureResponse;
}

/// Endpoint type for events.smokesignal.event.configure
pub struct ConfigureRequest;
impl jacquard_common::xrpc::XrpcEndpoint for ConfigureRequest {
    const PATH: &'static str = "/xrpc/events.smokesignal.event.configure";
    const METHOD: jacquard_common::xrpc::XrpcMethod =
        jacquard_common::xrpc::XrpcMethod::Procedure("application/json");
    type Request<S: BosStr> = Configure<S>;
    type Response = ConfigureResponse;
}

pub mod configure_state {

    pub use crate::builder_types::{IsSet, IsUnset, Set, Unset};
    #[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 Event;
    }
    /// Empty state - all required fields are unset
    pub struct Empty(());
    impl sealed::Sealed for Empty {}
    impl State for Empty {
        type Event = Unset;
    }
    ///State transition - sets the `event` field to Set
    pub struct SetEvent<St: State = Empty>(PhantomData<fn() -> St>);
    impl<St: State> sealed::Sealed for SetEvent<St> {}
    impl<St: State> State for SetEvent<St> {
        type Event = Set<members::event>;
    }
    /// Marker types for field names
    #[allow(non_camel_case_types)]
    pub mod members {
        ///Marker type for the `event` field
        pub struct event(());
    }
}

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

impl<S: BosStr> Configure<S> {
    /// Create a new builder for this type.
    pub fn new() -> ConfigureBuilder<S, configure_state::Empty> {
        ConfigureBuilder::new()
    }
}

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

impl<S: BosStr, St: configure_state::State> ConfigureBuilder<S, St> {
    /// Set the `disableDirectRsvp` field (optional)
    pub fn disable_direct_rsvp(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.0 = value.into();
        self
    }
    /// Set the `disableDirectRsvp` field to an Option value (optional)
    pub fn maybe_disable_direct_rsvp(mut self, value: Option<bool>) -> Self {
        self._fields.0 = value;
        self
    }
}

impl<S: BosStr, St> ConfigureBuilder<S, St>
where
    St: configure_state::State,
    St::Event: configure_state::IsUnset,
{
    /// Set the `event` field (required)
    pub fn event(
        mut self,
        value: impl Into<AtUri<S>>,
    ) -> ConfigureBuilder<S, configure_state::SetEvent<St>> {
        self._fields.1 = Option::Some(value.into());
        ConfigureBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _type: PhantomData,
        }
    }
}

impl<S: BosStr, St: configure_state::State> ConfigureBuilder<S, St> {
    /// Set the `requireConfirmedEmail` field (optional)
    pub fn require_confirmed_email(mut self, value: impl Into<Option<bool>>) -> Self {
        self._fields.2 = value.into();
        self
    }
    /// Set the `requireConfirmedEmail` field to an Option value (optional)
    pub fn maybe_require_confirmed_email(mut self, value: Option<bool>) -> Self {
        self._fields.2 = value;
        self
    }
}

impl<S: BosStr, St: configure_state::State> ConfigureBuilder<S, St> {
    /// Set the `rsvpRedirectUrl` field (optional)
    pub fn rsvp_redirect_url(mut self, value: impl Into<Option<UriValue<S>>>) -> Self {
        self._fields.3 = value.into();
        self
    }
    /// Set the `rsvpRedirectUrl` field to an Option value (optional)
    pub fn maybe_rsvp_redirect_url(mut self, value: Option<UriValue<S>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<S: BosStr, St> ConfigureBuilder<S, St>
where
    St: configure_state::State,
    St::Event: configure_state::IsSet,
{
    /// Build the final struct.
    pub fn build(self) -> Configure<S> {
        Configure {
            disable_direct_rsvp: self._fields.0,
            event: self._fields.1.unwrap(),
            require_confirmed_email: self._fields.2,
            rsvp_redirect_url: self._fields.3,
            extra_data: Default::default(),
        }
    }
    /// Build the final struct with custom extra_data.
    pub fn build_with_data(self, extra_data: BTreeMap<SmolStr, Data<S>>) -> Configure<S> {
        Configure {
            disable_direct_rsvp: self._fields.0,
            event: self._fields.1.unwrap(),
            require_confirmed_email: self._fields.2,
            rsvp_redirect_url: self._fields.3,
            extra_data: Some(extra_data),
        }
    }
}