// @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::CowStr;
use jacquard_common::types::string::{AtUri, UriValue};
use jacquard_derive::{IntoStatic, lexicon, open_union};
use serde::{Serialize, Deserialize};

#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic)]
#[serde(rename_all = "camelCase")]
pub struct Configure<'a> {
    ///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.
    #[serde(borrow)]
    pub event: AtUri<'a>,
    ///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")]
    #[serde(borrow)]
    pub rsvp_redirect_url: Option<UriValue<'a>>,
}


#[lexicon]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, IntoStatic, Default)]
#[serde(rename_all = "camelCase")]
pub struct ConfigureOutput<'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 ConfigureError<'a> {
    /// The specified event does not exist.
    #[serde(rename = "EventNotFound")]
    EventNotFound(Option<CowStr<'a>>),
    /// The authenticated user does not own this event.
    #[serde(rename = "NotAuthorized")]
    NotAuthorized(Option<CowStr<'a>>),
    /// The provided redirect URL is invalid or not allowed.
    #[serde(rename = "InvalidRedirectUrl")]
    InvalidRedirectUrl(Option<CowStr<'a>>),
}

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::Unknown(err) => write!(f, "Unknown error: {:?}", err),
        }
    }
}

/// 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<'de> = ConfigureOutput<'de>;
    type Err<'de> = ConfigureError<'de>;
}

impl<'a> jacquard_common::xrpc::XrpcRequest for Configure<'a> {
    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<'de> = Configure<'de>;
    type Response = ConfigureResponse;
}

pub mod configure_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 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<S: State = Empty>(PhantomData<fn() -> S>);
    impl<S: State> sealed::Sealed for SetEvent<S> {}
    impl<S: State> State for SetEvent<S> {
        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<'a, S: configure_state::State> {
    _state: PhantomData<fn() -> S>,
    _fields: (Option<bool>, Option<AtUri<'a>>, Option<bool>, Option<UriValue<'a>>),
    _lifetime: PhantomData<&'a ()>,
}

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

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

impl<'a, S: configure_state::State> ConfigureBuilder<'a, S> {
    /// 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<'a, S> ConfigureBuilder<'a, S>
where
    S: configure_state::State,
    S::Event: configure_state::IsUnset,
{
    /// Set the `event` field (required)
    pub fn event(
        mut self,
        value: impl Into<AtUri<'a>>,
    ) -> ConfigureBuilder<'a, configure_state::SetEvent<S>> {
        self._fields.1 = Option::Some(value.into());
        ConfigureBuilder {
            _state: PhantomData,
            _fields: self._fields,
            _lifetime: PhantomData,
        }
    }
}

impl<'a, S: configure_state::State> ConfigureBuilder<'a, S> {
    /// 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<'a, S: configure_state::State> ConfigureBuilder<'a, S> {
    /// Set the `rsvpRedirectUrl` field (optional)
    pub fn rsvp_redirect_url(mut self, value: impl Into<Option<UriValue<'a>>>) -> 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<'a>>) -> Self {
        self._fields.3 = value;
        self
    }
}

impl<'a, S> ConfigureBuilder<'a, S>
where
    S: configure_state::State,
    S::Event: configure_state::IsSet,
{
    /// Build the final struct
    pub fn build(self) -> Configure<'a> {
        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<
            jacquard_common::deps::smol_str::SmolStr,
            jacquard_common::types::value::Data<'a>,
        >,
    ) -> Configure<'a> {
        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),
        }
    }
}